Skip to content

Commit

Permalink
Add RsaPublicKey::new_unchecked (#206)
Browse files Browse the repository at this point in the history
Constructor for `RsaPublicKey` which bypasses all checks around the
modulus and public exponent size.
  • Loading branch information
tarcieri authored Oct 8, 2022
1 parent 9066931 commit 8a1026b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8a1026b

Please sign in to comment.