Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkcs8 API changes #446

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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