stun_coder/attribute/
errors.rs

1use thiserror::Error;
2
3/// Attribute encoding errors.
4#[derive(Error, Debug)]
5pub enum AttributeDecodeError {
6    /// Error reading field value.
7    #[error("Error reading field value.")]
8    ReadFailure(#[from] std::io::Error),
9    /// Failed to convert byte sequence into a UTF-8 string.
10    #[error("Failed to convert byte sequence into a UTF-8 string.")]
11    InvalidString(#[from] std::string::FromUtf8Error),
12    /// Not enough data was provided to decode the value.
13    #[error("Not enough data.")]
14    InsufficientData(),
15    /// Unrecognized field value was provided.
16    #[error("Invalid field value: {0}.")]
17    InvalidValue(u128),
18    /// Unrecognized attribute type value was provided.
19    #[error("Unrecognized attribute type value: {attr_type:?}.")]
20    UnrecognizedAttributeType {
21        /// The provided attribute type that was not recognized
22        attr_type: u16,
23    },
24}
25
26/// Attribute decoding errors.
27#[derive(Error, Debug)]
28pub enum AttributeEncodeError {
29    /// Error writing field value.
30    #[error("Error writing field value.")]
31    WriteFailure(#[from] std::io::Error),
32    /// The encoded UTF-8 value crosses the size limit for the field.
33    /// The REALM, SERVER, reason phrases, and NONCE are limited to 127 characters (763 bytes). USERNAME to 513 bytes.
34    #[error("UTF-8 value too big. Limit: {limit}, current length: {length}.")]
35    Utf8ValueTooBig {
36        /// The size limit specified in RFC
37        limit: usize,
38        /// The current length of the encoded value
39        length: usize,
40    },
41}