From f9f3c41a7c13177b46f33492b1d693109b112b12 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 7 Oct 2022 10:08:30 -0600 Subject: [PATCH] Add `RsaPublicKey::new_unchecked` Constructor for `RsaPublicKey` which bypasses all checks around the modulus and public exponent size. --- src/key.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/key.rs b/src/key.rs index ab3351c..b43434d 100644 --- a/src/key.rs +++ b/src/key.rs @@ -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 { - 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 {