summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-11-14 12:08:49 +0100
committerJustus Winter <justus@sequoia-pgp.org>2023-11-14 12:34:25 +0100
commitfb84b5223bf94941d4bd2decb105f8f03d7468a7 (patch)
tree2427881e403f764a1e4268675ea26fb027ea96f5
parenta9982139d733e9b1c2c452ce962165971621e466 (diff)
openpgp: Add new test.
- Tests that an inline-signed message using two different hash algorithms verifies correctly.
-rw-r--r--openpgp/src/parse/stream.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 870c728f..32f55362 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -4022,4 +4022,51 @@ xHUDBRY0WIQ+50WENDPP";
Ok(())
}
+
+ /// Tests that an inline-signed message using two different hash
+ /// algorithms verifies correctly.
+ #[test]
+ fn inline_signed_two_hashes() -> Result<()> {
+ use crate::{
+ types::{DataFormat, HashAlgorithm, SignatureType},
+ packet::Literal,
+ parse::SignatureBuilder,
+ };
+ let p = P::new();
+ let cert = Cert::from_bytes(crate::tests::key("testy-private.pgp"))?;
+ let helper = VHelper::new(0, 0, 0, 0, vec![cert.clone()]);
+ let mut signer = cert.primary_key().key().clone().parts_into_secret()?
+ .into_keypair()?;
+ let msg = b"Hello, world!";
+ let sig0 = SignatureBuilder::new(SignatureType::Binary)
+ .set_signature_creation_time(crate::frozen_time())?
+ .set_hash_algo(HashAlgorithm::SHA256)
+ .sign_message(&mut signer, msg)?;
+ let sig1 = SignatureBuilder::new(SignatureType::Binary)
+ .set_signature_creation_time(crate::frozen_time())?
+ .set_hash_algo(HashAlgorithm::SHA512)
+ .sign_message(&mut signer, msg)?;
+ let packets: Vec<Packet> = vec![
+ OnePassSig::try_from(&sig0)?.into(),
+ {
+ let mut ops = OnePassSig::try_from(&sig1)?;
+ ops.set_last(true);
+ ops.into()
+ },
+ {
+ let mut lit = Literal::new(DataFormat::Binary);
+ lit.set_body((*msg).into());
+ lit.into()
+ },
+ sig1.into(),
+ sig0.into(),
+ ];
+ let mut buf = Vec::new();
+ packets.iter().for_each(|p| p.serialize(&mut buf).unwrap());
+ let v = VerifierBuilder::from_bytes(&buf)?
+ .with_policy(&p, crate::frozen_time(), helper)?;
+ assert!(v.message_processed());
+ assert_eq!(v.helper_ref().good, 2);
+ Ok(())
+ }
}