@@ -11,8 +11,11 @@ use digest::{core_api::BlockSizeUser, Digest, FixedOutputReset};
11
11
use num_bigint:: BigUint ;
12
12
use num_traits:: Zero ;
13
13
use pkcs8:: {
14
- der:: { asn1:: UintRef , AnyRef , Decode , Encode } ,
15
- AlgorithmIdentifierRef , EncodePrivateKey , PrivateKeyInfo , SecretDocument ,
14
+ der:: {
15
+ asn1:: { OctetStringRef , UintRef } ,
16
+ AnyRef , Decode , Encode ,
17
+ } ,
18
+ AlgorithmIdentifierRef , EncodePrivateKey , PrivateKeyInfoRef , SecretDocument ,
16
19
} ;
17
20
use signature:: {
18
21
hazmat:: { PrehashSigner , RandomizedPrehashSigner } ,
@@ -182,7 +185,8 @@ impl EncodePrivateKey for SigningKey {
182
185
let x = UintRef :: new ( & x_bytes) ?;
183
186
let mut signing_key = x. to_der ( ) ?;
184
187
185
- let signing_key_info = PrivateKeyInfo :: new ( algorithm, & signing_key) ;
188
+ let signing_key_info =
189
+ PrivateKeyInfoRef :: new ( algorithm, OctetStringRef :: new ( & signing_key) ?) ;
186
190
let secret_document = signing_key_info. try_into ( ) ?;
187
191
188
192
signing_key. zeroize ( ) ;
@@ -192,19 +196,19 @@ impl EncodePrivateKey for SigningKey {
192
196
}
193
197
}
194
198
195
- impl < ' a > TryFrom < PrivateKeyInfo < ' a > > for SigningKey {
199
+ impl < ' a > TryFrom < PrivateKeyInfoRef < ' a > > for SigningKey {
196
200
type Error = pkcs8:: Error ;
197
201
198
- fn try_from ( value : PrivateKeyInfo < ' a > ) -> Result < Self , Self :: Error > {
202
+ fn try_from ( value : PrivateKeyInfoRef < ' a > ) -> Result < Self , Self :: Error > {
199
203
value. algorithm . assert_algorithm_oid ( OID ) ?;
200
204
201
205
let parameters = value. algorithm . parameters_any ( ) ?;
202
206
let components = parameters. decode_as :: < Components > ( ) ?;
203
207
204
- let x = UintRef :: from_der ( value. private_key ) ?;
208
+ let x = UintRef :: from_der ( value. private_key . as_bytes ( ) ) ?;
205
209
let x = BigUint :: from_bytes_be ( x. as_bytes ( ) ) ;
206
210
207
- let y = if let Some ( y_bytes) = value. public_key {
211
+ let y = if let Some ( y_bytes) = value. public_key . as_ref ( ) . and_then ( |bs| bs . as_bytes ( ) ) {
208
212
let y = UintRef :: from_der ( y_bytes) ?;
209
213
BigUint :: from_bytes_be ( y. as_bytes ( ) )
210
214
} else {
0 commit comments