Skip to content

Commit

Permalink
pkcs8 API changes (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo authored Sep 5, 2024
1 parent 45d2896 commit aeedb5a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[profile.dev]
opt-level = 2

[patch.crates-io]
pkcs1 = { git = "https://github.com/RustCrypto/formats.git" }
pkcs8 = { git = "https://github.com/RustCrypto/formats.git" }
13 changes: 9 additions & 4 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::{
};
use core::convert::{TryFrom, TryInto};
use pkcs8::{
der::Encode, Document, EncodePrivateKey, EncodePublicKey, ObjectIdentifier, SecretDocument,
der::{asn1::OctetStringRef, Encode},
Document, EncodePrivateKey, EncodePublicKey, ObjectIdentifier, SecretDocument,
};
use zeroize::Zeroizing;

Expand Down Expand Up @@ -37,10 +38,10 @@ pub(crate) fn verify_algorithm_id(
Ok(())
}

impl TryFrom<pkcs8::PrivateKeyInfo<'_>> for RsaPrivateKey {
impl TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for RsaPrivateKey {
type Error = pkcs8::Error;

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

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

pkcs8::PrivateKeyInfo::new(pkcs1::ALGORITHM_ID, private_key.as_ref()).try_into()
pkcs8::PrivateKeyInfoRef::new(
pkcs1::ALGORITHM_ID,
OctetStringRef::new(private_key.as_ref())?,
)
.try_into()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pkcs1v15/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ where
};
}

impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<D>
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SigningKey<D>
where
D: Digest + AssociatedOid,
{
type Error = pkcs8::Error;

fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
private_key_info
.algorithm
.assert_algorithm_oid(pkcs1::ALGORITHM_OID)?;
Expand Down
4 changes: 2 additions & 2 deletions src/pss/blinded_signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ where
}
}

impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for BlindedSigningKey<D>
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for BlindedSigningKey<D>
where
D: Digest + AssociatedOid,
{
type Error = pkcs8::Error;

fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
RsaPrivateKey::try_from(private_key_info).map(Self::new)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pss/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ where
}
}

impl<D> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<D>
impl<D> TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SigningKey<D>
where
D: Digest + AssociatedOid,
{
type Error = pkcs8::Error;

fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result<Self> {
fn try_from(private_key_info: pkcs8::PrivateKeyInfoRef<'_>) -> pkcs8::Result<Self> {
verify_algorithm_id(&private_key_info.algorithm)?;
RsaPrivateKey::try_from(private_key_info).map(Self::new)
}
Expand Down

0 comments on commit aeedb5a

Please sign in to comment.