Files
latls/src/extensions/extension_data/max_fragment_length.rs
Kris Kwiatkowski bd970016e5
Some checks failed
CI / build (push) Successful in 27s
CI / no-std (push) Successful in 26s
CI / clippy (push) Successful in 26s
CI / test (push) Failing after 39s
Initial commit
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-21 08:32:22 +00:00

35 lines
900 B
Rust

use crate::{
ProtocolError,
buffer::CryptoBuffer,
parse_buffer::{ParseBuffer, ParseError},
};
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum MaxFragmentLength {
Bits9 = 1,
Bits10 = 2,
Bits11 = 3,
Bits12 = 4,
}
impl MaxFragmentLength {
pub fn parse(buf: &mut ParseBuffer) -> Result<Self, ParseError> {
match buf.read_u8()? {
1 => Ok(Self::Bits9),
2 => Ok(Self::Bits10),
3 => Ok(Self::Bits11),
4 => Ok(Self::Bits12),
other => {
warn!("Read unknown MaxFragmentLength: {}", other);
Err(ParseError::InvalidData)
}
}
}
pub fn encode(&self, buf: &mut CryptoBuffer) -> Result<(), ProtocolError> {
buf.push(*self as u8)
.map_err(|_| ProtocolError::EncodeError)
}
}