diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-02-22 16:23:44 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-02-24 11:08:00 +0100 |
commit | 6529777daf9118b90928a77b051024e67fe2b4dd (patch) | |
tree | 08fb37e58e5f0548346aacf0e7c5b16ebba7f561 /buffered-reader | |
parent | de9cef3b7092eaaedd31569df0ea49afc951b343 (diff) |
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.
Diffstat (limited to 'buffered-reader')
-rw-r--r-- | buffered-reader/src/generic.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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<T: io::Read + Send + Sync, C: fmt::Debug + Sync + Send> Generic<T, C> { /// 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<T: io::Read + Send + Sync, C: fmt::Debug + Sync + Send> BufferedReader<C> 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: {:?})", |