From 3a80d2a1866b57b8c07f62ce095d951458e18430 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 19 Dec 2019 19:53:00 +0100 Subject: openpgp: Keep track whether a container has been streamed. - If a container was streamed, we can no longer compare it to other packets. Keep track of that, and use it in Container::PartialEq. - See #93. --- openpgp/src/parse/parse.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'openpgp/src/parse') diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 3c46726b..3722f79b 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -3442,7 +3442,7 @@ impl <'a> PacketParser<'a> { } else { self.state = state_; self.finish()?; - // XXX self.content_was_read = false; + // XXX self.set_content_was_read(false); let (fake_eof_, reader_) = buffered_reader_stack_pop( reader_, recursion_depth - 1)?; fake_eof = fake_eof_; @@ -3600,7 +3600,12 @@ impl <'a> PacketParser<'a> { /// # return Ok(()); /// # } pub fn buffer_unread_content(&mut self) -> Result<&[u8]> { + // If the packet has not yet been streamed, then the following + // read operation should not be considered streaming. + let content_was_read = self.content_was_read; let mut rest = self.steal_eof()?; + self.set_content_was_read(content_was_read); + match &mut self.packet { Packet::Literal(p) => { if rest.len() > 0 { @@ -3721,10 +3726,17 @@ impl <'a> PacketParser<'a> { /// Sets the content_was_read flag if `cond` is true. fn mark_content_was_read(&mut self, cond: bool) { if cond { + self.packet.container_mut().map(|c| c.set_streamed(true)); self.content_was_read = true; } } + /// Sets the content_was_read flag to `value`. + fn set_content_was_read(&mut self, value: bool) { + self.packet.container_mut().map(|c| c.set_streamed(value)); + self.content_was_read = value; + } + /// Returns a reference to the current packet's header. pub fn header(&self) -> &Header { &self.header -- cgit v1.2.3