diff --git a/src/asn1_types/any.rs b/src/asn1_types/any.rs index 8b01e41..330b02a 100644 --- a/src/asn1_types/any.rs +++ b/src/asn1_types/any.rs @@ -1,6 +1,7 @@ use crate::ber::*; use crate::*; use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::string::String; use core::convert::{TryFrom, TryInto}; @@ -103,10 +104,10 @@ impl<'a> Any<'a> { let (rem, any) = Any::from_ber(bytes).map_err(Err::convert)?; any.tag() .assert_eq(Tag(tag)) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; any.class() .assert_eq(class) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let (_, res) = op(any.data)?; Ok((rem, res)) } @@ -127,10 +128,10 @@ impl<'a> Any<'a> { let (rem, any) = Any::from_der(bytes).map_err(Err::convert)?; any.tag() .assert_eq(Tag(tag)) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; any.class() .assert_eq(class) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let (_, res) = op(any.data)?; Ok((rem, res)) } diff --git a/src/asn1_types/generalizedtime.rs b/src/asn1_types/generalizedtime.rs index 6e039d8..42a5629 100644 --- a/src/asn1_types/generalizedtime.rs +++ b/src/asn1_types/generalizedtime.rs @@ -1,6 +1,6 @@ -use crate::datetime::decode_decimal; use crate::*; use alloc::format; +#[cfg(not(feature = "std"))] use alloc::string::String; use core::convert::TryFrom; use core::fmt; diff --git a/src/asn1_types/object_descriptor.rs b/src/asn1_types/object_descriptor.rs index db78870..8f60e7c 100644 --- a/src/asn1_types/object_descriptor.rs +++ b/src/asn1_types/object_descriptor.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; // X.680 section 44.3 diff --git a/src/asn1_types/oid.rs b/src/asn1_types/oid.rs index a0747e6..aa8bc43 100644 --- a/src/asn1_types/oid.rs +++ b/src/asn1_types/oid.rs @@ -2,14 +2,13 @@ use crate::*; use alloc::borrow::Cow; #[cfg(not(feature = "std"))] use alloc::format; +#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::{ convert::TryFrom, fmt, iter::FusedIterator, marker::PhantomData, ops::Shl, str::FromStr, }; - -#[cfg(feature = "bigint")] -use num_bigint::BigUint; use num_traits::Num; /// An error for OID parsing functions. diff --git a/src/asn1_types/real.rs b/src/asn1_types/real.rs index 91f64e2..0abcc34 100644 --- a/src/asn1_types/real.rs +++ b/src/asn1_types/real.rs @@ -1,7 +1,6 @@ use crate::*; use alloc::format; use core::convert::TryFrom; -use nom::Needed; mod f32; mod f64; diff --git a/src/asn1_types/sequence.rs b/src/asn1_types/sequence.rs index 61ab888..ebacf41 100644 --- a/src/asn1_types/sequence.rs +++ b/src/asn1_types/sequence.rs @@ -1,5 +1,6 @@ use crate::*; use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; @@ -179,7 +180,7 @@ impl<'a> Sequence<'a> { { match self.content { Cow::Borrowed(b) => f(b), - _ => Err(nom::Err::Error(Error::LifetimeError.into())), + _ => Err(Err::Error(Error::LifetimeError.into())), } } diff --git a/src/asn1_types/sequence/sequence_of.rs b/src/asn1_types/sequence/sequence_of.rs index d8238da..d0e5afa 100644 --- a/src/asn1_types/sequence/sequence_of.rs +++ b/src/asn1_types/sequence/sequence_of.rs @@ -1,4 +1,5 @@ use crate::*; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; use core::fmt::{Debug, Display}; @@ -142,10 +143,10 @@ where .map_err(Err::convert)?; any.header .assert_tag(Self::TAG) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let items = SequenceIterator::::new(any.data) .collect::, E>>() - .map_err(nom::Err::Error)?; + .map_err(Err::Error)?; Ok((rem, SequenceOf::new(items))) }, bytes, diff --git a/src/asn1_types/sequence/vec.rs b/src/asn1_types/sequence/vec.rs index ca4869c..a5daea1 100644 --- a/src/asn1_types/sequence/vec.rs +++ b/src/asn1_types/sequence/vec.rs @@ -1,4 +1,5 @@ use crate::*; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; use core::fmt::Debug; @@ -121,10 +122,10 @@ where .map_err(Err::convert)?; any.header .assert_tag(Self::TAG) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let v = SequenceIterator::::new(any.data) .collect::, E>>() - .map_err(nom::Err::Error)?; + .map_err(Err::Error)?; Ok((rem, v)) }, bytes, diff --git a/src/asn1_types/set.rs b/src/asn1_types/set.rs index fb21399..06503c0 100644 --- a/src/asn1_types/set.rs +++ b/src/asn1_types/set.rs @@ -1,5 +1,6 @@ use crate::*; use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; @@ -180,7 +181,7 @@ impl<'a> Set<'a> { { match self.content { Cow::Borrowed(b) => f(b), - _ => Err(nom::Err::Error(Error::LifetimeError.into())), + _ => Err(Err::Error(Error::LifetimeError.into())), } } diff --git a/src/asn1_types/set/btreeset.rs b/src/asn1_types/set/btreeset.rs index f00df88..f852aba 100644 --- a/src/asn1_types/set/btreeset.rs +++ b/src/asn1_types/set/btreeset.rs @@ -62,13 +62,13 @@ where .map_err(Err::convert)?; any.tag() .assert_eq(Self::TAG) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; any.header .assert_constructed() - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let items = SetIterator::::new(any.data) .collect::, E>>() - .map_err(nom::Err::Error)?; + .map_err(Err::Error)?; Ok((rem, items)) }, bytes, diff --git a/src/asn1_types/set/hashset.rs b/src/asn1_types/set/hashset.rs index 1389ac0..752b941 100644 --- a/src/asn1_types/set/hashset.rs +++ b/src/asn1_types/set/hashset.rs @@ -57,13 +57,13 @@ where .map_err(Err::convert)?; any.tag() .assert_eq(Self::TAG) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; any.header .assert_constructed() - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let items = SetIterator::::new(any.data) .collect::, E>>() - .map_err(nom::Err::Error)?; + .map_err(Err::Error)?; Ok((rem, items)) }, bytes, diff --git a/src/asn1_types/set/set_of.rs b/src/asn1_types/set/set_of.rs index a71eee9..c2846ff 100644 --- a/src/asn1_types/set/set_of.rs +++ b/src/asn1_types/set/set_of.rs @@ -1,4 +1,5 @@ use crate::*; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; use core::fmt::{Debug, Display}; @@ -142,10 +143,10 @@ where .map_err(Err::convert)?; any.header .assert_tag(Self::TAG) - .map_err(|e| nom::Err::Error(e.into()))?; + .map_err(|e| Err::Error(e.into()))?; let items = SetIterator::::new(any.data) .collect::, E>>() - .map_err(nom::Err::Error)?; + .map_err(Err::Error)?; Ok((rem, SetOf::new(items))) }, bytes, diff --git a/src/asn1_types/strings/bmpstring.rs b/src/asn1_types/strings/bmpstring.rs index 5fdaa7a..ff69ba4 100644 --- a/src/asn1_types/strings/bmpstring.rs +++ b/src/asn1_types/strings/bmpstring.rs @@ -3,7 +3,9 @@ use crate::*; use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; /// ASN.1 `BMPSTRING` type @@ -42,7 +44,7 @@ impl<'a> From<&'a str> for BmpString<'a> { impl From for BmpString<'_> { fn from(s: String) -> Self { Self { - data: alloc::borrow::Cow::Owned(s), + data: Cow::Owned(s), } } } diff --git a/src/asn1_types/strings/generalstring.rs b/src/asn1_types/strings/generalstring.rs index f455d6a..d176abc 100644 --- a/src/asn1_types/strings/generalstring.rs +++ b/src/asn1_types/strings/generalstring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(GeneralString); diff --git a/src/asn1_types/strings/graphicstring.rs b/src/asn1_types/strings/graphicstring.rs index 3d84040..df4e56a 100644 --- a/src/asn1_types/strings/graphicstring.rs +++ b/src/asn1_types/strings/graphicstring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(GraphicString); diff --git a/src/asn1_types/strings/ia5string.rs b/src/asn1_types/strings/ia5string.rs index 4b37465..0fbf213 100644 --- a/src/asn1_types/strings/ia5string.rs +++ b/src/asn1_types/strings/ia5string.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(Ia5String); diff --git a/src/asn1_types/strings/numericstring.rs b/src/asn1_types/strings/numericstring.rs index dbe4ff1..e0462a1 100644 --- a/src/asn1_types/strings/numericstring.rs +++ b/src/asn1_types/strings/numericstring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(NumericString); diff --git a/src/asn1_types/strings/printablestring.rs b/src/asn1_types/strings/printablestring.rs index 5cd51fa..981704a 100644 --- a/src/asn1_types/strings/printablestring.rs +++ b/src/asn1_types/strings/printablestring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(PrintableString); diff --git a/src/asn1_types/strings/string.rs b/src/asn1_types/strings/string.rs index 81f6ba8..f4e0e2e 100644 --- a/src/asn1_types/strings/string.rs +++ b/src/asn1_types/strings/string.rs @@ -1,4 +1,5 @@ use crate::*; +#[cfg(not(feature = "std"))] use alloc::string::String; use core::convert::TryFrom; diff --git a/src/asn1_types/strings/teletexstring.rs b/src/asn1_types/strings/teletexstring.rs index 2f58804..590b5e9 100644 --- a/src/asn1_types/strings/teletexstring.rs +++ b/src/asn1_types/strings/teletexstring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(TeletexString); diff --git a/src/asn1_types/strings/universalstring.rs b/src/asn1_types/strings/universalstring.rs index 9006362..ae30612 100644 --- a/src/asn1_types/strings/universalstring.rs +++ b/src/asn1_types/strings/universalstring.rs @@ -3,7 +3,9 @@ use crate::*; use alloc::borrow::Cow; +#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::convert::TryFrom; use core::iter::FromIterator; @@ -43,7 +45,7 @@ impl<'a> From<&'a str> for UniversalString<'a> { impl From for UniversalString<'_> { fn from(s: String) -> Self { Self { - data: alloc::borrow::Cow::Owned(s), + data: Cow::Owned(s), } } } diff --git a/src/asn1_types/strings/utf8string.rs b/src/asn1_types/strings/utf8string.rs index 0bf87d4..78eae12 100644 --- a/src/asn1_types/strings/utf8string.rs +++ b/src/asn1_types/strings/utf8string.rs @@ -1,6 +1,7 @@ use crate::asn1_string; use crate::Result; use crate::TestValidCharset; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(Utf8String); diff --git a/src/asn1_types/strings/videotexstring.rs b/src/asn1_types/strings/videotexstring.rs index 51c5a46..d9324d6 100644 --- a/src/asn1_types/strings/videotexstring.rs +++ b/src/asn1_types/strings/videotexstring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(VideotexString); diff --git a/src/asn1_types/strings/visiblestring.rs b/src/asn1_types/strings/visiblestring.rs index 2b141dc..cb72348 100644 --- a/src/asn1_types/strings/visiblestring.rs +++ b/src/asn1_types/strings/visiblestring.rs @@ -1,5 +1,6 @@ use crate::{asn1_string, TestValidCharset}; use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::String; asn1_string!(VisibleString); diff --git a/src/asn1_types/tagged/helpers.rs b/src/asn1_types/tagged/helpers.rs index dfb1018..5025785 100644 --- a/src/asn1_types/tagged/helpers.rs +++ b/src/asn1_types/tagged/helpers.rs @@ -34,7 +34,7 @@ where parse_der_container(tag, move |any: Any<'a>| { any.header .assert_tag(tag) - .map_err(|e| nom::Err::convert(e.into()))?; + .map_err(|e| Err::convert(e.into()))?; f(any.data, any.header) }) } @@ -51,9 +51,7 @@ where let tag = tag.into(); move |i| { let (rem, tagged) = TaggedParser::from_der(i)?; - tagged - .assert_tag(tag) - .map_err(|e| nom::Err::convert(e.into()))?; + tagged.assert_tag(tag).map_err(|e| Err::convert(e.into()))?; Ok((rem, tagged)) } } @@ -73,7 +71,7 @@ where // verify tag of external header any.header .assert_tag(tag) - .map_err(|e| nom::Err::convert(e.into()))?; + .map_err(|e| Err::convert(e.into()))?; // build a fake header with the expected tag let Any { header, data } = any; let header = Header { @@ -93,10 +91,10 @@ where E: ParseError<&'a [u8]> + From, { move |i: &[u8]| { - let (rem, any) = Any::from_der(i).map_err(nom::Err::convert)?; + let (rem, any) = Any::from_der(i).map_err(Err::convert)?; any.header .assert_tag(tag) - .map_err(|e| nom::Err::convert(e.into()))?; + .map_err(|e| Err::convert(e.into()))?; let (_, output) = f(any)?; Ok((rem, output)) } diff --git a/src/asn1_types/tagged/implicit.rs b/src/asn1_types/tagged/implicit.rs index 5594e49..01e6ae5 100644 --- a/src/asn1_types/tagged/implicit.rs +++ b/src/asn1_types/tagged/implicit.rs @@ -74,7 +74,7 @@ where }; match T::try_from(any) { Ok(inner) => Ok((rem, TaggedValue::implicit(inner))), - Err(e) => Err(nom::Err::Error(e)), + Err(e) => Err(Err::Error(e)), } } } @@ -182,7 +182,7 @@ where }; Ok((rem, tagged_value)) } - Err(e) => Err(nom::Err::Error(e)), + Err(e) => Err(Err::Error(e)), } } } @@ -217,7 +217,7 @@ where }, data, }; - T::check_constraints(&any).map_err(|e| nom::Err::Error(e.into()))?; + T::check_constraints(&any).map_err(|e| Err::Error(e.into()))?; match T::try_from(any) { Ok(t) => { let tagged_value = TaggedParser { @@ -228,7 +228,7 @@ where }; Ok((rem, tagged_value)) } - Err(e) => Err(nom::Err::Error(e)), + Err(e) => Err(Err::Error(e)), } } } diff --git a/src/asn1_types/tagged/optional.rs b/src/asn1_types/tagged/optional.rs index 00504df..dcf8307 100644 --- a/src/asn1_types/tagged/optional.rs +++ b/src/asn1_types/tagged/optional.rs @@ -1,4 +1,3 @@ -use super::{explicit::TaggedExplicit, implicit::TaggedImplicit}; use crate::*; /// Helper object to parse TAGGED OPTIONAL types (explicit or implicit) diff --git a/src/asn1_types/utctime.rs b/src/asn1_types/utctime.rs index 8604914..3a67598 100644 --- a/src/asn1_types/utctime.rs +++ b/src/asn1_types/utctime.rs @@ -1,4 +1,3 @@ -use crate::datetime::decode_decimal; use crate::*; use core::convert::TryFrom; use core::fmt; diff --git a/src/datetime.rs b/src/datetime.rs index f3a48b7..33125ae 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -1,5 +1,6 @@ use crate::{Result, Tag}; use alloc::format; +#[cfg(not(feature = "std"))] use alloc::string::ToString; use core::fmt; #[cfg(feature = "datetime")] diff --git a/src/error.rs b/src/error.rs index b486f83..8ec409a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ use crate::{Class, Tag}; use alloc::str; use alloc::string; +#[cfg(not(feature = "std"))] use alloc::string::String; use displaydoc::Display; use nom::error::{ErrorKind, FromExternalError, ParseError}; diff --git a/src/header.rs b/src/header.rs index c2b9aa5..7291cb7 100644 --- a/src/header.rs +++ b/src/header.rs @@ -248,17 +248,17 @@ impl<'a> FromBer<'a> for Header<'a> { (_, l1) => { // if len is 0xff -> error (8.1.3.5) if l1 == 0b0111_1111 { - return Err(::nom::Err::Error(Error::InvalidLength)); + return Err(nom::Err::Error(Error::InvalidLength)); } let (i3, llen) = take(l1)(i2)?; match bytes_to_u64(llen) { Ok(l) => { let l = - usize::try_from(l).or(Err(::nom::Err::Error(Error::InvalidLength)))?; + usize::try_from(l).or(Err(nom::Err::Error(Error::InvalidLength)))?; (i3, Length::Definite(l)) } Err(_) => { - return Err(::nom::Err::Error(Error::InvalidLength)); + return Err(nom::Err::Error(Error::InvalidLength)); } } } @@ -284,14 +284,14 @@ impl<'a> FromDer<'a> for Header<'a> { } (_, 0) => { // Indefinite form is not allowed in DER (10.1) - return Err(::nom::Err::Error(Error::DerConstraintFailed( + return Err(nom::Err::Error(Error::DerConstraintFailed( DerConstraint::IndefiniteLength, ))); } (_, l1) => { // if len is 0xff -> error (8.1.3.5) if l1 == 0b0111_1111 { - return Err(::nom::Err::Error(Error::InvalidLength)); + return Err(nom::Err::Error(Error::InvalidLength)); } // DER(9.1) if len is 0 (indefinite form), obj must be constructed der_constraint_fail_if!( @@ -305,11 +305,11 @@ impl<'a> FromDer<'a> for Header<'a> { // DER: should have been encoded in short form (< 127) // XXX der_constraint_fail_if!(i, l < 127); let l = - usize::try_from(l).or(Err(::nom::Err::Error(Error::InvalidLength)))?; + usize::try_from(l).or(Err(nom::Err::Error(Error::InvalidLength)))?; (i3, Length::Definite(l)) } Err(_) => { - return Err(::nom::Err::Error(Error::InvalidLength)); + return Err(nom::Err::Error(Error::InvalidLength)); } } } diff --git a/src/tag.rs b/src/tag.rs index 8ce7c57..d610a2f 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -1,4 +1,5 @@ use crate::{Error, Result}; +#[cfg(not(feature = "std"))] use alloc::string::ToString; use rusticata_macros::newtype_enum;