//! The one error type of the crate. use core::fmt; /// Result with the crate's [`Error`]. pub type Result = core::result::Result; /// Everything that can go wrong. Errors never carry key material or decrypted bytes. #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// A part of the API that has no implementation (none today; kept so callers and tests can name it). Unimplemented, /// Input is larger than the parser's `MAX_*` constant. Checked before anything is allocated. TooLarge { /// What was being parsed, e.g. `"rtsp message"`. what: &'static str, /// The cap. max: usize, /// The size that was offered. actual: usize, }, /// Input ends before a field it announces. Truncated { /// What was being parsed. what: &'static str, /// Bytes the field needs. needed: usize, /// Bytes that were there. actual: usize, }, /// Input does not follow the format (bad syntax, bad length field, wrong constant, bad encoding). Malformed { /// What was being parsed and what was wrong, a fixed string. what: &'static str, }, /// A field holds a value this client does not accept (unknown type code, out-of-range number). UnexpectedValue { /// The field. what: &'static str, /// The value seen. value: u64, }, /// The host answered with a non-200 `status_code` (HTTP XML) or RTSP status. HostStatus { /// The status code. code: u32, }, /// Decryption, tag or signature check failed. Deliberately without detail. Crypto, /// Pairing refused: wrong PIN, failed host proof (possible man in the middle), or `paired=0`. PairingRefused, /// The host does not offer something this client requires (for example control encryption). Unsupported { /// What is missing. what: &'static str, }, /// The call is not valid in the current state of the state machine. State { /// The state the call needs, a fixed string. expected: &'static str, }, /// The peer stopped answering within its timeout. TimedOut, /// The session is closed; no more calls are accepted. Closed, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Unimplemented => f.write_str("not implemented yet"), Self::TooLarge { what, max, actual } => { write!(f, "{what}: {actual} bytes is over the {max}-byte limit") } Self::Truncated { what, needed, actual } => { write!(f, "{what}: needs {needed} bytes, got {actual}") } Self::Malformed { what } => write!(f, "malformed {what}"), Self::UnexpectedValue { what, value } => { write!(f, "{what}: unexpected value {value:#x}") } Self::HostStatus { code } => write!(f, "host answered with status {code}"), Self::Crypto => f.write_str("cryptographic check failed"), Self::PairingRefused => f.write_str("pairing refused"), Self::Unsupported { what } => write!(f, "host does not support {what}"), Self::State { expected } => write!(f, "not allowed now: needs state {expected}"), Self::TimedOut => f.write_str("timed out"), Self::Closed => f.write_str("session closed"), } } } impl std::error::Error for Error {}