summaryrefslogtreecommitdiffstats
path: root/openpgp/src/parse
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-07-24 15:49:43 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-07-24 16:45:10 +0200
commit0ac1c16d62b7a1900779be513579419f6a0ec730 (patch)
tree29b3c71f21b38c8cff04dd84de93c1dc561d9f33 /openpgp/src/parse
parent14fe75c02b0ae03440d5ba25efe8d1c64119272c (diff)
openpgp: Improve PacketParserResult::as_ref, as_mut, and map.
- Previously, these method withheld information in the EOF case (and in case of `map` this loss is irrecoverable). Fix this by returning a Result instead.
Diffstat (limited to 'openpgp/src/parse')
-rw-r--r--openpgp/src/parse/packet_pile_parser.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs
index 2540026a..78483b82 100644
--- a/openpgp/src/parse/packet_pile_parser.rs
+++ b/openpgp/src/parse/packet_pile_parser.rs
@@ -54,7 +54,7 @@ use buffered_reader::BufferedReader;
/// # include_bytes!("../../tests/data/keys/public-key.gpg");
/// # let mut n = 0;
/// let mut ppp = PacketPileParser::from_bytes(message_data)?;
-/// while let Some(pp) = ppp.as_ref() {
+/// while let Ok(pp) = ppp.as_ref() {
/// eprintln!("{:?}", pp);
/// ppp.recurse()?;
/// # n += 1;
@@ -198,7 +198,7 @@ impl<'a> PacketPileParser<'a> {
/// let message_data: &[u8] = // ...
/// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp");
/// let mut ppp = PacketPileParser::from_bytes(message_data)?;
- /// while let Some(pp) = ppp.as_ref() {
+ /// while let Ok(pp) = ppp.as_ref() {
/// // Do something interesting with `pp` here.
///
/// // Start parsing the next packet, recursing.
@@ -251,7 +251,7 @@ impl<'a> PacketPileParser<'a> {
/// let message_data: &[u8] = // ...
/// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp");
/// let mut ppp = PacketPileParser::from_bytes(message_data)?;
- /// while let Some(pp) = ppp.as_ref() {
+ /// while let Ok(pp) = ppp.as_ref() {
/// // Do something interesting with `pp` here.
///
/// // Start parsing the next packet.
@@ -296,7 +296,7 @@ impl<'a> PacketPileParser<'a> {
/// let message_data: &[u8] = // ...
/// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp");
/// let mut ppp = PacketPileParser::from_bytes(message_data)?;
- /// while let Some(pp) = ppp.as_ref() {
+ /// while let Ok(pp) = ppp.as_ref() {
/// match pp.packet {
/// Packet::CompressedData(_) =>
/// assert_eq!(ppp.recursion_depth(), Some(0)),
@@ -424,7 +424,7 @@ fn message_parser_reader_interface() {
let mut ppp = PacketPileParser::from_bytes(
crate::tests::message("compressed-data-algo-1.gpg")).unwrap();
let mut count = 0;
- while let Some(pp) = ppp.as_mut() {
+ while let Ok(pp) = ppp.as_mut() {
if let Packet::Literal(_) = pp.packet {
assert_eq!(count, 1); // The *second* packet.