diff --git a/spki/src/algorithm.rs b/spki/src/algorithm.rs index 6f76d6d35..02a40ccee 100644 --- a/spki/src/algorithm.rs +++ b/spki/src/algorithm.rs @@ -7,6 +7,9 @@ use der::{ Decode, DecodeValue, DerOrd, Encode, Header, Reader, Sequence, ValueOrd, }; +#[cfg(feature = "alloc")] +use der::asn1::Any; + /// X.509 `AlgorithmIdentifier` as defined in [RFC 5280 Section 4.1.1.2]. /// /// ```text @@ -78,6 +81,10 @@ where /// `AlgorithmIdentifier` reference which has `AnyRef` parameters. pub type AlgorithmIdentifierRef<'a> = AlgorithmIdentifier>; +/// `AlgorithmIdentifierOwned` reference which has `Any` parameters. +#[cfg(feature = "alloc")] +pub type AlgorithmIdentifierOwned = AlgorithmIdentifier; + impl<'a> AlgorithmIdentifierRef<'a> { /// Assert the `algorithm` OID is an expected value. pub fn assert_algorithm_oid(&self, expected_oid: ObjectIdentifier) -> Result { @@ -146,4 +153,13 @@ impl<'a> AlgorithmIdentifierRef<'a> { }, )) } + + /// Convert to an [`AlgorithmIdentifierOwned`] + #[cfg(feature = "alloc")] + pub fn to_owned(&self) -> AlgorithmIdentifierOwned { + AlgorithmIdentifier { + oid: self.oid, + parameters: self.parameters.map(|p| p.into()), + } + } } diff --git a/spki/src/lib.rs b/spki/src/lib.rs index 34f5b347e..ad883254c 100644 --- a/spki/src/lib.rs +++ b/spki/src/lib.rs @@ -50,7 +50,10 @@ pub use der::{self, asn1::ObjectIdentifier}; #[cfg(feature = "alloc")] pub use { - crate::{spki::SubjectPublicKeyInfoOwned, traits::EncodePublicKey}, + crate::{ + algorithm::AlgorithmIdentifierOwned, spki::SubjectPublicKeyInfoOwned, + traits::EncodePublicKey, + }, der::Document, };