use did_crypto::{ algorithms::Algorithm, crypto::rsa::{RsaSigningKey, RsaVerifyingKey}, signer::sign, verifier::verify, }; const PRIVATE_KEY: &'static str = "-----BEGIN RSA PRIVATE KEY----- MIIJKAIBAAKCAgEAg4TeWkvIRLAfwH2DsPgZDNwQVasBzEy4EIFBbVBZOfuCxYk0 NAU6vSuUjny9tIDyhnJ6UHdizJ377fgvJvR8GTKJrz1dN3/D8H+0qZ6aQefLNRjB zfFW+mgJ8ICznyNPlSu5XikQ8pI8A2Kf64dPFy7QDd+oIm6BRKL+2Nwrepq4utjw XNKuzaGrZYzvJiJp3X3W5wAseV1nOfkTZzH2JnRbtL8uLhbm9wEeXkvqeMFmfuHy q7FaNOBG8XWq8z6ki858+4fak0/EaeALWdZJEc34v0hfV1IP2h5YIZPUfJbugIac usa5F+917U5ZPHciMIj8Myl0EdAk0ZyE6lwqsgPHnt0uAzEVm04d9/1rOpFIQ3ux +OvzjZRq6sSUtDlUJsbLFc4ERk1xg9sg7gpGW1o8pssz7Il4tIM1bo9DTVxqCq4M XDw8MasKH0Ods35caqIHBIayaDhDKm5cS7rtXhW9Bfn5f171nYgBebE/v0MiNIfO 3/5sHgsOFP1UtSHAtcS5fE70ywg5qKEh0JNU/joWEHIAJ6qsUqpunthWHveAWWtH 6U1oojZrs+7sEGRr81H4QPzLtwV+Cc/+dXbXxUxxbn/5p50u1jBSI0IFFzQSculW 1YMFXQX/2WK7SwusVbLTBfiQGT9rdX2Sb4+rYtikMnhP7iJ5qVcWLlRgxd0CAwEA AQKCAgAtiscMcY2J64szNsNxdpgGEfY+FBdtTWu3m2qylc4v+94O1TIUiXMLqpmo tZ1jcfuJfv7H+m9l95cTkouRa7vFZfCzlAZBf6a0EyTWT6uPAtslKcuCqv25fGlk tMx+YNXgC+IGryXFOco6Sd6iypoipv04sKgiNC3jPKYPJj6QGB+74/9nxTTu0/rs EV+GzwflwPu3xiGgbS2fr5Z+d5iLPGO9NS6imx+jjOmdMaCh7Ca37ToBJkrcYIV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EWB0miA5ks= -----END RSA PRIVATE KEY-----"; const PUBLIC_KEY: &'static str = "-----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAg4TeWkvIRLAfwH2DsPgZ DNwQVasBzEy4EIFBbVBZOfuCxYk0NAU6vSuUjny9tIDyhnJ6UHdizJ377fgvJvR8 GTKJrz1dN3/D8H+0qZ6aQefLNRjBzfFW+mgJ8ICznyNPlSu5XikQ8pI8A2Kf64dP Fy7QDd+oIm6BRKL+2Nwrepq4utjwXNKuzaGrZYzvJiJp3X3W5wAseV1nOfkTZzH2 JnRbtL8uLhbm9wEeXkvqeMFmfuHyq7FaNOBG8XWq8z6ki858+4fak0/EaeALWdZJ Ec34v0hfV1IP2h5YIZPUfJbugIacusa5F+917U5ZPHciMIj8Myl0EdAk0ZyE6lwq sgPHnt0uAzEVm04d9/1rOpFIQ3ux+OvzjZRq6sSUtDlUJsbLFc4ERk1xg9sg7gpG W1o8pssz7Il4tIM1bo9DTVxqCq4MXDw8MasKH0Ods35caqIHBIayaDhDKm5cS7rt XhW9Bfn5f171nYgBebE/v0MiNIfO3/5sHgsOFP1UtSHAtcS5fE70ywg5qKEh0JNU /joWEHIAJ6qsUqpunthWHveAWWtH6U1oojZrs+7sEGRr81H4QPzLtwV+Cc/+dXbX xUxxbn/5p50u1jBSI0IFFzQSculW1YMFXQX/2WK7SwusVbLTBfiQGT9rdX2Sb4+r YtikMnhP7iJ5qVcWLlRgxd0CAwEAAQ== -----END PUBLIC KEY-----"; const RSA256_CONTENT: &'static str = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; const RSA384_CONTENT: &'static str = "eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; const RSA512_CONTENT: &'static str = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; const PS256_CONTENT: &'static str = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; const PS384_CONTENT: &'static str = "eyJhbGciOiJQUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; const PS512_CONTENT: &'static str = "eyJhbGciOiJQUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0"; #[test] pub fn test_rsa256_signing_and_verifying() { let sig_result = sign( String::from(RSA256_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::RS256, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(RSA256_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::RS256, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } } } #[test] pub fn test_rsa384_signing_and_verifying() { let sig_result = sign( String::from(RSA384_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::RS384, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(RSA384_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::RS384, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } } } #[test] pub fn test_rsa512_signing_and_verifying() { let sig_result = sign( String::from(RSA512_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::RS512, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(RSA512_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::RS512, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } }; } #[test] pub fn test_ps256_signing_and_verifying() { let sig_result = sign( String::from(PS256_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::PS256, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(PS256_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::PS256, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } } } #[test] pub fn test_ps384_signing_and_verifying() { let sig_result = sign( String::from(PS384_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::PS384, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(PS384_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::PS384, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } } } #[test] pub fn test_ps512_signing_and_verifying() { let sig_result = sign( String::from(PS512_CONTENT), RsaSigningKey::from_pem(PRIVATE_KEY).unwrap(), Algorithm::PS512, ); let signature = match sig_result { Ok(val) => val, Err(error) => { eprintln!("{}", error); panic!() } }; match verify( String::from(PS512_CONTENT), String::from(signature), RsaVerifyingKey::from_pem(PUBLIC_KEY).unwrap(), Algorithm::PS512, ) { Ok(val) => assert!(val), Err(error) => { println!("{}", error.to_string()); } } }