@@ -377,10 +377,6 @@ where
377377/// [`PrivateKeyInfo`] with [`AnyRef`] algorithm parameters, and `&[u8]` key.
378378pub type PrivateKeyInfoRef < ' a > = PrivateKeyInfo < AnyRef < ' a > , & ' a OctetStringRef , BitStringRef < ' a > > ;
379379
380- /// [`PrivateKeyInfo`] with [`Any`] algorithm parameters, and `Box<[u8]>` key.
381- #[ cfg( feature = "alloc" ) ]
382- pub type PrivateKeyInfoOwned = PrivateKeyInfo < Any , OctetString , BitString > ;
383-
384380/// [`BitStringLike`] marks object that will act like a `BitString`.
385381///
386382/// It will allow to get a [`BitStringRef`] that points back to the underlying bytes.
@@ -396,15 +392,39 @@ impl BitStringLike for BitStringRef<'_> {
396392}
397393
398394#[ cfg( feature = "alloc" ) ]
399- mod allocating {
395+ pub ( crate ) mod allocating {
400396 use super :: * ;
397+ use crate :: { DecodePrivateKey , EncodePrivateKey } ;
401398 use alloc:: borrow:: ToOwned ;
402399 use core:: borrow:: Borrow ;
403400 use der:: referenced:: * ;
404401
405- impl BitStringLike for BitString {
406- fn as_bit_string ( & self ) -> BitStringRef < ' _ > {
407- BitStringRef :: from ( self )
402+ #[ cfg( feature = "pem" ) ]
403+ use der:: DecodePem ;
404+
405+ /// [`PrivateKeyInfo`] with [`Any`] algorithm parameters, and `Box<[u8]>` key.
406+ pub type PrivateKeyInfoOwned = PrivateKeyInfo < Any , OctetString , BitString > ;
407+
408+ impl DecodePrivateKey for PrivateKeyInfoOwned {
409+ fn from_pkcs8_der ( bytes : & [ u8 ] ) -> Result < Self > {
410+ Ok ( Self :: from_der ( bytes) ?)
411+ }
412+
413+ #[ cfg( feature = "pem" ) ]
414+ fn from_pkcs8_pem ( pem : & str ) -> Result < Self > {
415+ Ok ( Self :: from_pem ( pem) ?)
416+ }
417+ }
418+
419+ impl EncodePrivateKey for PrivateKeyInfoOwned {
420+ fn to_pkcs8_der ( & self ) -> Result < SecretDocument > {
421+ self . try_into ( )
422+ }
423+ }
424+
425+ impl EncodePrivateKey for PrivateKeyInfoRef < ' _ > {
426+ fn to_pkcs8_der ( & self ) -> Result < SecretDocument > {
427+ self . try_into ( )
408428 }
409429 }
410430
@@ -429,4 +449,10 @@ mod allocating {
429449 }
430450 }
431451 }
452+
453+ impl BitStringLike for BitString {
454+ fn as_bit_string ( & self ) -> BitStringRef < ' _ > {
455+ BitStringRef :: from ( self )
456+ }
457+ }
432458}
0 commit comments