From 734eea5fd899aedc6f81277880f2dfcf7e92a0f0 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 29 Sep 2023 21:57:48 -0700 Subject: [PATCH] Bring back the `RsaKeyPair` name. The original plan was to add RSA encryption/decryption to the next release but that plan has changed. To make it easier for people to upgrade, and to be consistent with the current state of the other signature algorithm keypair names, bring back the old name. --- src/rsa.rs | 2 +- src/rsa/keypair.rs | 10 +++++----- src/signature.rs | 8 ++------ tests/rsa_tests.rs | 10 +++++----- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/rsa.rs b/src/rsa.rs index e4cf7683ac..4a04664626 100644 --- a/src/rsa.rs +++ b/src/rsa.rs @@ -72,6 +72,6 @@ pub(crate) mod verification; use self::{public_exponent::PublicExponent, public_modulus::PublicModulus}; pub use self::{ - keypair::KeyPair, keypair_components::KeyPairComponents, public_key::PublicKey, + keypair::RsaKeyPair, keypair_components::KeyPairComponents, public_key::PublicKey, public_key_components::PublicKeyComponents, }; diff --git a/src/rsa/keypair.rs b/src/rsa/keypair.rs index ef05960838..09a2e1c03e 100644 --- a/src/rsa/keypair.rs +++ b/src/rsa/keypair.rs @@ -29,7 +29,7 @@ use crate::{ }; /// An RSA key pair, used for signing. -pub struct KeyPair { +pub struct RsaKeyPair { p: PrivatePrime

, q: PrivatePrime, qInv: bigint::Elem, @@ -38,9 +38,9 @@ pub struct KeyPair { public: PublicKey, } -derive_debug_via_field!(KeyPair, stringify!(RsaKeyPair), public); +derive_debug_via_field!(RsaKeyPair, stringify!(RsaKeyPair), public); -impl KeyPair { +impl RsaKeyPair { /// Parses an unencrypted PKCS#8-encoded RSA private key. /// /// This will generate a 2048-bit RSA private key of the correct form using @@ -452,7 +452,7 @@ impl KeyPair { } } -impl signature::KeyPair for KeyPair { +impl signature::KeyPair for RsaKeyPair { type PublicKey = PublicKey; fn public_key(&self) -> &Self::PublicKey { @@ -547,7 +547,7 @@ unsafe impl bigint::SlightlySmallerModulus

for Q {} unsafe impl bigint::SmallerModulus for Q {} unsafe impl bigint::NotMuchSmallerModulus for Q {} -impl KeyPair { +impl RsaKeyPair { /// Computes the signature of `msg` and writes it into `signature`. /// /// `msg` is digested using the digest algorithm from `padding_alg` and the diff --git a/src/signature.rs b/src/signature.rs index 527386e127..a8da1290a2 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -201,7 +201,7 @@ //! // Create an RSA keypair from the DER-encoded bytes. This example uses //! // a 2048-bit key, but larger keys are also supported. //! let private_key_der = read_file(private_key_path)?; -//! let key_pair = rsa::KeyPair::from_der(&private_key_der) +//! let key_pair = rsa::RsaKeyPair::from_der(&private_key_der) //! .map_err(|_| MyError::BadPrivateKey)?; //! //! // Sign the message "hello, world", using PKCS#1 v1.5 padding and the @@ -292,13 +292,9 @@ pub use crate::rsa::{ RSA_PSS_2048_8192_SHA256, RSA_PSS_2048_8192_SHA384, RSA_PSS_2048_8192_SHA512, }, RsaParameters, + RsaKeyPair, }; -/// An RSA key pair, used for signing. -#[cfg(feature = "alloc")] -#[deprecated = "Use `rsa::KeyPair`"] -pub type RsaKeyPair = crate::rsa::KeyPair; - /// A public key signature returned from a signing operation. #[derive(Clone, Copy)] pub struct Signature { diff --git a/tests/rsa_tests.rs b/tests/rsa_tests.rs index 9fe3f112f2..ca29c8a47c 100644 --- a/tests/rsa_tests.rs +++ b/tests/rsa_tests.rs @@ -38,7 +38,7 @@ fn rsa_from_pkcs8_test() { let input = test_case.consume_bytes("Input"); let error = test_case.consume_optional_string("Error"); - match (rsa::KeyPair::from_pkcs8(&input), error) { + match (rsa::RsaKeyPair::from_pkcs8(&input), error) { (Ok(_), None) => {} (Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e), (Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e), @@ -72,7 +72,7 @@ fn test_signature_rsa_pkcs1_sign() { let expected = test_case.consume_bytes("Sig"); let result = test_case.consume_string("Result"); - let key_pair = rsa::KeyPair::from_der(&private_key); + let key_pair = rsa::RsaKeyPair::from_der(&private_key); if result == "Fail-Invalid-Key" { assert!(key_pair.is_err()); return Ok(()); @@ -109,7 +109,7 @@ fn test_signature_rsa_pss_sign() { let result = test_case.consume_string("Result"); let private_key = test_case.consume_bytes("Key"); - let key_pair = rsa::KeyPair::from_der(&private_key); + let key_pair = rsa::RsaKeyPair::from_der(&private_key); if key_pair.is_err() && result == "Fail-Invalid-Key" { return Ok(()); } @@ -139,7 +139,7 @@ fn test_signature_rsa_pkcs1_sign_output_buffer_len() { const PRIVATE_KEY_DER: &[u8] = include_bytes!("../src/rsa/signature_rsa_example_private_key.der"); - let key_pair = rsa::KeyPair::from_der(PRIVATE_KEY_DER).unwrap(); + let key_pair = rsa::RsaKeyPair::from_der(PRIVATE_KEY_DER).unwrap(); // When the output buffer is not exactly the right length, `sign()` returns // an error (and does not panic or invoke UB). if `sign` doesn't check that @@ -311,7 +311,7 @@ fn test_signature_rsa_primitive_verification() { fn rsa_test_keypair_coverage() { const PRIVATE_KEY: &[u8] = include_bytes!("rsa_test_private_key_2048.p8"); - let key_pair = rsa::KeyPair::from_pkcs8(PRIVATE_KEY).unwrap(); + let key_pair = rsa::RsaKeyPair::from_pkcs8(PRIVATE_KEY).unwrap(); // Test that `signature::KeyPair::PublicKey` is `rsa::PublicKey`; if it // were a separate type then it would need to be tested separately.