Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spki/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +81,10 @@ where
/// `AlgorithmIdentifier` reference which has `AnyRef` parameters.
pub type AlgorithmIdentifierRef<'a> = AlgorithmIdentifier<AnyRef<'a>>;

/// `AlgorithmIdentifierOwned` reference which has `Any` parameters.
#[cfg(feature = "alloc")]
pub type AlgorithmIdentifierOwned = AlgorithmIdentifier<Any>;

impl<'a> AlgorithmIdentifierRef<'a> {
/// Assert the `algorithm` OID is an expected value.
pub fn assert_algorithm_oid(&self, expected_oid: ObjectIdentifier) -> Result<ObjectIdentifier> {
Expand Down Expand Up @@ -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()),
}
}
}
5 changes: 4 additions & 1 deletion spki/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down