1use thiserror::Error;
5
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
8#[non_exhaustive]
9pub enum DecodeError {
10 #[error("{what}: {len} bytes over the cap of {cap}")]
12 TooLarge {
13 what: &'static str,
15 len: usize,
17 cap: usize,
19 },
20 #[error("{0}: malformed")]
22 Malformed(&'static str),
23}
24
25pub fn check_cap(what: &'static str, len: usize, cap: usize) -> Result<(), DecodeError> {
27 if len > cap {
28 Err(DecodeError::TooLarge { what, len, cap })
29 } else {
30 Ok(())
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq, Error)]
36#[non_exhaustive]
37pub enum TrustError {
38 #[error("the server's call identity changed ({what})")]
40 ServerIdentityChanged {
41 what: &'static str,
43 },
44 #[error("READY call_keys: {0}")]
46 Malformed(&'static str),
47 #[error("device store: {0}")]
49 Store(String),
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Error)]
54#[non_exhaustive]
55pub enum IdentityError {
56 #[error("the certificate names another member")]
58 WrongMember,
59 #[error("the certificate names another device key")]
61 WrongKey,
62 #[error("device certificate refused: {0}")]
64 BadCert(&'static str),
65 #[error("the device is not enrolled")]
67 NotEnrolled,
68 #[error("the device signature does not verify")]
70 BadSignature,
71 #[error("the key_package_ref does not match the package")]
73 RefMismatch,
74 #[error("the key package has no ref (upload it first)")]
76 NoRef,
77 #[error("the key package is stale")]
79 Stale,
80 #[error("MLS: {0}")]
82 Mls(&'static str),
83 #[error("the server's call identity changed")]
85 ServerIdentityChanged,
86 #[error("device store: {0}")]
88 Store(String),
89}
90
91#[derive(Debug, Clone, PartialEq, Eq, Error)]
93#[non_exhaustive]
94pub enum SessionError {
95 #[error("params: {key} out of range")]
97 Params {
98 key: &'static str,
100 },
101 #[error("key_ring_size must be 64, got {got}")]
103 RingSize {
104 got: u32,
106 },
107 #[error("lk_identity does not match join_id")]
109 IdentityMismatch,
110 #[error("external_sender differs from the pin")]
112 ExternalSenderMismatch,
113 #[error("unsupported ciphersuite {0:#06x}")]
115 UnsupportedCiphersuite(u16),
116 #[error("the session has left")]
118 Left,
119 #[error("ignored: {0}")]
121 Ignored(&'static str),
122 #[error(transparent)]
124 Decode(#[from] DecodeError),
125 #[error("MLS: {0}")]
127 Mls(&'static str),
128 #[error("refused: {0}")]
130 Refused(&'static str),
131 #[error(transparent)]
133 Identity(#[from] IdentityError),
134}
135
136#[derive(Debug, Clone, PartialEq, Eq, Error)]
138#[non_exhaustive]
139pub enum JoinError {
140 #[error("this client cannot join encrypted calls ({unsupported})")]
142 Unsupported {
143 unsupported: String,
145 },
146 #[error("the key package was refused twice")]
148 KeyPackage,
149 #[error(transparent)]
151 Session(#[from] SessionError),
152}
153
154#[derive(Debug, Clone, PartialEq, Eq, Error)]
156#[non_exhaustive]
157pub enum ReleaseError {
158 #[error("release sizes")]
160 Sizes,
161 #[error("release does not open")]
163 Aead,
164 #[error("release: {0}")]
166 Malformed(&'static str),
167}
168
169#[derive(Debug, Clone, PartialEq, Eq, Error)]
171#[non_exhaustive]
172pub enum BindingError {
173 #[error("binding table signature")]
175 Signature,
176 #[error("binding table identity")]
178 Identity,
179 #[error("binding table duplicate or order")]
181 Duplicate,
182 #[error("binding table scope: {0}")]
184 Scope(&'static str),
185 #[error("binding table does not cover the tree")]
187 Coverage,
188 #[error("binding table changes a live leaf's identity")]
190 Changed,
191 #[error("binding table names another join for the local leaf")]
193 Local,
194 #[error(transparent)]
196 Decode(#[from] DecodeError),
197}
198
199#[derive(Debug, Clone, PartialEq, Eq, Error)]
201#[non_exhaustive]
202pub enum ChunkError {
203 #[error("recording header: {0}")]
205 Header(&'static str),
206 #[error("recording chunk length")]
208 Length,
209 #[error("recording chunk does not open")]
211 Aead,
212 #[error("recording file length")]
214 FileLength,
215}