zaun_community_protocol/crypto/voice/error.rs
1//! Errors of the voice layer. None of them carries key material.
2
3use crate::encoding::{DecodeError, EncodeError};
4use crate::ids::RngError;
5use crate::signed::SignedError;
6
7/// A voice key or frame operation failed.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
9pub enum VoiceError {
10 /// The OS CSPRNG failed.
11 #[error("the random number generator failed")]
12 Rng,
13 /// A value breaks an encoding rule.
14 #[error(transparent)]
15 Encode(#[from] EncodeError),
16 /// Bytes are not a canonical encoding.
17 #[error(transparent)]
18 Decode(#[from] DecodeError),
19 /// A member signature does not verify, or signing failed.
20 #[error(transparent)]
21 Signed(#[from] SignedError),
22 /// The input has the wrong length.
23 #[error("{0} has the wrong length")]
24 Length(&'static str),
25 /// The voice suite is not one this implementation knows.
26 #[error("unknown voice suite {0}")]
27 UnknownSuite(u8),
28 /// The X-Wing public key is invalid.
29 #[error("invalid voice public key")]
30 PublicKey,
31 /// A signed field does not match what the verifier expects.
32 #[error("{0} does not match")]
33 Mismatch(&'static str),
34 /// HPKE failed: the wrapped key was not made for this recipient or was altered.
35 #[error("the wrapped key does not open")]
36 Unwrap,
37 /// The wrapped key's hash is not the one the sender signed for this recipient.
38 #[error("the wrapped key is not the one the sender signed")]
39 WrappedHash,
40 /// The sender-keys message does not name this recipient.
41 #[error("not a recipient of these sender keys")]
42 NotARecipient,
43 /// More recipients than [`super::MAX_RECIPIENTS`], or the same one twice.
44 #[error("invalid recipient list")]
45 Recipients,
46 /// An epoch that is not newer than the one in use.
47 #[error("stale epoch")]
48 StaleEpoch,
49 /// The sender has used every epoch or counter of this voice session; rejoin.
50 #[error("keys exhausted; rejoin with a new voice session")]
51 Exhausted,
52 /// The SFrame header is malformed or not minimally encoded.
53 #[error("malformed SFrame header")]
54 Header,
55 /// No key for the frame's KID.
56 #[error("unknown key id")]
57 UnknownKid,
58 /// The frame's counter was already seen or is older than the replay window.
59 #[error("replayed or too old frame")]
60 Replay,
61 /// The frame does not authenticate.
62 #[error("the frame does not open")]
63 Open,
64 /// Two participants' KIDs collide; the newer one rejoins with a new voice session.
65 #[error("key id collision")]
66 KidCollision,
67 /// The participant is not known (no verified key package).
68 #[error("unknown participant")]
69 UnknownPeer,
70 /// No sender key is active yet.
71 #[error("no active sender key")]
72 NoSenderKey,
73}
74
75impl From<RngError> for VoiceError {
76 fn from(_: RngError) -> Self {
77 Self::Rng
78 }
79}