embedded_tls/extensions/extension_data/
max_fragment_length.rs1use crate::{
2 buffer::CryptoBuffer,
3 parse_buffer::{ParseBuffer, ParseError},
4 TlsError,
5};
6
7#[derive(Debug, Copy, Clone, PartialEq)]
15#[cfg_attr(feature = "defmt", derive(defmt::Format))]
16pub enum MaxFragmentLength {
17 Bits9 = 1,
19 Bits10 = 2,
21 Bits11 = 3,
23 Bits12 = 4,
25}
26
27impl MaxFragmentLength {
28 pub fn parse(buf: &mut ParseBuffer) -> Result<Self, ParseError> {
29 match buf.read_u8()? {
30 1 => Ok(Self::Bits9),
31 2 => Ok(Self::Bits10),
32 3 => Ok(Self::Bits11),
33 4 => Ok(Self::Bits12),
34 other => {
35 warn!("Read unknown MaxFragmentLength: {}", other);
36 Err(ParseError::InvalidData)
37 }
38 }
39 }
40
41 pub fn encode(&self, buf: &mut CryptoBuffer) -> Result<(), TlsError> {
42 buf.push(*self as u8).map_err(|_| TlsError::EncodeError)
43 }
44}