diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-07-05 15:02:04 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-07-05 15:02:04 +0200 |
commit | bc7214228a10b613057a8c319534d2fd4560175f (patch) | |
tree | 1918e920192d43b2cef60d89921b43f5f52ddf36 | |
parent | fe58f69466d947f51d7bd43e474f5fec2e8e7cc9 (diff) |
openpgp: Don't put the packet body in the map unless we're buffering
- Previously, Sequoia would buffer packet bodies when mapping is
enabled in the parser, even if the packet parser is not
configured to buffer the bodies. This adds considerable
overhead.
- With this change, Sequoia no longer includes the packet bodies in
the maps unless the parser is configured to buffer any unread
content.
- This makes parsing packets faster if you don't rely on the packet
body in the map, but changes the default behavior. If you need
the old behavior, please do adjust your code to buffer unread
content.
-rw-r--r-- | openpgp/NEWS | 13 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 6 | ||||
-rw-r--r-- | openpgp/src/parse/map.rs | 5 |
3 files changed, 23 insertions, 1 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index 9813c082..ba31c24e 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -8,6 +8,19 @@ - Sequoia now ignores some formatting errors when reading secret keys. Being lenient in this case helps the user recover their valuable key material. + - Previously, Sequoia would buffer packet bodies when mapping is + enabled in the parser, even if the packet parser is not + configured to buffer the bodies. This adds considerable + overhead. + + Starting with this version, Sequoia no longer includes the packet + bodies in the maps unless the parser is configured to buffer any + unread content. + + This makes parsing packets faster if you don't rely on the packet + body in the map, but changes the default behavior. If you need + the old behavior, please do adjust your code to buffer unread + content. ** New functionality - crypto::SessionKey::as_protected - types::AEADAlgorithm::GCM diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index f5b3bff8..b6289219 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -530,7 +530,11 @@ impl<'a> PacketHeaderParser<'a> { if self.state.settings.map { // Steal the body for the map. self.reader.rewind(); - let body = self.reader.steal_eof()?; + let body = if self.state.settings.buffer_unread_content { + self.reader.steal_eof()? + } else { + self.reader.steal(total_out)? + }; if body.len() > total_out { self.field("body", body.len() - total_out); } diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index 996f1c09..2657e1ed 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -14,6 +14,7 @@ //! let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; //! let pp = PacketParserBuilder::from_bytes(message_data)? //! .map(true) // Enable mapping. +//! .buffer_unread_content() // For the packet body. //! .build()? //! .expect("One packet, not EOF"); //! let map = pp.map().expect("Mapping is enabled"); @@ -83,6 +84,7 @@ impl Map { /// let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; /// let pp = PacketParserBuilder::from_bytes(message_data)? /// .map(true) // Enable mapping. + /// .buffer_unread_content() // For the packet body. /// .build()? /// .expect("One packet, not EOF"); /// let map = pp.map().expect("Mapping is enabled"); @@ -170,6 +172,7 @@ impl<'a> Field<'a> { /// let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; /// let pp = PacketParserBuilder::from_bytes(message_data)? /// .map(true) // Enable mapping. + /// .buffer_unread_content() // For the packet body. /// .build()? /// .expect("One packet, not EOF"); /// let map = pp.map().expect("Mapping is enabled"); @@ -199,6 +202,7 @@ impl<'a> Field<'a> { /// let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; /// let pp = PacketParserBuilder::from_bytes(message_data)? /// .map(true) // Enable mapping. + /// .buffer_unread_content() // For the packet body. /// .build()? /// .expect("One packet, not EOF"); /// let map = pp.map().expect("Mapping is enabled"); @@ -228,6 +232,7 @@ impl<'a> Field<'a> { /// let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; /// let pp = PacketParserBuilder::from_bytes(message_data)? /// .map(true) // Enable mapping. + /// .buffer_unread_content() // For the packet body. /// .build()? /// .expect("One packet, not EOF"); /// let map = pp.map().expect("Mapping is enabled"); |