summaryrefslogtreecommitdiffstats
path: root/openpgp/src/parse
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-07-03 17:58:05 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-07-07 15:29:28 +0200
commita30a2cf128feb0ac8ee763c5b80d348900cca6b0 (patch)
treed654ba75a8183b25dd935ea14063fcfbcc5c12a6 /openpgp/src/parse
parenteebc463f41560d54defe3bcd6aac2ddc365bde0f (diff)
openpgp: Add a way to disable automatic hashing.
- When encountering a one-pass-signature packet, the packet parser will, by default, start hashing later packets using the hash algorithm specified in the packet. In some cases, this is not needed, and hashing will incur a non-trivial overhead. - See #1034.
Diffstat (limited to 'openpgp/src/parse')
-rw-r--r--openpgp/src/parse/packet_parser_builder.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs
index 006f7db7..52ac1027 100644
--- a/openpgp/src/parse/packet_parser_builder.rs
+++ b/openpgp/src/parse/packet_parser_builder.rs
@@ -364,6 +364,32 @@ impl<'a> PacketParserBuilder<'a> {
self
}
+ /// Controls automatic hashing.
+ ///
+ /// When encountering a [`OnePassSig`] packet, the packet parser
+ /// will, by default, start hashing later packets using the hash
+ /// algorithm specified in the packet. In some cases, this is not
+ /// needed, and hashing will incur a non-trivial overhead.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # fn main() -> sequoia_openpgp::Result<()> {
+ /// # use sequoia_openpgp as openpgp;
+ /// # use openpgp::parse::{Parse, PacketParserBuilder};
+ /// #
+ /// let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
+ /// let pp = PacketParserBuilder::from_bytes(message_data)?
+ /// .automatic_hashing(false) // Disable automatic hashing.
+ /// .build()?
+ /// .expect("One packet, not EOF");
+ /// # Ok(()) }
+ /// ```
+ pub fn automatic_hashing(mut self, enable: bool) -> Self {
+ self.settings.automatic_hashing = enable;
+ self
+ }
+
/// Controls transparent transformation of messages using the
/// cleartext signature framework into signed messages.
///