From c925b4991de3006e00935000901e392a276c98a4 Mon Sep 17 00:00:00 2001 From: LWEdslev <202010638@post.au.dk> Date: Wed, 27 Mar 2024 21:48:02 +0100 Subject: [PATCH] use verify_algorithm_id for pss::SigningKey decoding --- src/encoding.rs | 2 +- src/pss/signing_key.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/encoding.rs b/src/encoding.rs index b6ce17be..3151791d 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -17,7 +17,7 @@ use zeroize::Zeroizing; pub const ID_RSASSA_PSS: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.10"); /// Verify that the `AlgorithmIdentifier` for a key is correct. -fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> pkcs8::spki::Result<()> { +pub(crate) fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> pkcs8::spki::Result<()> { match algorithm.oid { pkcs1::ALGORITHM_OID => { if algorithm.parameters_any()? != pkcs8::der::asn1::Null.into() { diff --git a/src/pss/signing_key.rs b/src/pss/signing_key.rs index 22a6cac1..0ed526bd 100644 --- a/src/pss/signing_key.rs +++ b/src/pss/signing_key.rs @@ -1,5 +1,5 @@ use super::{get_pss_signature_algo_id, sign_digest, Signature, VerifyingKey}; -use crate::encoding::ID_RSASSA_PSS; +use crate::encoding::verify_algorithm_id; use crate::{Result, RsaPrivateKey}; use const_oid::AssociatedOid; use core::marker::PhantomData; @@ -232,9 +232,7 @@ where type Error = pkcs8::Error; fn try_from(private_key_info: pkcs8::PrivateKeyInfo<'_>) -> pkcs8::Result { - private_key_info - .algorithm - .assert_algorithm_oid(ID_RSASSA_PSS)?; + verify_algorithm_id(&private_key_info.algorithm)?; RsaPrivateKey::try_from(private_key_info).map(Self::new) } }