1616 sec1:: { FromEncodedPoint , ToEncodedPoint } ,
1717 AffinePoint , CurveArithmetic ,
1818 } ,
19- pkcs8:: { der, EncodePrivateKey } ,
19+ pkcs8:: {
20+ der:: { self , asn1:: OctetStringRef } ,
21+ EncodePrivateKey ,
22+ } ,
2023} ;
2124
2225// Imports for actual PEM support
@@ -39,19 +42,19 @@ where
3942 } ;
4043}
4144
42- impl < C > TryFrom < pkcs8:: PrivateKeyInfo < ' _ > > for SecretKey < C >
45+ impl < C > TryFrom < pkcs8:: PrivateKeyInfoRef < ' _ > > for SecretKey < C >
4346where
4447 C : AssociatedOid + Curve + ValidatePublicKey ,
4548 FieldBytesSize < C > : ModulusSize ,
4649{
4750 type Error = pkcs8:: Error ;
4851
49- fn try_from ( private_key_info : pkcs8:: PrivateKeyInfo < ' _ > ) -> pkcs8:: Result < Self > {
52+ fn try_from ( private_key_info : pkcs8:: PrivateKeyInfoRef < ' _ > ) -> pkcs8:: Result < Self > {
5053 private_key_info
5154 . algorithm
5255 . assert_oids ( ALGORITHM_OID , C :: OID ) ?;
5356
54- let ec_private_key = EcPrivateKey :: from_der ( private_key_info. private_key ) ?;
57+ let ec_private_key = EcPrivateKey :: from_der ( private_key_info. private_key . as_bytes ( ) ) ?;
5558 Ok ( Self :: try_from ( ec_private_key) ?)
5659 }
5760}
@@ -64,14 +67,16 @@ where
6467 FieldBytesSize < C > : ModulusSize ,
6568{
6669 fn to_pkcs8_der ( & self ) -> pkcs8:: Result < der:: SecretDocument > {
67- // TODO(tarcieri): make `PrivateKeyInfo` generic around `Params`
6870 let algorithm_identifier = pkcs8:: AlgorithmIdentifierRef {
6971 oid : ALGORITHM_OID ,
7072 parameters : Some ( ( & C :: OID ) . into ( ) ) ,
7173 } ;
7274
7375 let ec_private_key = self . to_sec1_der ( ) ?;
74- let pkcs8_key = pkcs8:: PrivateKeyInfo :: new ( algorithm_identifier, & ec_private_key) ;
76+ let pkcs8_key = pkcs8:: PrivateKeyInfoRef :: new (
77+ algorithm_identifier,
78+ OctetStringRef :: new ( & ec_private_key) ?,
79+ ) ;
7580 Ok ( der:: SecretDocument :: encode_msg ( & pkcs8_key) ?)
7681 }
7782}
0 commit comments