1use thiserror::Error;
4
5#[derive(Debug, Error, PartialEq)]
7pub enum EnvelopeError {
8 #[error("Invalid TLV type code: {0:#x}")]
10 InvalidTlvType(u8),
11
12 #[error("Invalid TLV length: {0}")]
14 InvalidTlvLength(usize),
15
16 #[error("Unexpected end of data at offset {0}")]
18 UnexpectedEof(usize),
19
20 #[error("Invalid UTF-8 in field: {0}")]
22 InvalidUtf8(#[from] std::string::FromUtf8Error),
23
24 #[error("Invalid timestamp: {0}")]
26 InvalidTimestamp(u64),
27
28 #[error("Invalid sequence: {0}")]
30 InvalidSequence(u64),
31
32 #[error("String field '{0}' exceeds maximum length of {1} bytes")]
34 StringTooLong(String, usize),
35
36 #[error("Malformed envelope header: {0}")]
38 MalformedHeader(String),
39
40 #[error("Duplicate TLV entry for type {0:#x}")]
42 DuplicateTlvEntry(u8),
43
44 #[error("TLV entries not in canonical order: {0:#x} after {1:#x}")]
46 NonCanonicalOrder(u8, u8),
47
48 #[error("IO error: {0}")]
50 Io(String),
51}
52
53impl From<std::io::Error> for EnvelopeError {
54 fn from(err: std::io::Error) -> Self {
55 EnvelopeError::Io(err.to_string())
56 }
57}
58
59pub type Result<T> = std::result::Result<T, EnvelopeError>;