Add RsaPublicKey::new_unchecked (#206)

Constructor for `RsaPublicKey` which bypasses all checks around the
modulus and public exponent size.
This commit is contained in:
Tony Arcieri 2022-10-08 13:02:14 -06:00 committed by GitHub
parent 9066931701
commit 8a1026b379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -250,10 +250,20 @@ impl RsaPublicKey {
/// Create a new public key from its components.
pub fn new_with_max_size(n: BigUint, e: BigUint, max_size: usize) -> Result<Self> {
let k = RsaPublicKey { n, e };
let k = Self { n, e };
check_public_with_max_size(&k, max_size)?;
Ok(k)
}
/// Create a new public key, bypassing checks around the modulus and public
/// exponent size.
///
/// This method is not recommended, and only intended for unusual use cases.
/// Most applications should use [`RsaPublicKey::new`] or
/// [`RsaPublicKey::new_with_max_size`] instead.
pub fn new_unchecked(n: BigUint, e: BigUint) -> Self {
Self { n, e }
}
}
impl PublicKeyParts for RsaPrivateKey {