From cadeb552b31b3092eb205a4b5b1b1320719418c7 Mon Sep 17 00:00:00 2001 From: liushuai <770722922@qq.com> Date: Wed, 9 Oct 2024 17:56:06 +0800 Subject: [PATCH 1/2] feat: add uncheck_modulus_size feature --- Cargo.toml | 1 + src/key.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index e7fa5ea0..58ba07e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,7 @@ pem = ["pkcs1/pem", "pkcs8/pem"] pkcs5 = ["pkcs8/encryption"] u64_digit = ["num-bigint/u64_digit"] std = ["digest/std", "pkcs1/std", "pkcs8/std", "rand_core/std", "signature/std"] +uncheck_modulus_size = [] [package.metadata.docs.rs] features = ["std", "pem", "serde", "hazmat", "sha2"] diff --git a/src/key.rs b/src/key.rs index b7747d6f..9deae78b 100644 --- a/src/key.rs +++ b/src/key.rs @@ -504,6 +504,7 @@ pub fn check_public(public_key: &impl PublicKeyParts) -> Result<()> { /// Check that the public key is well formed and has an exponent within acceptable bounds. #[inline] fn check_public_with_max_size(public_key: &impl PublicKeyParts, max_size: usize) -> Result<()> { + #[cfg(not(feature = "uncheck_modulus_size"))] if public_key.n().bits() > max_size { return Err(Error::ModulusTooLarge); } From c805a30740299230e9ea38a4718879205cf2256d Mon Sep 17 00:00:00 2001 From: liushuai <770722922@qq.com> Date: Wed, 9 Oct 2024 18:32:49 +0800 Subject: [PATCH 2/2] feat: suppress unused warning --- src/key.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/key.rs b/src/key.rs index 9deae78b..ff2107df 100644 --- a/src/key.rs +++ b/src/key.rs @@ -508,6 +508,8 @@ fn check_public_with_max_size(public_key: &impl PublicKeyParts, max_size: usize) if public_key.n().bits() > max_size { return Err(Error::ModulusTooLarge); } + #[cfg(feature = "uncheck_modulus_size")] + let _unused = max_size; let e = public_key .e()