diff --git a/spki/src/spki.rs b/spki/src/spki.rs index 3d949f887..b7e4c9280 100644 --- a/spki/src/spki.rs +++ b/spki/src/spki.rs @@ -181,6 +181,7 @@ impl PemLabel for SubjectPublicKeyInfo { #[cfg(feature = "alloc")] mod allocating { use super::*; + use crate::EncodePublicKey; use der::referenced::*; impl<'a> RefToOwned<'a> for SubjectPublicKeyInfoRef<'a> { @@ -202,4 +203,15 @@ mod allocating { } } } + + impl SubjectPublicKeyInfoOwned { + /// Create a [`SubjectPublicKeyInfoOwned`] from any object that implements + /// [`EncodePublicKey`]. + pub fn from_key(source: T) -> Result + where + T: EncodePublicKey, + { + Ok(source.to_public_key_der()?.decode_msg::()?) + } + } }