stun_rs/attributes/discovery/
padding.rs

1const PADDING: u16 = 0x0026;
2const MAX_ENCODED_SIZE: usize = 64000;
3const MAX_DECODED_SIZE: usize = 64000;
4
5crate::common::string_attribute!(
6    /// The padding attribute allows for the entire message to be padded to
7    /// force the STUN message to be divided into IP fragments.  This attribute
8    /// consists entirely of a free-form string, the value of which does not
9    /// matter. Padding can be used in either Binding Requests or Binding
10    /// Responses.
11    ///
12    /// # Examples
13    ///```rust
14    /// # use std::error::Error;
15    /// # use stun_rs::attributes::discovery::Padding;
16    /// #
17    /// # fn main() -> Result<(), Box<dyn Error>> {
18    /// let attr = Padding::new("ABCDEFGHIJK...")?;
19    /// assert_eq!(attr, "ABCDEFGHIJK...");
20    /// #
21    /// #  Ok(())
22    /// # }
23    ///```
24    Padding,
25    PADDING,
26    MAX_ENCODED_SIZE,
27    MAX_DECODED_SIZE,
28);
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33    use crate::StunAttribute;
34
35    #[test]
36    fn other_address_server_stunt_attribute() {
37        let attr = StunAttribute::Padding(
38            Padding::new("test").expect("Failed to create padding attribute"),
39        );
40        assert!(attr.is_padding());
41        assert!(attr.as_padding().is_ok());
42        assert!(attr.as_error_code().is_err());
43
44        assert!(attr.attribute_type().is_comprehension_required());
45        assert!(!attr.attribute_type().is_comprehension_optional());
46
47        let dbg_fmt = format!("{:?}", attr);
48        assert_eq!("Padding(Padding(\"test\"))", dbg_fmt);
49    }
50}