From 4a3e45564f5dd5aa14256a3e0334a0085fa9bde0 Mon Sep 17 00:00:00 2001 From: codeesura Date: Sun, 28 Jul 2024 01:43:20 +0300 Subject: [PATCH 1/2] refactor and format test function --- signature_gen/src/main.rs | 63 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/signature_gen/src/main.rs b/signature_gen/src/main.rs index 4143a55..be6145c 100644 --- a/signature_gen/src/main.rs +++ b/signature_gen/src/main.rs @@ -1,14 +1,10 @@ use num_bigint::BigUint; use rsa::pkcs1v15::Signature; -use rsa::pkcs1v15::VerifyingKey; use rsa::{RsaPrivateKey, RsaPublicKey}; +use rsa::signature::{SignatureEncoding, Signer}; use rsa::traits::PublicKeyParts; use sha2::Sha256; -use rsa::signature::{ - SignatureEncoding, Signer, Verifier, -}; -use rand; use noir_bignum_paramgen::{bn_limbs, bn_runtime_instance}; @@ -27,41 +23,44 @@ fn generate_2048_bit_signature_parameters() { let sig_uint: BigUint = BigUint::from_bytes_be(sig_bytes); - let sig_str = bn_limbs(sig_uint.clone(), 2048); - println!("let signature: BigNum<18, Params2048> = BigNum::from_array({});", sig_str.as_str()); + println!( + "let signature: BigNum<18, Params2048> = BigNum::from_array({});", + sig_str.as_str() + ); let r = bn_runtime_instance(pub_key.n().clone(), 2048, String::from("BNInstance")); println!("{}", r.as_str()); } - fn main() { generate_2048_bit_signature_parameters(); } - - -fn test_signature_generation_impl() { - let mut rng = rand::thread_rng(); - let bits = 2048; - let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); - let pub_key: RsaPublicKey = priv_key.clone().into(); - let text: &str = "hello world"; - let signing_key = rsa::pkcs1v15::SigningKey::::new(priv_key); - let sig: Vec = signing_key.sign(text.as_bytes()).to_vec(); - let verifying_key = VerifyingKey::::new(pub_key); - - let result = verifying_key.verify( - text.as_bytes(), - &Signature::try_from(sig.as_slice()).unwrap(), - ); - result.expect("failed to verify"); - +#[cfg(test)] +mod tests { + use super::*; + use rand::thread_rng; + use rsa::pkcs1v15::Signature; + use rsa::signature::{Signer, Verifier}; + use rsa::{pkcs1v15::VerifyingKey, RsaPrivateKey, RsaPublicKey}; + use sha2::Sha256; + + #[test] + fn test_signature_generation() { + let mut rng = thread_rng(); + let bits = 2048; + let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); + let pub_key: RsaPublicKey = priv_key.clone().into(); + let text: &str = "hello world"; + let signing_key = rsa::pkcs1v15::SigningKey::::new(priv_key); + let sig: Vec = signing_key.sign(text.as_bytes()).to_vec(); + let verifying_key = VerifyingKey::::new(pub_key); + + let result = verifying_key.verify( + text.as_bytes(), + &Signature::try_from(sig.as_slice()).unwrap(), + ); + result.expect("failed to verify"); + } } - -#[test] -fn test_signature_generation() -{ - test_signature_generation_impl(); -} \ No newline at end of file From 43810d70f537813cb1b946402952b43461fa7154 Mon Sep 17 00:00:00 2001 From: codeesura <120671243+codeesura@users.noreply.github.com> Date: Sun, 28 Jul 2024 01:44:34 +0300 Subject: [PATCH 2/2] Delete signature_gen/.DS_Store --- signature_gen/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 signature_gen/.DS_Store diff --git a/signature_gen/.DS_Store b/signature_gen/.DS_Store deleted file mode 100644 index 6d6450171ab05407b5386718b108c3a4bfc1f1ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ8DBQ5S)!oFr;yrQdh_ggmF%g3nZ~k8iOHr`d9f}Ia+2v1e?c$G-=E%tVUYx zNN9?;ZvoiqYx@K&0W9c_IQuX*-*+F`T}2$t&)DqW4~IRcxF01?1e`m=5uey>kC*%t z-WdGA4yVhFiDML&0#ZN