age: Add test that X25519 and scrypt recipients are incompatible

This commit is contained in:
Jack Grigg 2024-08-10 06:45:20 +00:00
parent d2c2e895bf
commit 8091015514

View file

@ -301,7 +301,7 @@ mod tests {
use super::{Decryptor, Encryptor};
use crate::{
identity::{IdentityFile, IdentityFileEntry},
scrypt, x25519, Identity, Recipient,
scrypt, x25519, EncryptError, Identity, Recipient,
};
#[cfg(feature = "async")]
@ -510,4 +510,19 @@ mod tests {
.unwrap();
recipient_async_round_trip(vec![Box::new(pk)], iter::once(&sk as &dyn Identity));
}
#[test]
fn mixed_recipient_and_passphrase() {
let pk: x25519::Recipient = crate::x25519::tests::TEST_PK.parse().unwrap();
let passphrase = crate::scrypt::Recipient::new(SecretString::new("passphrase".to_string()));
let recipients = vec![Box::new(pk) as _, Box::new(passphrase) as _];
let mut encrypted = vec![];
let e = Encryptor::with_recipients(recipients).unwrap();
assert!(matches!(
e.wrap_output(&mut encrypted),
Err(EncryptError::MixedRecipientAndPassphrase),
));
}
}