()
| 71 | |
| 72 | #[test] |
| 73 | fn signing_interoperability() { |
| 74 | let key = example_private_key(); |
| 75 | let public = key.to_public_key(); |
| 76 | |
| 77 | for msg in [b"".as_slice(), b"inherent signing methods"] { |
| 78 | let hash = Sha256::digest(msg); |
| 79 | let pss = key |
| 80 | .pss_sign_with_rng::<Sha256, _>(&mut example_rng(), msg) |
| 81 | .unwrap(); |
| 82 | assert_eq!(pss.len(), public.size()); |
| 83 | assert_eq!( |
| 84 | pss, |
| 85 | key.sign_with_rng(&mut example_rng(), Pss::<Sha256>::new(), &hash) |
| 86 | .unwrap() |
| 87 | ); |
| 88 | assert_eq!( |
| 89 | pss, |
| 90 | key.pss_sign_prehash_with_rng::<Sha256, _>(&mut example_rng(), &hash) |
| 91 | .unwrap() |
| 92 | ); |
| 93 | public.verify(Pss::<Sha256>::new(), &hash, &pss).unwrap(); |
| 94 | public.pss_verify::<Sha256>(msg, &pss).unwrap(); |
| 95 | public.pss_verify_prehash::<Sha256>(&hash, &pss).unwrap(); |
| 96 | assert!(public.pss_verify::<Sha256>(b"wrong message", &pss).is_err()); |
| 97 | |
| 98 | #[cfg(feature = "pkcs1v15")] |
| 99 | let pkcs = { |
| 100 | let pkcs = key |
| 101 | .pkcs1v15_sign_with_rng::<Sha256, _>(&mut example_rng(), msg) |
| 102 | .unwrap(); |
| 103 | |
| 104 | assert_eq!(pkcs.len(), public.size()); |
| 105 | assert_eq!( |
| 106 | pkcs, |
| 107 | key.sign(Pkcs1v15Sign::new::<Sha256>(), &hash).unwrap() |
| 108 | ); |
| 109 | assert_eq!(pkcs, key.pkcs1v15_sign::<Sha256>(msg).unwrap()); |
| 110 | assert_eq!(pkcs, key.pkcs1v15_sign_prehash::<Sha256>(&hash).unwrap()); |
| 111 | assert_eq!( |
| 112 | pkcs, |
| 113 | key.pkcs1v15_sign_prehash_with_rng::<Sha256, _>(&mut example_rng(), &hash) |
| 114 | .unwrap() |
| 115 | ); |
| 116 | |
| 117 | public |
| 118 | .verify(Pkcs1v15Sign::new::<Sha256>(), &hash, &pkcs) |
| 119 | .unwrap(); |
| 120 | public.pkcs1v15_verify::<Sha256>(msg, &pkcs).unwrap(); |
| 121 | public |
| 122 | .pkcs1v15_verify_prehash::<Sha256>(&hash, &pkcs) |
| 123 | .unwrap(); |
| 124 | |
| 125 | assert!( |
| 126 | public |
| 127 | .pkcs1v15_verify::<Sha256>(b"wrong message", &pkcs) |
| 128 | .is_err() |
| 129 | ); |
| 130 |
nothing calls this directly
no test coverage detected