From 6529777daf9118b90928a77b051024e67fe2b4dd Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 22 Feb 2021 16:23:44 +0100 Subject: openpgp: Inline buffered_reader::Generic. - Previously, armor::Reader implemented BufferedReader using the Generic reader on top of IoReader's io::Read implementation. However, that is no longer good enough, because we need to access the cookie from (Io)Reader::initialize. - The real fix is to directly implement the BufferedReader protocol. That would have been the right thing to do from the beginning, instead of using buffered_reader::Generic. This may actually simplify the code and reduce buffering. However, implementing the BufferedReader protocol is a bit error-prone, so we defer it once again! - Instead, manually inline the code from the Generic reader. - In the following commits, we will take advantage of that and access the cookie. --- buffered-reader/src/generic.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'buffered-reader') diff --git a/buffered-reader/src/generic.rs b/buffered-reader/src/generic.rs index d2e9acfa..8d6ec104 100644 --- a/buffered-reader/src/generic.rs +++ b/buffered-reader/src/generic.rs @@ -99,6 +99,11 @@ impl Generic { /// Return the buffer. Ensure that it contains at least `amount` /// bytes. + // + // Note: + // + // If you find a bug in this function, consider whether + // sequoia_openpgp::armor::Reader::data_helper is also affected. fn data_helper(&mut self, amount: usize, hard: bool, and_consume: bool) -> Result<&[u8], io::Error> { // println!("Generic.data_helper(\ @@ -229,6 +234,10 @@ impl BufferedReader f return self.data_helper(amount, true, false); } + // Note: + // + // If you find a bug in this function, consider whether + // sequoia_openpgp::armor::Reader::consume is also affected. fn consume(&mut self, amount: usize) -> &[u8] { // println!("Generic.consume({}) \ // (cursor: {}, buffer: {:?})", -- cgit v1.2.3