Skip to content

Commit

Permalink
Bring back the RsaKeyPair name.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
briansmith committed Sep 30, 2023
1 parent 02b01e0 commit 734eea5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
10 changes: 5 additions & 5 deletions src/rsa/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
};

/// An RSA key pair, used for signing.
pub struct KeyPair {
pub struct RsaKeyPair {
p: PrivatePrime<P>,
q: PrivatePrime<Q>,
qInv: bigint::Elem<P, R>,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -547,7 +547,7 @@ unsafe impl bigint::SlightlySmallerModulus<P> for Q {}
unsafe impl bigint::SmallerModulus<QQ> for Q {}
unsafe impl bigint::NotMuchSmallerModulus<QQ> 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
Expand Down
8 changes: 2 additions & 6 deletions src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions tests/rsa_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(());
Expand Down Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 734eea5

Please sign in to comment.