diff --git a/Cargo.lock b/Cargo.lock index 33d01836..8a02a676 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -894,8 +894,7 @@ dependencies = [ [[package]] name = "pkcs8" version = "0.11.0-rc.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66180445f1dce533620a7743467ef85fe1c5e80cdaf7c7053609d7a2fbcdae20" +source = "git+https://github.com/RustCrypto/formats.git#3fb883b2f445e74f38f51fef63a347ecfe69f623" dependencies = [ "der 0.8.0-rc.0", "spki 0.8.0-rc.0", @@ -1069,8 +1068,7 @@ dependencies = [ [[package]] name = "sec1" version = "0.8.0-rc.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32c98827dc6ed0ea1707286a3d14b4ad4e25e2643169cbf111568a46ff5b09f5" +source = "git+https://github.com/RustCrypto/formats.git#3fb883b2f445e74f38f51fef63a347ecfe69f623" dependencies = [ "base16ct", "der 0.8.0-rc.0", diff --git a/Cargo.toml b/Cargo.toml index 2ca101fb..bbea205a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,6 @@ members = [ [patch.crates-io] digest = { path = "./digest" } signature = { path = "./signature" } + +sec1 = { git = "https://github.com/RustCrypto/formats.git" } +pkcs8 = { git = "https://github.com/RustCrypto/formats.git" } diff --git a/elliptic-curve/src/secret_key/pkcs8.rs b/elliptic-curve/src/secret_key/pkcs8.rs index a1c37aa3..6cf1b33e 100644 --- a/elliptic-curve/src/secret_key/pkcs8.rs +++ b/elliptic-curve/src/secret_key/pkcs8.rs @@ -16,7 +16,10 @@ use { sec1::{FromEncodedPoint, ToEncodedPoint}, AffinePoint, CurveArithmetic, }, - pkcs8::{der, EncodePrivateKey}, + pkcs8::{ + der::{self, asn1::OctetStringRef}, + EncodePrivateKey, + }, }; // Imports for actual PEM support @@ -39,19 +42,19 @@ where }; } -impl TryFrom> for SecretKey +impl TryFrom> for SecretKey where C: AssociatedOid + Curve + ValidatePublicKey, FieldBytesSize: ModulusSize, { type Error = pkcs8::Error; - fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result { + fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result { private_key_info .algorithm .assert_oids(ALGORITHM_OID, C::OID)?; - let ec_private_key = EcPrivateKey::from_der(private_key_info.private_key)?; + let ec_private_key = EcPrivateKey::from_der(private_key_info.private_key.as_bytes())?; Ok(Self::try_from(ec_private_key)?) } } @@ -64,14 +67,16 @@ where FieldBytesSize: ModulusSize, { fn to_pkcs8_der(&self) -> pkcs8::Result { - // TODO(tarcieri): make `PrivateKeyInfo` generic around `Params` let algorithm_identifier = pkcs8::AlgorithmIdentifierRef { oid: ALGORITHM_OID, parameters: Some((&C::OID).into()), }; let ec_private_key = self.to_sec1_der()?; - let pkcs8_key = pkcs8::PrivateKeyInfo::new(algorithm_identifier, &ec_private_key); + let pkcs8_key = pkcs8::PrivateKeyInfoRef::new( + algorithm_identifier, + OctetStringRef::new(&ec_private_key)?, + ); Ok(der::SecretDocument::encode_msg(&pkcs8_key)?) } }