From 5bea3e127cb1ea70249b7b7860df990dad0ae76c Mon Sep 17 00:00:00 2001 From: MattesWhite Date: Tue, 23 Apr 2024 16:10:16 +0200 Subject: [PATCH 1/2] Implement Error for OidParseError Only available with 'std' feature. --- src/asn1_types/oid.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/asn1_types/oid.rs b/src/asn1_types/oid.rs index a119348..c26e50a 100644 --- a/src/asn1_types/oid.rs +++ b/src/asn1_types/oid.rs @@ -13,12 +13,24 @@ 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 and relative OIDs must not be empty") + )] TooShort, + /// 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 +43,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, From d798dffa57f176f9b5be0aabdaa1fc76fcda8b6d Mon Sep 17 00:00:00 2001 From: MattesWhite <> Date: Tue, 7 May 2024 15:32:57 +0200 Subject: [PATCH 2/2] Derive core::fmt::Display for OidParseError --- src/asn1_types/oid.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/asn1_types/oid.rs b/src/asn1_types/oid.rs index c26e50a..9a5f340 100644 --- a/src/asn1_types/oid.rs +++ b/src/asn1_types/oid.rs @@ -9,28 +9,20 @@ use alloc::vec::Vec; use core::{ convert::TryFrom, fmt, iter::FusedIterator, marker::PhantomData, ops::Shl, str::FromStr, }; +use displaydoc::Display; use num_traits::Num; /// An error for OID parsing functions. -#[derive(Debug)] +#[derive(Debug, Display)] #[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 and relative OIDs must not be empty") - )] + /// Non-relative OIDs must be at least 2 components long and relative OIDs must not be empty TooShort, - /// 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") - )] + /// 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"))] + /// OID component is not an integer ParseIntError, }