diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-05-30 12:03:15 +0200 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-06-06 10:37:51 +0200 |
commit | f5f9b14a304321816526c30ce98edbd6535df9c4 (patch) | |
tree | ccc0f752f9e1ea1037bd4f37a59a52387cd9e7fb /openpgp | |
parent | 4f3d260a013835a8ab0b2f15f45e22ca4678ab24 (diff) |
buffered_reader: Introduce `into_boxed` and deprecate `as_boxed`.
- According to the Rust API Guidelines, a conversion function taking
self should be called `into_*` if the self is not Copy, so this
function should be named `into_boxed`.
- Deprecate old function not to break the API.
- Update all references in the code.
- Fixes https://gitlab.com/sequoia-pgp/sequoia/-/issues/781
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/cert/raw.rs | 10 | ||||
-rw-r--r-- | openpgp/src/crypto/aead.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/symmetric.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 8 | ||||
-rw-r--r-- | openpgp/src/parse/hashed_reader.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/mpis.rs | 14 | ||||
-rw-r--r-- | openpgp/src/parse/packet_parser_builder.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/partial_body.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 6 |
9 files changed, 24 insertions, 24 deletions
diff --git a/openpgp/src/cert/raw.rs b/openpgp/src/cert/raw.rs index c16de091..f999e66d 100644 --- a/openpgp/src/cert/raw.rs +++ b/openpgp/src/cert/raw.rs @@ -614,12 +614,12 @@ impl<'a> RawCertParser<'a> { } // Strip the Dup reader. - let mut reader = dup.as_boxed().into_inner().expect("inner"); + let mut reader = dup.into_boxed().into_inner().expect("inner"); if dearmor { reader = armor::Reader::from_buffered_reader( reader, armor::ReaderMode::Tolerant(None), - Default::default()).as_boxed(); + Default::default()).into_boxed(); let mut dup = Dup::with_cookie(reader, Default::default()); match Header::parse(&mut dup) { @@ -639,7 +639,7 @@ impl<'a> RawCertParser<'a> { } } - reader = dup.as_boxed().into_inner().expect("inner"); + reader = dup.into_boxed().into_inner().expect("inner"); } Ok(RawCertParser { @@ -703,7 +703,7 @@ impl<'a> Iterator for RawCertParser<'a> // Get the reader, let reader = std::mem::replace( &mut self.reader, - EOF::with_cookie(Default::default()).as_boxed()); + EOF::with_cookie(Default::default()).into_boxed()); // peel off the armor reader, let reader = reader.into_inner().expect("the armor reader"); @@ -711,7 +711,7 @@ impl<'a> Iterator for RawCertParser<'a> // and install a new one! self.reader = armor::Reader::from_buffered_reader( reader, armor::ReaderMode::Tolerant(None), - Default::default()).as_boxed(); + Default::default()).into_boxed(); } if self.reader.eof() { diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index b6fcc578..ae81cbf7 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -571,7 +571,7 @@ impl<'a, S: Schedule> BufferedReader<Cookie> for BufferedReaderDecryptor<'a, S> fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where Self: 'b { - Some(self.reader.into_reader().source.as_boxed()) + Some(self.reader.into_reader().source.into_boxed()) } fn cookie_set(&mut self, cookie: Cookie) -> Cookie { diff --git a/openpgp/src/crypto/symmetric.rs b/openpgp/src/crypto/symmetric.rs index ea4beb11..0652497c 100644 --- a/openpgp/src/crypto/symmetric.rs +++ b/openpgp/src/crypto/symmetric.rs @@ -264,7 +264,7 @@ impl<'a> BufferedReader<Cookie> for BufferedReaderDecryptor<'a> { fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where Self: 'b { - Some(self.reader.into_reader().source.as_boxed()) + Some(self.reader.into_reader().source.into_boxed()) } fn cookie_set(&mut self, cookie: Cookie) -> Cookie { diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 2dc9fad5..7c34f62b 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -341,7 +341,7 @@ macro_rules! impl_parse_with_buffered_reader { fn from_buffered_reader<'a, B>(br: B) -> Result<Self> where B: 'a + BufferedReader<Cookie>, { - Ok($from_buffered_reader(br.as_boxed())?) + Ok($from_buffered_reader(br.into_boxed())?) } } @@ -1110,7 +1110,7 @@ impl<'a> Parse<'a, S2K> for S2K { fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self> { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut parser = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut parser = PacketHeaderParser::new_naked(bio.into_boxed()); Self::parse_v4(&mut parser) } } @@ -3052,7 +3052,7 @@ impl<'a> Parse<'a, MPI> for MPI { fn from_reader<R: io::Read + Send + Sync>(reader: R) -> Result<Self> { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut parser = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut parser = PacketHeaderParser::new_naked(bio.into_boxed()); Self::parse("(none_len)", "(none)", &mut parser) } } @@ -3533,7 +3533,7 @@ impl<'a> PacketParserEOF<'a> { Self::new( PacketParserState::new(Default::default()), buffered_reader::Memory::with_cookie(b"", Default::default()) - .as_boxed()) + .into_boxed()) } /// Returns whether the stream is an OpenPGP Message. diff --git a/openpgp/src/parse/hashed_reader.rs b/openpgp/src/parse/hashed_reader.rs index f70775cc..cc481374 100644 --- a/openpgp/src/parse/hashed_reader.rs +++ b/openpgp/src/parse/hashed_reader.rs @@ -434,7 +434,7 @@ impl<R: BufferedReader<Cookie>> fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where Self: 'b { - Some(self.reader.as_boxed()) + Some(self.reader.into_boxed()) } fn cookie_set(&mut self, cookie: Cookie) -> Cookie { diff --git a/openpgp/src/parse/mpis.rs b/openpgp/src/parse/mpis.rs index b1351ee8..cfadbc70 100644 --- a/openpgp/src/parse/mpis.rs +++ b/openpgp/src/parse/mpis.rs @@ -26,7 +26,7 @@ impl mpi::PublicKey { { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php) } @@ -160,7 +160,7 @@ impl mpi::SecretKeyMaterial { -> Result<Self> { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php, Some(checksum)) } @@ -173,7 +173,7 @@ impl mpi::SecretKeyMaterial { -> Result<Self> { let bio = buffered_reader::Memory::with_cookie( bytes, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php, Some(checksum)) } @@ -189,7 +189,7 @@ impl mpi::SecretKeyMaterial { { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php, None) } @@ -201,7 +201,7 @@ impl mpi::SecretKeyMaterial { pub fn from_bytes(algo: PublicKeyAlgorithm, buf: &[u8]) -> Result<Self> { let bio = buffered_reader::Memory::with_cookie( buf, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php, None) } @@ -336,7 +336,7 @@ impl mpi::Ciphertext { { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php) } @@ -415,7 +415,7 @@ impl mpi::Signature { { let bio = buffered_reader::Generic::with_cookie( reader, None, Cookie::default()); - let mut php = PacketHeaderParser::new_naked(bio.as_boxed()); + let mut php = PacketHeaderParser::new_naked(bio.into_boxed()); Self::_parse(algo, &mut php) } diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs index e23767a0..006f7db7 100644 --- a/openpgp/src/parse/packet_parser_builder.rs +++ b/openpgp/src/parse/packet_parser_builder.rs @@ -437,7 +437,7 @@ impl<'a> PacketParserBuilder<'a> { self.bio = armor::Reader::from_buffered_reader_csft(self.bio, Some(mode), Cookie::new(ARMOR_READER_LEVEL), self.csf_transformation) - .as_boxed(); + .into_boxed(); } // Parse the first packet. diff --git a/openpgp/src/parse/partial_body.rs b/openpgp/src/parse/partial_body.rs index 0ae9bad4..43bf2b62 100644 --- a/openpgp/src/parse/partial_body.rs +++ b/openpgp/src/parse/partial_body.rs @@ -407,7 +407,7 @@ impl<T: BufferedReader<Cookie>> BufferedReader<Cookie> fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where Self: 'b { - Some(self.reader.as_boxed()) + Some(self.reader.into_boxed()) } fn cookie_set(&mut self, cookie: Cookie) -> Cookie { diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index b59005e7..7a188bc4 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -1616,19 +1616,19 @@ impl<'a, H: VerificationHelper> DetachedVerifier<'a, H> { /// Verifies the given data. pub fn verify_reader<R: io::Read + Send + Sync>(&mut self, reader: R) -> Result<()> { self.verify(buffered_reader::Generic::with_cookie( - reader, None, Default::default()).as_boxed()) + reader, None, Default::default()).into_boxed()) } /// Verifies the given data. pub fn verify_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()> { self.verify(buffered_reader::File::with_cookie( - path, Default::default())?.as_boxed()) + path, Default::default())?.into_boxed()) } /// Verifies the given data. pub fn verify_bytes<B: AsRef<[u8]>>(&mut self, buf: B) -> Result<()> { self.verify(buffered_reader::Memory::with_cookie( - buf.as_ref(), Default::default()).as_boxed()) + buf.as_ref(), Default::default()).into_boxed()) } /// Verifies the given data. |