diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2024-06-19 13:09:45 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-06-19 13:10:43 +0200 |
commit | c12981022528b5f972094f53300ad330875d1f75 (patch) | |
tree | 74f4f6db59ed3624f6763fda720b62d6011cd566 /openpgp | |
parent | 41d3213b2e99609af7987c04a49091caf922aef8 (diff) |
openpgp: Port test to the higher-level PKESK::decrypt API.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/packet/key.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 765580f7..38bcf7cd 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -2376,8 +2376,7 @@ mod tests { } #[test] - fn import_cv25519_sec() { - use crate::crypto::ecdh; + fn import_cv25519_sec() -> Result<()> { use self::mpi::{MPI, Ciphertext}; // X25519 key @@ -2402,20 +2401,19 @@ mod tests { e: MPI::new(&eph_pubkey[..]), key: Vec::from(&b"\x45\x8b\xd8\x4d\x88\xb3\xd2\x16\xb6\xc2\x3b\x99\x33\xd1\x23\x4b\x10\x15\x8e\x04\x16\xc5\x7c\x94\x88\xf6\x63\xf2\x68\x37\x08\x66\xfd\x5a\x7b\x40\x58\x21\x6b\x2c\xc0\xf4\xdc\x91\xd3\x48\xed\xc1"[..]).into_boxed_slice() }; + let pkesk = + PKESK3::new(KeyID::wildcard(), PublicKeyAlgorithm::ECDH, ciphertext)?; // Session key - let dek = b"\x09\x0D\xDC\x40\xC5\x71\x51\x88\xAC\xBD\x45\x56\xD4\x2A\xDF\x77\xCD\xF4\x82\xA2\x1B\x8F\x2E\x48\x3B\xCA\xBF\xD3\xE8\x6D\x0A\x7C\xDF\x10\xe6"; + let dek = b"\x0D\xDC\x40\xC5\x71\x51\x88\xAC\xBD\x45\x56\xD4\x2A\xDF\x77\xCD\xF4\x82\xA2\x1B\x8F\x2E\x48\x3B\xCA\xBF\xD3\xE8\x6D\x0A\x7C\xDF"; - let key = key.parts_into_public(); - let got_dek = match key.optional_secret() { - Some(SecretKeyMaterial::Unencrypted(ref u)) => u.map(|mpis| { - ecdh::decrypt(&key, mpis, &ciphertext, None) - .unwrap() - }), - _ => unreachable!(), - }; + let key = key.parts_into_secret().unwrap(); + let mut keypair = key.into_keypair()?; + let (sym, got_dek) = pkesk.decrypt(&mut keypair, None).unwrap(); + assert_eq!(sym, SymmetricAlgorithm::AES256); assert_eq!(&dek[..], &got_dek[..]); + Ok(()) } #[test] |