Skip to content

Commit

Permalink
spki: adds a public key to SubjectPublicKeyInfoOwned helper (RustCryp…
Browse files Browse the repository at this point in the history
…to#1269)

This adds a `SubjectPublicKeyInfoOwned::from_key` helper that will accept any
public key (an object implementing `EncodePublicKey`).
  • Loading branch information
baloo authored and carl-wallace committed Dec 4, 2023
1 parent 1ef0219 commit 8d08a78
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spki/src/spki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl<Params, Key> PemLabel for SubjectPublicKeyInfo<Params, Key> {
#[cfg(feature = "alloc")]
mod allocating {
use super::*;
use crate::EncodePublicKey;
use der::referenced::*;

impl<'a> RefToOwned<'a> for SubjectPublicKeyInfoRef<'a> {
Expand All @@ -202,4 +203,15 @@ mod allocating {
}
}
}

impl SubjectPublicKeyInfoOwned {
/// Create a [`SubjectPublicKeyInfoOwned`] from any object that implements
/// [`EncodePublicKey`].
pub fn from_key<T>(source: T) -> Result<Self>
where
T: EncodePublicKey,
{
Ok(source.to_public_key_der()?.decode_msg::<Self>()?)
}
}
}

0 comments on commit 8d08a78

Please sign in to comment.