From 72c81a202de9c3e15a97247b361bad5220503e56 Mon Sep 17 00:00:00 2001 From: MattesWhite Date: Tue, 23 Apr 2024 16:10:16 +0200 Subject: [PATCH] Implement Error for OidParseError Only available with 'std' feature. --- src/asn1_types/oid.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/asn1_types/oid.rs b/src/asn1_types/oid.rs index a119348..99e6d0f 100644 --- a/src/asn1_types/oid.rs +++ b/src/asn1_types/oid.rs @@ -13,12 +13,27 @@ use num_traits::Num; /// An error for OID parsing functions. #[derive(Debug)] +#[cfg_attr(feature = "std", derive(thiserror::Error))] pub enum OidParseError { + #[cfg_attr( + feature = "std", + error("Non-relative OIDs must be at least 2 components long") + )] TooShort, + + #[cfg_attr(feature = "std", error("Relative OIDs must not be empty"))] + RelativeTooShort, + /// Signalizes that the first or second component is too large. /// The first must be within the range 0 to 6 (inclusive). /// The second component must be less than 40. + #[cfg_attr( + feature = "std", + error("The first OID component must be < 7 and the second must be < 40") + )] FirstComponentsTooLarge, + + #[cfg_attr(feature = "std", error("OID component is not an integer"))] ParseIntError, } @@ -31,7 +46,6 @@ pub enum OidParseError { /// create oids. For example `oid!(1.2.44.233)` or `oid!(rel 44.233)` /// for relative oids. See the [module documentation](index.html) for more information. #[derive(Hash, PartialEq, Eq, Clone)] - pub struct Oid<'a> { asn1: Cow<'a, [u8]>, relative: bool, @@ -161,7 +175,7 @@ impl<'a> Oid<'a> { /// Build a relative OID from an array of object identifier components. pub fn from_relative(s: &[u64]) -> core::result::Result, OidParseError> { if s.is_empty() { - return Err(OidParseError::TooShort); + return Err(OidParseError::RelativeTooShort); } let asn1_encoded: Vec = encode_relative(s).collect(); Ok(Oid {