MCPcopy Create free account
hub / github.com/RustCrypto/RSA / encryption_interoperability

Function encryption_interoperability

tests/private_key.rs:22–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21#[test]
22fn encryption_interoperability() {
23 let key = example_private_key();
24 let public = key.to_public_key();
25
26 // Empty messages and the exact maximum message lengths are supported.
27 #[cfg(feature = "pkcs1v15")]
28 for len in [0, public.size() - 11] {
29 let msg = vec![42; len];
30 let ct = public
31 .pkcs1v15_encrypt_with_rng(&mut example_rng(), &msg)
32 .unwrap();
33 assert_eq!(ct.len(), public.size());
34 assert_eq!(
35 ct,
36 public
37 .encrypt(&mut example_rng(), Pkcs1v15Encrypt, &msg)
38 .unwrap()
39 );
40 assert_eq!(key.decrypt(Pkcs1v15Encrypt, &ct).unwrap(), msg);
41 assert_eq!(key.pkcs1v15_decrypt(&ct).unwrap(), msg);
42 assert_eq!(
43 key.pkcs1v15_decrypt_with_rng(&mut example_rng(), &ct)
44 .unwrap(),
45 msg
46 );
47 }
48
49 for len in [0, public.size() - 2 * 32 - 2] {
50 let msg = vec![42; len];
51 let ct = public
52 .oaep_encrypt_with_rng::<Sha256, _>(&mut example_rng(), &msg)
53 .unwrap();
54
55 assert_eq!(ct.len(), public.size());
56 assert_eq!(
57 ct,
58 public
59 .encrypt(&mut example_rng(), Oaep::<Sha256>::new(), &msg)
60 .unwrap()
61 );
62 assert_eq!(key.decrypt(Oaep::<Sha256>::new(), &ct).unwrap(), msg);
63 assert_eq!(key.oaep_decrypt::<Sha256>(&ct).unwrap(), msg);
64 assert_eq!(
65 key.oaep_decrypt_with_rng::<Sha256, _>(&mut example_rng(), &ct)
66 .unwrap(),
67 msg
68 );
69 }
70}
71
72#[test]
73fn signing_interoperability() {

Callers

nothing calls this directly

Calls 5

example_private_keyFunction · 0.85
example_rngFunction · 0.85
to_public_keyMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected