()
| 20 | |
| 21 | #[test] |
| 22 | fn 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] |
| 73 | fn signing_interoperability() { |
nothing calls this directly
no test coverage detected