From 2662f6ad1fc452230a8936394a9c293837a385e3 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 17 Nov 2020 14:45:07 +0100 Subject: [PATCH] fmt + clippy --- tests/ecdsa/mod.rs | 22 +++++++++++++++------- tests/eddsa/mod.rs | 22 +++++++++++++++------- tests/hmac.rs | 12 +++++++++--- tests/rsa/mod.rs | 34 +++++++++++++++++++++++++--------- 4 files changed, 64 insertions(+), 26 deletions(-) diff --git a/tests/ecdsa/mod.rs b/tests/ecdsa/mod.rs index 40e97df..0f26ae0 100644 --- a/tests/ecdsa/mod.rs +++ b/tests/ecdsa/mod.rs @@ -18,10 +18,15 @@ fn round_trip_sign_verification_pk8() { let pubkey = include_bytes!("public_ecdsa_key.pk8"); let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_ec_der(privkey), Algorithm::ES256).unwrap(); - let is_valid = - verify(&encrypted, "hello world".as_bytes(), &DecodingKey::from_ec_der(pubkey), Algorithm::ES256) + sign(b"hello world", &EncodingKey::from_ec_der(privkey), Algorithm::ES256) .unwrap(); + let is_valid = verify( + &encrypted, + b"hello world", + &DecodingKey::from_ec_der(pubkey), + Algorithm::ES256, + ) + .unwrap(); assert!(is_valid); } @@ -29,12 +34,15 @@ fn round_trip_sign_verification_pk8() { fn round_trip_sign_verification_pem() { let privkey_pem = include_bytes!("private_ecdsa_key.pem"); let pubkey_pem = include_bytes!("public_ecdsa_key.pem"); - let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_ec_pem(privkey_pem).unwrap(), Algorithm::ES256) - .unwrap(); + let encrypted = sign( + b"hello world", + &EncodingKey::from_ec_pem(privkey_pem).unwrap(), + Algorithm::ES256, + ) + .unwrap(); let is_valid = verify( &encrypted, - "hello world".as_bytes(), + b"hello world", &DecodingKey::from_ec_pem(pubkey_pem).unwrap(), Algorithm::ES256, ) diff --git a/tests/eddsa/mod.rs b/tests/eddsa/mod.rs index c67f0c2..4430345 100644 --- a/tests/eddsa/mod.rs +++ b/tests/eddsa/mod.rs @@ -18,10 +18,15 @@ fn round_trip_sign_verification_pk8() { let pubkey = include_bytes!("public_ed25519_key.pk8"); let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_ed_der(privkey), Algorithm::EdDSA).unwrap(); - let is_valid = - verify(&encrypted, "hello world".as_bytes(), &DecodingKey::from_ed_der(pubkey), Algorithm::EdDSA) + sign(b"hello world", &EncodingKey::from_ed_der(privkey), Algorithm::EdDSA) .unwrap(); + let is_valid = verify( + &encrypted, + b"hello world", + &DecodingKey::from_ed_der(pubkey), + Algorithm::EdDSA, + ) + .unwrap(); assert!(is_valid); } @@ -29,12 +34,15 @@ fn round_trip_sign_verification_pk8() { fn round_trip_sign_verification_pem() { let privkey_pem = include_bytes!("private_ed25519_key.pem"); let pubkey_pem = include_bytes!("public_ed25519_key.pem"); - let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_ed_pem(privkey_pem).unwrap(), Algorithm::EdDSA) - .unwrap(); + let encrypted = sign( + b"hello world", + &EncodingKey::from_ed_pem(privkey_pem).unwrap(), + Algorithm::EdDSA, + ) + .unwrap(); let is_valid = verify( &encrypted, - "hello world".as_bytes(), + b"hello world", &DecodingKey::from_ed_pem(pubkey_pem).unwrap(), Algorithm::EdDSA, ) diff --git a/tests/hmac.rs b/tests/hmac.rs index 1a25cdf..9286187 100644 --- a/tests/hmac.rs +++ b/tests/hmac.rs @@ -17,7 +17,8 @@ pub struct Claims { #[test] fn sign_hs256() { let result = - sign("hello world".as_bytes(), &EncodingKey::from_secret(b"secret"), Algorithm::HS256).unwrap(); + sign(b"hello world", &EncodingKey::from_secret(b"secret"), Algorithm::HS256) + .unwrap(); let expected = "c0zGLzKEFWj0VxWuufTXiRMk5tlI5MbGDAYhzaxIYjo"; assert_eq!(result, expected); } @@ -25,8 +26,13 @@ fn sign_hs256() { #[test] fn verify_hs256() { let sig = "c0zGLzKEFWj0VxWuufTXiRMk5tlI5MbGDAYhzaxIYjo"; - let valid = - verify(sig, "hello world".as_bytes(), &DecodingKey::from_secret(b"secret"), Algorithm::HS256).unwrap(); + let valid = verify( + sig, + b"hello world", + &DecodingKey::from_secret(b"secret"), + Algorithm::HS256, + ) + .unwrap(); assert!(valid); } diff --git a/tests/rsa/mod.rs b/tests/rsa/mod.rs index dfd28f0..2dc864f 100644 --- a/tests/rsa/mod.rs +++ b/tests/rsa/mod.rs @@ -28,10 +28,15 @@ fn round_trip_sign_verification_pem_pkcs1() { for &alg in RSA_ALGORITHMS { let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_rsa_pem(privkey_pem).unwrap(), alg).unwrap(); - let is_valid = - verify(&encrypted, "hello world".as_bytes(), &DecodingKey::from_rsa_pem(pubkey_pem).unwrap(), alg) + sign(b"hello world", &EncodingKey::from_rsa_pem(privkey_pem).unwrap(), alg) .unwrap(); + let is_valid = verify( + &encrypted, + b"hello world", + &DecodingKey::from_rsa_pem(pubkey_pem).unwrap(), + alg, + ) + .unwrap(); assert!(is_valid); } } @@ -43,10 +48,15 @@ fn round_trip_sign_verification_pem_pkcs8() { for &alg in RSA_ALGORITHMS { let encrypted = - sign("hello world".as_bytes(), &EncodingKey::from_rsa_pem(privkey_pem).unwrap(), alg).unwrap(); - let is_valid = - verify(&encrypted, "hello world".as_bytes(), &DecodingKey::from_rsa_pem(pubkey_pem).unwrap(), alg) + sign(b"hello world", &EncodingKey::from_rsa_pem(privkey_pem).unwrap(), alg) .unwrap(); + let is_valid = verify( + &encrypted, + b"hello world", + &DecodingKey::from_rsa_pem(pubkey_pem).unwrap(), + alg, + ) + .unwrap(); assert!(is_valid); } } @@ -57,9 +67,15 @@ fn round_trip_sign_verification_der() { let pubkey_der = include_bytes!("public_rsa_key.der"); for &alg in RSA_ALGORITHMS { - let encrypted = sign("hello world".as_bytes(), &EncodingKey::from_rsa_der(privkey_der), alg).unwrap(); - let is_valid = - verify(&encrypted, "hello world".as_bytes(), &DecodingKey::from_rsa_der(pubkey_der), alg).unwrap(); + let encrypted = + sign(b"hello world", &EncodingKey::from_rsa_der(privkey_der), alg).unwrap(); + let is_valid = verify( + &encrypted, + b"hello world", + &DecodingKey::from_rsa_der(pubkey_der), + alg, + ) + .unwrap(); assert!(is_valid); } }