RSA: Deprecate and replace RsaKeyPair::public_modulus_len
.
This commit is contained in:
parent
e05f7e1273
commit
617b09baa6
@ -48,8 +48,9 @@ impl Modulus {
|
|||||||
Ok(Self { value, bits })
|
Ok(Self { value, bits })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The length of the modulus in bits.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn len_bits(&self) -> bits::BitLength {
|
pub fn len_bits(&self) -> bits::BitLength {
|
||||||
self.bits
|
self.bits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,14 +373,18 @@ impl RsaKeyPair {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a reference to the public key.
|
||||||
|
pub fn public(&self) -> &public::Key {
|
||||||
|
&self.public
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the length in bytes of the key pair's public modulus.
|
/// Returns the length in bytes of the key pair's public modulus.
|
||||||
///
|
///
|
||||||
/// A signature has the same length as the public modulus.
|
/// A signature has the same length as the public modulus.
|
||||||
|
#[deprecated = "Use `public().n().len_bits().as_usize_bits()`"]
|
||||||
|
#[inline]
|
||||||
pub fn public_modulus_len(&self) -> usize {
|
pub fn public_modulus_len(&self) -> usize {
|
||||||
self.public_key
|
self.public().n().len_bits().as_usize_bits()
|
||||||
.modulus()
|
|
||||||
.big_endian_without_leading_zero()
|
|
||||||
.len()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@
|
|||||||
//! // SHA256 digest algorithm.
|
//! // SHA256 digest algorithm.
|
||||||
//! const MESSAGE: &'static [u8] = b"hello, world";
|
//! const MESSAGE: &'static [u8] = b"hello, world";
|
||||||
//! let rng = rand::SystemRandom::new();
|
//! let rng = rand::SystemRandom::new();
|
||||||
//! let mut signature = vec![0; key_pair.public_modulus_len()];
|
//! let mut signature = vec![0; key_pair.public().n().len().as_usize_bytes_rounded_up()];
|
||||||
//! key_pair.sign(&signature::RSA_PKCS1_SHA256, &rng, MESSAGE, &mut signature)
|
//! key_pair.sign(&signature::RSA_PKCS1_SHA256, &rng, MESSAGE, &mut signature)
|
||||||
//! .map_err(|_| MyError::OOM)?;
|
//! .map_err(|_| MyError::OOM)?;
|
||||||
//!
|
//!
|
||||||
|
@ -82,7 +82,8 @@ fn test_signature_rsa_pkcs1_sign() {
|
|||||||
|
|
||||||
// XXX: This test is too slow on Android ARM Travis CI builds.
|
// XXX: This test is too slow on Android ARM Travis CI builds.
|
||||||
// TODO: re-enable these tests on Android ARM.
|
// TODO: re-enable these tests on Android ARM.
|
||||||
let mut actual = vec![0u8; key_pair.public_modulus_len()];
|
let mut actual =
|
||||||
|
vec![0u8; key_pair.public().n().len_bits().as_usize_bytes_rounded_up()];
|
||||||
key_pair
|
key_pair
|
||||||
.sign(alg, &rng, &msg, actual.as_mut_slice())
|
.sign(alg, &rng, &msg, actual.as_mut_slice())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -121,7 +122,8 @@ fn test_signature_rsa_pss_sign() {
|
|||||||
|
|
||||||
let rng = test::rand::FixedSliceRandom { bytes: &salt };
|
let rng = test::rand::FixedSliceRandom { bytes: &salt };
|
||||||
|
|
||||||
let mut actual = vec![0u8; key_pair.public_modulus_len()];
|
let mut actual =
|
||||||
|
vec![0u8; key_pair.public().n().len_bits().as_usize_bytes_rounded_up()];
|
||||||
key_pair.sign(alg, &rng, &msg, actual.as_mut_slice())?;
|
key_pair.sign(alg, &rng, &msg, actual.as_mut_slice())?;
|
||||||
assert_eq!(actual.as_slice() == &expected[..], result == "Pass");
|
assert_eq!(actual.as_slice() == &expected[..], result == "Pass");
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -143,7 +145,7 @@ fn test_signature_rsa_pkcs1_sign_output_buffer_len() {
|
|||||||
let key_pair = signature::RsaKeyPair::from_der(PRIVATE_KEY_DER).unwrap();
|
let key_pair = signature::RsaKeyPair::from_der(PRIVATE_KEY_DER).unwrap();
|
||||||
|
|
||||||
// The output buffer is one byte too short.
|
// The output buffer is one byte too short.
|
||||||
let mut signature = vec![0; key_pair.public_modulus_len() - 1];
|
let mut signature = vec![0; key_pair.public().n().len_bits().as_usize_bytes_rounded_up() - 1];
|
||||||
|
|
||||||
assert!(key_pair
|
assert!(key_pair
|
||||||
.sign(&signature::RSA_PKCS1_SHA256, &rng, MESSAGE, &mut signature)
|
.sign(&signature::RSA_PKCS1_SHA256, &rng, MESSAGE, &mut signature)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user