Skip to content

Commit

Permalink
der: add From<ObjectIdentifier> impl for Any (RustCrypto#965)
Browse files Browse the repository at this point in the history
This is useful for writing a blanket impl for converting generic
`AlgorithmIdentifier<Params>` to `AlgorithmIdentifierOwned`,
specifically for the `AlgorithmIdentifier<ObjectIdentifier>` case, but
other types can opt into this same protocol.
  • Loading branch information
tarcieri authored Apr 2, 2023
1 parent 78910e2 commit 59afffb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions der/src/asn1/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::{
};
use const_oid::ObjectIdentifier;

#[cfg(feature = "alloc")]
use super::Any;

impl<'a> DecodeValue<'a> for ObjectIdentifier {
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
let mut buf = [0u8; ObjectIdentifier::MAX_SIZE];
Expand Down Expand Up @@ -50,6 +53,13 @@ impl<'a> From<&'a ObjectIdentifier> for AnyRef<'a> {
}
}

#[cfg(feature = "alloc")]
impl From<ObjectIdentifier> for Any {
fn from(oid: ObjectIdentifier) -> Any {
AnyRef::from(&oid).into()
}
}

impl TryFrom<AnyRef<'_>> for ObjectIdentifier {
type Error = Error;

Expand Down

0 comments on commit 59afffb

Please sign in to comment.