Skip to content

Commit ccad5d2

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

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ where
3939
};
4040
}
4141

42-
impl<C> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SecretKey<C>
42+
impl<C> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SecretKey<C>
4343
where
4444
C: AssociatedOid + Curve + ValidatePublicKey,
4545
FieldBytesSize<C>: ModulusSize,
4646
{
4747
type Error = pkcs8::Error;
4848

49-
fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
49+
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
5050
private_key_info
5151
.algorithm
5252
.assert_oids(ALGORITHM_OID, C::OID)?;
5353

54-
let ec_private_key = EcPrivateKey::from_der(private_key_info.private_key)?;
54+
let ec_private_key = EcPrivateKey::from_der(private_key_info.private_key.as_bytes())?;
5555
Ok(Self::try_from(ec_private_key)?)
5656
}
5757
}
@@ -64,14 +64,17 @@ where
6464
FieldBytesSize<C>: ModulusSize,
6565
{
6666
fn to_pkcs8_der(&self) -> pkcs8::Result<der::SecretDocument> {
67-
// TODO(tarcieri): make `PrivateKeyInfo` generic around `Params`
67+
// TODO(tarcieri): make `PrivateKeyInfoRef` generic around `Params`
6868
let algorithm_identifier = pkcs8::AlgorithmIdentifierRef {
6969
oid: ALGORITHM_OID,
7070
parameters: Some((&C::OID).into()),
7171
};
7272

7373
let ec_private_key = self.to_sec1_der()?;
74-
let pkcs8_key = pkcs8::PrivateKeyInfo::new(algorithm_identifier, &ec_private_key);
74+
let pkcs8_key = pkcs8::PrivateKeyInfoRef::new(
75+
algorithm_identifier,
76+
OctetStringRef::new(&ec_private_key)?,
77+
);
7578
Ok(der::SecretDocument::encode_msg(&pkcs8_key)?)
7679
}
7780
}

0 commit comments

Comments
 (0)