| 1 | //! Error types |
| 2 | |
| 3 | use craterust-analyzer cargo const-oid 0.10.2 crate/::Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#; |
| 4 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 5 | |
| 6 | /// Result type |
| 7 | pub type Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<T> = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo const-oid 0.10.2 error/Error#>; |
| 8 | |
| 9 | /// OID errors. |
| 10 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 11 | pub enum Errorrust-analyzer cargo const-oid 0.10.2 error/Error# { |
| 12 | /// Arc exceeds allowed range (i.e. for first or second OID) |
| 13 | ArcInvalidrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid# { |
| 14 | /// Arc value that is erroneous. |
| 15 | arcrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid#arc.: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#, |
| 16 | }, |
| 17 | |
| 18 | /// Arc is too big (exceeds 32-bit limits of this library). |
| 19 | /// |
| 20 | /// Technically the size of an arc is not constrained by X.660, however |
| 21 | /// this library has elected to use `u32` as the arc representation as |
| 22 | /// sufficient for PKIX/PKCS usages. |
| 23 | ArcTooBigrust-analyzer cargo const-oid 0.10.2 error/Error#ArcTooBig#, |
| 24 | |
| 25 | /// Base 128 encoding error (used in BER/DER serialization of arcs). |
| 26 | Base128rust-analyzer cargo const-oid 0.10.2 error/Error#Base128#, |
| 27 | |
| 28 | /// Expected a digit, but was provided something else. |
| 29 | DigitExpectedrust-analyzer cargo const-oid 0.10.2 error/Error#DigitExpected# { |
| 30 | /// What was found instead of a digit |
| 31 | actualrust-analyzer cargo const-oid 0.10.2 error/Error#DigitExpected#actual.: u8, |
| 32 | }, |
| 33 | |
| 34 | /// Input data is empty. |
| 35 | Emptyrust-analyzer cargo const-oid 0.10.2 error/Error#Empty#, |
| 36 | |
| 37 | /// OID length is invalid (too short or too long). |
| 38 | Lengthrust-analyzer cargo const-oid 0.10.2 error/Error#Length#, |
| 39 | |
| 40 | /// Arithmetic overflow (or underflow) errors. |
| 41 | /// |
| 42 | /// These generally indicate a bug in the `const-oid` crate. |
| 43 | Overflowrust-analyzer cargo const-oid 0.10.2 error/Error#Overflow#, |
| 44 | |
| 45 | /// Repeated `..` characters in input data. |
| 46 | RepeatedDotrust-analyzer cargo const-oid 0.10.2 error/Error#RepeatedDot#, |
| 47 | |
| 48 | /// Trailing `.` character at end of input. |
| 49 | TrailingDotrust-analyzer cargo const-oid 0.10.2 error/Error#TrailingDot#, |
| 50 | } |
| 51 | |
| 52 | impl Errorrust-analyzer cargo const-oid 0.10.2 error/Error# { |
| 53 | /// Escalate this error into a panic. |
| 54 | /// |
| 55 | /// This is a workaround until `Result::unwrap` is allowed in `const fn`. |
| 56 | #[allow(clippy::panic)] |
| 57 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const fn panicrust-analyzer cargo const-oid 0.10.2 error/impl#[Error]panic().(self) -> ! { |
| 58 | match self { |
| 59 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcInvalidrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid# { .. } | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcTooBigrust-analyzer cargo const-oid 0.10.2 error/Error#ArcTooBig# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID contains invalid arc"), |
| 60 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Base128rust-analyzer cargo const-oid 0.10.2 error/Error#Base128# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID contains arc with invalid base 128 encoding"), |
| 61 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::DigitExpectedrust-analyzer cargo const-oid 0.10.2 error/Error#DigitExpected# { .. } => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID expected to start with digit"), |
| 62 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Emptyrust-analyzer cargo const-oid 0.10.2 error/Error#Empty# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID value is empty"), |
| 63 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Lengthrust-analyzer cargo const-oid 0.10.2 error/Error#Length# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID length invalid"), |
| 64 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Overflowrust-analyzer cargo const-oid 0.10.2 error/Error#Overflow# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("arithmetic calculation overflowed"), |
| 65 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::RepeatedDotrust-analyzer cargo const-oid 0.10.2 error/Error#RepeatedDot# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("repeated consecutive '..' characters in OID"), |
| 66 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::TrailingDotrust-analyzer cargo const-oid 0.10.2 error/Error#TrailingDot# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("OID ends with invalid trailing '.'"), |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo const-oid 0.10.2 error/Error# { |
| 72 | fn fmtrust-analyzer cargo const-oid 0.10.2 error/impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 73 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 74 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcInvalidrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid# { arcrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid#arc. } => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "OID contains out-of-range arc: {arc}"), |
| 75 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcTooBigrust-analyzer cargo const-oid 0.10.2 error/Error#ArcTooBig# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("OID contains arc which is larger than 32-bits"), |
| 76 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Base128rust-analyzer cargo const-oid 0.10.2 error/Error#Base128# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("OID contains arc with invalid base 128 encoding"), |
| 77 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::DigitExpectedrust-analyzer cargo const-oid 0.10.2 error/Error#DigitExpected# { actualrust-analyzer cargo const-oid 0.10.2 error/Error#DigitExpected#actual. } => { |
| 78 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "expected digit, got '{}'", char::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/convert/impl#[char][`From<u8>`]from().(actual)) |
| 79 | } |
| 80 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Emptyrust-analyzer cargo const-oid 0.10.2 error/Error#Empty# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("OID value is empty"), |
| 81 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Lengthrust-analyzer cargo const-oid 0.10.2 error/Error#Length# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("OID length invalid"), |
| 82 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Overflowrust-analyzer cargo const-oid 0.10.2 error/Error#Overflow# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("arithmetic calculation overflowed"), |
| 83 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::RepeatedDotrust-analyzer cargo const-oid 0.10.2 error/Error#RepeatedDot# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("repeated consecutive '..' characters in OID"), |
| 84 | Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::TrailingDotrust-analyzer cargo const-oid 0.10.2 error/Error#TrailingDot# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("OID ends with invalid trailing '.'"), |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo const-oid 0.10.2 error/Error# {} |