1use crate::Arc;
4use core::fmt;
5
6pub type Result<T> = core::result::Result<T, Error>;
8
9#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
11pub enum Error {
12 ArcInvalid {
14 arc: Arc,
16 },
17
18 ArcTooBig,
24
25 Base128,
27
28 DigitExpected {
30 actual: u8,
32 },
33
34 Empty,
36
37 Length,
39
40 NotEnoughArcs,
42
43 TrailingDot,
45}
46
47impl Error {
48 #[allow(clippy::panic)]
52 pub(crate) const fn panic(self) -> ! {
53 match self {
54 Error::ArcInvalid { .. } | Error::ArcTooBig => panic!("OID contains invalid arc"),
55 Error::Base128 => panic!("OID contains arc with invalid base 128 encoding"),
56 Error::DigitExpected { .. } => panic!("OID expected to start with digit"),
57 Error::Empty => panic!("OID value is empty"),
58 Error::Length => panic!("OID length invalid"),
59 Error::NotEnoughArcs => panic!("OID requires minimum of 3 arcs"),
60 Error::TrailingDot => panic!("OID ends with invalid trailing '.'"),
61 }
62 }
63}
64
65impl fmt::Display for Error {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 match *self {
68 Error::ArcInvalid { arc } => write!(f, "OID contains out-of-range arc: {}", arc),
69 Error::ArcTooBig => f.write_str("OID contains arc which is larger than 32-bits"),
70 Error::Base128 => f.write_str("OID contains arc with invalid base 128 encoding"),
71 Error::DigitExpected { actual } => {
72 write!(f, "expected digit, got '{}'", char::from(actual))
73 }
74 Error::Empty => f.write_str("OID value is empty"),
75 Error::Length => f.write_str("OID length invalid"),
76 Error::NotEnoughArcs => f.write_str("OID requires minimum of 3 arcs"),
77 Error::TrailingDot => f.write_str("OID ends with invalid trailing '.'"),
78 }
79 }
80}
81
82#[cfg(feature = "std")]
83impl std::error::Error for Error {}