stun_coder/message/
errors.rs1use crate::{AttributeDecodeError, AttributeEncodeError, HeaderDecodeError, HeaderEncodeError, definitions::StunTransactionId};
2use thiserror::Error;
3
4#[derive(Error, Debug)]
6pub enum IntegrityKeyGenerationError {
7 #[error("Failed to process key section via SASLprep.")]
9 SASLPrepFailure(#[from] stringprep::Error),
10 #[error("No username has been provided for long-term credential key generation")]
12 MissingUsername(),
13}
14
15#[derive(Error, Debug)]
17pub enum MessageDecodeError {
18 #[error("Error reading field value.")]
20 ReadFailure(#[from] std::io::Error),
21 #[error("Error decoding STUN header.")]
23 HeaderDecodeFailure(#[from] HeaderDecodeError),
24 #[error("Error decoding STUN attribute.")]
26 AttributeDecodeFailure {
27 #[source]
28 source: AttributeDecodeError,
30 transaction_id: StunTransactionId
32 },
33 #[error("Error decoding STUN attribute.")]
35 IntegrityKeyGenerationFailure(#[from] IntegrityKeyGenerationError),
36 #[error("Fingerprint attribute is not the last one. Message length: {msg_len}, attribute position: {attr_pos}.")]
39 IncorrectFingerprintAttributePosition {
40 msg_len: usize,
42 attr_pos: usize,
44 },
45 #[error("Fingerprint value mismatch. Attribute value: {attr_value:#X?}, computed value: {computed_value:#X?}.")]
48 FingerprintMismatch {
49 attr_value: u32,
51 computed_value: u32,
53 },
54 #[error("Message integrity is compromised. Attribute HMAC value: {attr_value:#X?}, computed HMAC value: {computed_value:#X?}.")]
57 MessageIntegrityFail {
58 attr_value: Vec<u8>,
60 computed_value: Vec<u8>,
62 },
63}
64
65#[derive(Error, Debug)]
67pub enum MessageEncodeError {
68 #[error("Error writing field value.")]
70 WriteFailure(#[from] std::io::Error),
71 #[error("Error encoding STUN header.")]
73 HeaderEncodeFailure(#[from] HeaderEncodeError),
74 #[error("Error encoding STUN attribute.")]
76 AttributeEncodeFailure(#[from] AttributeEncodeError),
77 #[error("Error decoding STUN attribute.")]
79 IntegrityKeyGenerationFailure(#[from] IntegrityKeyGenerationError),
80 #[error("Fingerprint attribute is not the last one. Attributes count: {attr_count}, fingerprint attribute index: {fingerprint_attr_idx}.")]
82 IncorrectFingerprintAttributePosition {
83 attr_count: usize,
85 fingerprint_attr_idx: usize,
87 },
88 #[error("An attribute was added after the MessageIntegrity attribute. Only the Fingerprint attribute can be placed after the MessageIntegrity attribute.")]
90 AttributeAfterIntegrity(),
91 #[error("Missing message integrity password. A placeholder HMAC value is set in MessageIntegrity attribute but no `integrity_password` is provided as an encoding argument.")]
93 MissingIntegrityPassword(),
94}