use crate::Arc;
use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Error {
ArcInvalid {
arc: Arc,
},
ArcTooBig,
Base128,
DigitExpected {
actual: u8,
},
Empty,
Length,
NotEnoughArcs,
TrailingDot,
}
impl Error {
#[allow(clippy::panic)]
pub(crate) const fn panic(self) -> ! {
match self {
Error::ArcInvalid { .. } | Error::ArcTooBig => panic!("OID contains invalid arc"),
Error::Base128 => panic!("OID contains arc with invalid base 128 encoding"),
Error::DigitExpected { .. } => panic!("OID expected to start with digit"),
Error::Empty => panic!("OID value is empty"),
Error::Length => panic!("OID length invalid"),
Error::NotEnoughArcs => panic!("OID requires minimum of 3 arcs"),
Error::TrailingDot => panic!("OID ends with invalid trailing '.'"),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Error::ArcInvalid { arc } => write!(f, "OID contains out-of-range arc: {}", arc),
Error::ArcTooBig => f.write_str("OID contains arc which is larger than 32-bits"),
Error::Base128 => f.write_str("OID contains arc with invalid base 128 encoding"),
Error::DigitExpected { actual } => {
write!(f, "expected digit, got '{}'", char::from(actual))
}
Error::Empty => f.write_str("OID value is empty"),
Error::Length => f.write_str("OID length invalid"),
Error::NotEnoughArcs => f.write_str("OID requires minimum of 3 arcs"),
Error::TrailingDot => f.write_str("OID ends with invalid trailing '.'"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}