From fb84b5223bf94941d4bd2decb105f8f03d7468a7 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 14 Nov 2023 12:08:49 +0100 Subject: openpgp: Add new test. - Tests that an inline-signed message using two different hash algorithms verifies correctly. --- openpgp/src/parse/stream.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'openpgp') 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 = 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(()) + } } -- cgit v1.2.3