1use crate::codec::v1::opcode::OpCode;
2
3#[derive(Debug, thiserror::Error)]
5pub enum DecodeError {
6 #[error("bad magic bytes")]
8 BadMagic,
9 #[error("bad version")]
11 BadVersion,
12 #[error("bad attestation tag")]
14 BadAttestationTag,
15 #[error("read a LEB128 value overflows {0} bits")]
17 LEB128Overflow(u32),
18 #[error("unrecognized opcode: 0x{0:02x}")]
20 BadOpCode(u8),
21 #[error("expected digest opcode but got: {0}")]
23 ExpectedDigestOp(OpCode),
24 #[error("read value out of range")]
26 OutOfRange,
27 #[error("invalid character in URI")]
29 InvalidUriChar,
30 #[error("URI too long")]
32 UriTooLong,
33 #[error("recursion limit reached")]
35 RecursionLimit,
36 #[error("unexpected end of file")]
38 UnexpectedEof,
39 #[error("I/O error: {0}")]
41 Io(std::io::Error),
42}
43
44#[derive(Debug, thiserror::Error)]
46pub enum EncodeError {
47 #[error("tried to encode a usize exceeding u32::MAX")]
49 UsizeOverflow,
50 #[error("invalid character in URI")]
52 InvalidUriChar,
53 #[error("URI too long")]
55 UriTooLong,
56 #[error("I/O error: {0}")]
58 Io(#[from] std::io::Error),
59}
60
61impl From<std::io::Error> for DecodeError {
62 fn from(err: std::io::Error) -> Self {
63 match err.kind() {
64 std::io::ErrorKind::UnexpectedEof => Self::UnexpectedEof,
65 _ => Self::Io(err),
66 }
67 }
68}