use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("{what}: {len} bytes over the cap of {cap}")]
TooLarge {
what: &'static str,
len: usize,
cap: usize,
},
#[error("{0}: malformed")]
Malformed(&'static str),
}
pub fn check_cap(what: &'static str, len: usize, cap: usize) -> Result<(), DecodeError> {
if len > cap {
Err(DecodeError::TooLarge { what, len, cap })
} else {
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum TrustError {
#[error("the server's call identity changed ({what})")]
ServerIdentityChanged {
what: &'static str,
},
#[error("READY call_keys: {0}")]
Malformed(&'static str),
#[error("device store: {0}")]
Store(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum IdentityError {
#[error("the certificate names another member")]
WrongMember,
#[error("the certificate names another device key")]
WrongKey,
#[error("device certificate refused: {0}")]
BadCert(&'static str),
#[error("the device is not enrolled")]
NotEnrolled,
#[error("the device signature does not verify")]
BadSignature,
#[error("the key_package_ref does not match the package")]
RefMismatch,
#[error("the key package has no ref (upload it first)")]
NoRef,
#[error("the key package is stale")]
Stale,
#[error("MLS: {0}")]
Mls(&'static str),
#[error("the server's call identity changed")]
ServerIdentityChanged,
#[error("device store: {0}")]
Store(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum SessionError {
#[error("params: {key} out of range")]
Params {
key: &'static str,
},
#[error("key_ring_size must be 64, got {got}")]
RingSize {
got: u32,
},
#[error("lk_identity does not match join_id")]
IdentityMismatch,
#[error("external_sender differs from the pin")]
ExternalSenderMismatch,
#[error("unsupported ciphersuite {0:#06x}")]
UnsupportedCiphersuite(u16),
#[error("the session has left")]
Left,
#[error("ignored: {0}")]
Ignored(&'static str),
#[error(transparent)]
Decode(#[from] DecodeError),
#[error("MLS: {0}")]
Mls(&'static str),
#[error("refused: {0}")]
Refused(&'static str),
#[error(transparent)]
Identity(#[from] IdentityError),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum JoinError {
#[error("this client cannot join encrypted calls ({unsupported})")]
Unsupported {
unsupported: String,
},
#[error("the key package was refused twice")]
KeyPackage,
#[error(transparent)]
Session(#[from] SessionError),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ReleaseError {
#[error("release sizes")]
Sizes,
#[error("release does not open")]
Aead,
#[error("release: {0}")]
Malformed(&'static str),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum BindingError {
#[error("binding table signature")]
Signature,
#[error("binding table identity")]
Identity,
#[error("binding table duplicate or order")]
Duplicate,
#[error("binding table scope: {0}")]
Scope(&'static str),
#[error("binding table does not cover the tree")]
Coverage,
#[error("binding table changes a live leaf's identity")]
Changed,
#[error("binding table names another join for the local leaf")]
Local,
#[error(transparent)]
Decode(#[from] DecodeError),
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ChunkError {
#[error("recording header: {0}")]
Header(&'static str),
#[error("recording chunk length")]
Length,
#[error("recording chunk does not open")]
Aead,
#[error("recording file length")]
FileLength,
}