From c9aa8f586ee339adbe3baa3f8da63491e3b1bd13 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 21 Aug 2023 13:44:30 +0200 Subject: openpgp: Shortcut parse_finish for non-document signatures. --- openpgp/src/parse.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'openpgp/src/parse.rs') diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index c6fa646b..495f866e 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1310,12 +1310,28 @@ impl Signature { Signature4::plausible(bio, header) } + /// When parsing an inline-signed message, attaches the digest to + /// the signature. fn parse_finish(indent: isize, mut pp: PacketParser, typ: SignatureType, hash_algo: HashAlgorithm) -> Result { tracer!(TRACE, "Signature::parse_finish", indent); + let sig: &Signature = pp.packet.downcast_ref() + .ok_or_else( + || Error::InvalidOperation( + format!("Called Signature::parse_finish on a {:?}", + pp.packet)))?; + + // If we are not parsing an inline-signed message, we are + // done. + if sig.typ() != SignatureType::Binary + && sig.typ() != SignatureType::Text + { + return Ok(pp); + } + let need_hash = HashingMode::for_signature(hash_algo, typ); // Locate the corresponding HashedReader and extract the -- cgit v1.2.3