diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-05-16 15:53:59 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-05-16 15:53:59 +0200 |
commit | 56e2e9a6205a21c42a1273114e2be8e373b0b8f3 (patch) | |
tree | 48aea56997f04d052b5a2aaa765cfc90180fad28 | |
parent | d2b7c908384084ea80eee100f2ab8b4995054950 (diff) |
Revert "openpgp: Provide a function to turn a PacketParser into an iterator."
This reverts commit 32c78a7358ba3c2b1290ae5dc298d885d098fe1d.
- This functionality is too easy a shortcut at too high a price: we
want to encourage users to use the PacketParser API to process
packets in a streaming manner, and to handle errors. This
iterator is very convenient, and does neither of these things.
-rw-r--r-- | openpgp/src/lib.rs | 10 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 68 |
2 files changed, 0 insertions, 78 deletions
diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 3c461c93..ec39ba72 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -160,16 +160,6 @@ pub enum Error { Io(#[cause] io::Error), } -/// Returns any pending error. -/// -/// This interface is useful, because using an iterator, the caller -/// cannot distinguish between no more items and an error. -pub trait IterError { - fn error(&mut self) -> Option<failure::Error> { - None - } -} - // A helpful debugging function. #[allow(dead_code)] fn to_hex(s: &[u8], pretty: bool) -> String { diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 70ccf44a..a2eaedea 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -2784,75 +2784,7 @@ mod test { } } } - -/// An iterator over a packet stream. -/// -/// This iterator recurses into any containers. -/// -/// Because parsing packets may result in an error, users of this -/// iterator should call iter.error() when they receive None to -/// determine if the iterator stopped due to an error or because the -/// packet stream was really exhausted. -pub struct PacketParserIter<'a> { - ppo: Option<PacketParser<'a>>, - error: Option<failure::Error>, -} - -impl<'a> Iterator for PacketParserIter<'a> { - type Item = Packet; - - fn next(&mut self) -> Option<Self::Item> { - if self.error.is_some() { - return None; - } - - let ppo = self.ppo.take(); - if let Some(pp) = ppo { - match pp.recurse() { - Ok((packet, _, ppo_tmp, _)) => { - self.ppo = ppo_tmp; - Some(packet) - }, - Err(err) => { - self.error = Some(err); - None - }, - } - } else { - None - } - } -} - -impl<'a> IterError for PacketParserIter<'a> { - /// Returns any pending error. - fn error(&mut self) -> Option<failure::Error> { - self.error.take() - } -} - -impl<'a> IntoIterator for PacketParser<'a> { - type Item = Packet; - type IntoIter = PacketParserIter<'a>; - - fn into_iter(self) -> Self::IntoIter { - PacketParserIter { - ppo: Some(self), - error: None, - } - } -} -#[test] -fn packet_parser_iter_test() { - let pp = PacketParser::from_file( - path_to("compressed-data-algo-1.gpg")).unwrap().unwrap(); - - let tags : Vec<Tag> = pp.into_iter().map(|p| p.tag()).collect(); - assert_eq!(&[ Tag::CompressedData, Tag::Literal ][..], - &tags[..]); -} - impl Message { // Reads all of the packets from a `PacketParser`, and turns them // into a message. Note: this assumes that `ppo` points to a |