Skip to content

Commit df6f7ab

Browse files
committed
elliptic-curve: pkcs8 API changes
see RustCrypto/formats#1483
1 parent dff9996 commit df6f7ab

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

elliptic-curve/src/secret_key/pkcs8.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
use super::SecretKey;
44
use crate::{
5-
pkcs8::{der::Decode, AssociatedOid},
5+
pkcs8::{
6+
der::{asn1::OctetStringRef, Decode},
7+
AssociatedOid,
8+
},
69
sec1::{ModulusSize, ValidatePublicKey},
710
Curve, FieldBytesSize, ALGORITHM_OID,
811
};
@@ -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>
4346
where
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,17 @@ where
6467
FieldBytesSize<C>: ModulusSize,
6568
{
6669
fn to_pkcs8_der(&self) -> pkcs8::Result<der::SecretDocument> {
67-
// TODO(tarcieri): make `PrivateKeyInfo` generic around `Params`
70+
// TODO(tarcieri): make `PrivateKeyInfoRef` generic around `Params`
6871
let algorithm_identifier = pkcs8::AlgorithmIdentifierRef {
6972
oid: ALGORITHM_OID,
7073
parameters: Some((&C::OID).into()),
7174
};
7275

7376
let ec_private_key = self.to_sec1_der()?;
74-
let pkcs8_key = pkcs8::PrivateKeyInfo::new(algorithm_identifier, &ec_private_key);
77+
let pkcs8_key = pkcs8::PrivateKeyInfoRef::new(
78+
algorithm_identifier,
79+
OctetStringRef::new(&ec_private_key)?,
80+
);
7581
Ok(der::SecretDocument::encode_msg(&pkcs8_key)?)
7682
}
7783
}

0 commit comments

Comments
 (0)