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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use core::fmt;
#[allow(clippy::module_name_repetitions)]
#[derive(PartialEq, Clone, Debug)]
pub enum TlvError {
InvalidInput,
TagIsRFU,
ParseIntError,
TruncatedInput,
Inconsistant,
InvalidLength,
}
#[cfg(feature = "std")]
impl std::error::Error for TlvError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
_ => None,
}
}
}
impl fmt::Display for TlvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::InvalidInput => "Invalid tag encountered",
Self::TagIsRFU => "Tag is reserved for future usage",
Self::ParseIntError => "Error parsing input as int",
Self::TruncatedInput => "Error input too short",
Self::Inconsistant => "Inconsistant (tag, value) pair",
Self::InvalidLength => "Read invalid length value",
};
write!(f, "{}", s)
}
}
impl From<core::num::ParseIntError> for TlvError {
fn from(_: core::num::ParseIntError) -> Self {
Self::ParseIntError
}
}
impl From<untrusted::EndOfInput> for TlvError {
fn from(_: untrusted::EndOfInput) -> Self {
Self::TruncatedInput
}
}