Skip to content

Commit aeedb5a

Browse files
authored
pkcs8 API changes (#446)
see RustCrypto/formats#1483
1 parent 45d2896 commit aeedb5a

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
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

+4
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ rustdoc-args = ["--cfg", "docsrs"]
6565

6666
[profile.dev]
6767
opt-level = 2
68+
69+
[patch.crates-io]
70+
pkcs1 = { git = "https://github.com/RustCrypto/formats.git" }
71+
pkcs8 = { git = "https://github.com/RustCrypto/formats.git" }

src/encoding.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::{
99
};
1010
use core::convert::{TryFrom, TryInto};
1111
use pkcs8::{
12-
der::Encode, Document, EncodePrivateKey, EncodePublicKey, ObjectIdentifier, SecretDocument,
12+
der::{asn1::OctetStringRef, Encode},
13+
Document, EncodePrivateKey, EncodePublicKey, ObjectIdentifier, SecretDocument,
1314
};
1415
use zeroize::Zeroizing;
1516

@@ -37,10 +38,10 @@ pub(crate) fn verify_algorithm_id(
3738
Ok(())
3839
}
3940

40-
impl TryFrom<pkcs8::PrivateKeyInfo<'_>> for RsaPrivateKey {
41+
impl TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for RsaPrivateKey {
4142
type Error = pkcs8::Error;
4243

43-
fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
44+
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
4445
verify_algorithm_id(&private_key_info.algorithm)?;
4546

4647
let pkcs1_key = pkcs1::RsaPrivateKey::try_from(private_key_info.private_key)?;
@@ -110,7 +111,11 @@ impl EncodePrivateKey for RsaPrivateKey {
110111
}
111112
.to_der()?;
112113

113-
pkcs8::PrivateKeyInfo::new(pkcs1::ALGORITHM_ID, private_key.as_ref()).try_into()
114+
pkcs8::PrivateKeyInfoRef::new(
115+
pkcs1::ALGORITHM_ID,
116+
OctetStringRef::new(private_key.as_ref())?,
117+
)
118+
.try_into()
114119
}
115120
}
116121

src/pkcs1v15/signing_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ where
247247
};
248248
}
249249

250-
impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<D>
250+
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SigningKey<D>
251251
where
252252
D: Digest + AssociatedOid,
253253
{
254254
type Error = pkcs8::Error;
255255

256-
fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
256+
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
257257
private_key_info
258258
.algorithm
259259
.assert_algorithm_oid(pkcs1::ALGORITHM_OID)?;

src/pss/blinded_signing_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ where
201201
}
202202
}
203203

204-
impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for BlindedSigningKey<D>
204+
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for BlindedSigningKey<D>
205205
where
206206
D: Digest + AssociatedOid,
207207
{
208208
type Error = pkcs8::Error;
209209

210-
fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
210+
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
211211
RsaPrivateKey::try_from(private_key_info).map(Self::new)
212212
}
213213
}

src/pss/signing_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ where
225225
}
226226
}
227227

228-
impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<D>
228+
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SigningKey<D>
229229
where
230230
D: Digest + AssociatedOid,
231231
{
232232
type Error = pkcs8::Error;
233233

234-
fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
234+
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
235235
verify_algorithm_id(&private_key_info.algorithm)?;
236236
RsaPrivateKey::try_from(private_key_info).map(Self::new)
237237
}

0 commit comments

Comments
 (0)