use crate::index::MAX_HEIGHT;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecodingError {
ExceedMaxHeight,
IndexOverflow,
TooManyEncodedBytes,
BytesNotEnough,
ValueDecodingError {
msg: String,
},
}
impl core::fmt::Display for DecodingError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
DecodingError::ExceedMaxHeight => {
write!(
f,
"The height exceeds the maximum height, {}, in an SMT.",
MAX_HEIGHT
)?;
}
DecodingError::IndexOverflow => {
write!(f, "Index Overflow")?;
}
DecodingError::TooManyEncodedBytes => {
write!(f, "Too many encoded bytes than required")?;
}
DecodingError::BytesNotEnough => {
write!(f, "Bytes are not enough for decoding.")?;
}
DecodingError::ValueDecodingError { msg } => {
write!(f, "Value decoding error: {}", msg)?;
}
}
Ok(())
}
}
impl std::error::Error for DecodingError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TreeError {
HeightNotMatch,
IndexNotSorted,
IndexDuplicated,
SecretError,
}
impl core::fmt::Display for TreeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
TreeError::HeightNotMatch => {
write!(
f,
"The height of the index doesn't match with the height of the tree."
)?;
}
TreeError::IndexNotSorted => {
write!(f, "The indexes are not sorted.")?;
}
TreeError::IndexDuplicated => {
write!(f, "There are duplicated indexes")?;
}
TreeError::SecretError => {
write!(f, "Wrong Secret size")?;
}
}
Ok(())
}
}
impl std::error::Error for TreeError {}