Skip to content

Commit 8ea45a0

Browse files
committed
elliptic-curve: pkcs8 API changes
see RustCrypto/formats#1483
1 parent 7fb782a commit 8ea45a0

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Cargo.lock

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ members = [
1818
[patch.crates-io]
1919
digest = { path = "./digest" }
2020
signature = { path = "./signature" }
21+
22+
sec1 = { git = "https://github.com/RustCrypto/formats.git" }
23+
pkcs8 = { git = "https://github.com/RustCrypto/formats.git" }

elliptic-curve/src/secret_key/pkcs8.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use {
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>
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)