use crate::codec::v1::opcode::OpCode;
#[derive(Debug, thiserror::Error)]
pub enum DecodeError {
#[error("bad magic bytes")]
BadMagic,
#[error("bad version")]
BadVersion,
#[error("bad attestation tag")]
BadAttestationTag,
#[error("read a LEB128 value overflows {0} bits")]
LEB128Overflow(u32),
#[error("unrecognized opcode: 0x{0:02x}")]
BadOpCode(u8),
#[error("expected digest opcode but got: {0}")]
ExpectedDigestOp(OpCode),
#[error("read value out of range")]
OutOfRange,
#[error("invalid character in URI")]
InvalidUriChar,
#[error("URI too long")]
UriTooLong,
#[error("recursion limit reached")]
RecursionLimit,
#[error("unexpected end of file")]
UnexpectedEof,
#[cfg(feature = "std")]
#[error("I/O error: {0}")]
Io(std::io::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum EncodeError {
#[error("tried to encode a usize exceeding u32::MAX")]
UsizeOverflow,
#[error("invalid character in URI")]
InvalidUriChar,
#[error("URI too long")]
UriTooLong,
#[cfg(feature = "std")]
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
#[cfg(feature = "std")]
impl From<std::io::Error> for DecodeError {
fn from(err: std::io::Error) -> Self {
match err.kind() {
std::io::ErrorKind::UnexpectedEof => Self::UnexpectedEof,
_ => Self::Io(err),
}
}
}