1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::pdu::formats::Integer4;
pub const MAX_PDU_LENGTH: usize = 70000;
pub const MIN_PDU_LENGTH: usize = 8;
#[derive(Debug)]
pub enum CommandLengthError {
TooLong(u32),
TooShort(u32),
}
pub fn validate_command_length(
command_length: &Integer4,
) -> Result<(), CommandLengthError> {
let len = command_length.value;
if len > MAX_PDU_LENGTH as u32 {
Err(CommandLengthError::TooLong(len))
} else if len < MIN_PDU_LENGTH as u32 {
Err(CommandLengthError::TooShort(len))
} else {
Ok(())
}
}