fmt + clippy

This commit is contained in:
Vincent Prouillet 2020-11-17 14:45:07 +01:00
parent ea4ed55551
commit 2662f6ad1f
4 changed files with 64 additions and 26 deletions

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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);
}

View File

@ -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);
}
}