diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 16:42:59 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 18:18:30 +0200 |
commit | 2e1eec5fe4157a391a13554ff7df3075cfe043cc (patch) | |
tree | 03ac579ba58d27c08a7ac16ca16f687d1a9456ed /openpgp/src | |
parent | c1516c59709fa47d13100daddb57657008a793c3 (diff) |
openpgp: Make PacketParserResult a std::result::Result.
- This avoids the partial implementation imitating
std::option::Option, replacing it with std::result::Result.
- As a benefit, std::result::Result is in the prelude, simplifying a
lot of parsing loops.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/cert/mod.rs | 4 | ||||
-rw-r--r-- | openpgp/src/cert/parser/mod.rs | 6 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 18 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 185 | ||||
-rw-r--r-- | openpgp/src/parse/packet_parser_builder.rs | 12 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 24 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 18 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 10 |
12 files changed, 110 insertions, 179 deletions
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 861fdd83..e72db089 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -312,7 +312,7 @@ use super::*; /// ```rust /// # extern crate sequoia_openpgp as openpgp; /// # use openpgp::Result; -/// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +/// # use openpgp::parse::{Parse, PacketParser}; /// use openpgp::cert::prelude::*; /// /// # fn main() { f().unwrap(); } @@ -387,7 +387,7 @@ use super::*; /// # extern crate sequoia_openpgp as openpgp; /// # use std::convert::TryFrom; /// # use openpgp::Result; -/// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +/// # use openpgp::parse::{Parse, PacketParser}; /// use openpgp::Cert; /// /// # fn main() { f().unwrap(); } diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index 50cc7e5a..da0194bc 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -394,7 +394,7 @@ enum PacketSource<'a, I: Iterator<Item=Packet>> { /// ```rust /// # extern crate sequoia_openpgp as openpgp; /// # use openpgp::Result; -/// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +/// # use openpgp::parse::{Parse, PacketParser}; /// use openpgp::cert::prelude::*; /// /// # fn main() { f().unwrap(); } @@ -441,7 +441,7 @@ impl<'a> From<PacketParserResult<'a>> for CertParser<'a, vec::IntoIter<Packet>> /// Initializes a `CertParser` from a `PacketParser`. fn from(ppr: PacketParserResult<'a>) -> Self { let mut parser : Self = Default::default(); - if let PacketParserResult::Some(pp) = ppr { + if let Ok(pp) = ppr { parser.source = PacketSource::PacketParser(pp); } parser @@ -731,7 +731,7 @@ impl<'a, I: Iterator<Item=Packet>> Iterator for CertParser<'a, I> { match pp.next() { Ok((packet, ppr)) => { - if let PacketParserResult::Some(pp) = ppr { + if let Ok(pp) = ppr { self.source = PacketSource::PacketParser(pp); } diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 8dff4693..40a26bda 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -416,7 +416,7 @@ mod tests { // Get the next packet. let (_, ppr) = pp.next().unwrap(); - assert!(ppr.is_none()); + assert!(ppr.is_err()); } } diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index d06ac07e..29409ace 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -29,7 +29,7 @@ //! ```rust //! # extern crate sequoia_openpgp as openpgp; //! # use openpgp::Result; -//! # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +//! # use openpgp::parse::{Parse, PacketParser}; //! # use openpgp::cert::prelude::*; //! use openpgp::packet::{Key, key}; //! diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 66c0065a..b294ae5a 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1283,7 +1283,7 @@ mod test { use super::*; use crate::Cert; - use crate::parse::{PacketParserResult, PacketParser}; + use crate::parse::PacketParser; struct Test<'a> { key: &'a str, @@ -1369,7 +1369,7 @@ mod test { let mut good = 0; let mut ppr = PacketParser::from_bytes( crate::tests::message(test.data)).unwrap(); - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { if let Packet::Signature(ref sig) = pp.packet { let result = sig.verify(cert.primary_key().key()) .map(|_| true).unwrap_or(false); diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 605d48d2..ac000842 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -34,13 +34,13 @@ //! # extern crate sequoia_openpgp as openpgp; //! # use openpgp::Result; //! # use openpgp::Packet; -//! # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +//! # use openpgp::parse::{Parse, PacketParser}; //! # //! # f(include_bytes!("../../../tests/data/messages/signed.gpg")); //! # //! # fn f(message_data: &[u8]) -> Result<()> { //! let mut ppr = PacketParser::from_bytes(message_data)?; -//! while let PacketParserResult::Some(mut pp) = ppr { +//! while let Ok(mut pp) = ppr { //! if let Packet::Signature(ref sig) = pp.packet { //! if let Some(fp) = sig.issuer_fingerprint() { //! eprintln!("Signature issued by: {}", fp.to_string()); diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 250d9f14..d3ced30f 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -349,7 +349,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { // ppo.recursion_depth and leave the rest of the message, but // it is hard to imagine that that is what the caller wants. // Instead of hiding that error, fail fast. - if let PacketParserResult::Some(ref pp) = ppr { + if let Ok(ref pp) = ppr { if pp.recursion_depth() != 0 { return Err(Error::InvalidOperation( format!("Expected top-level packet, \ @@ -363,7 +363,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { let mut last_position = 0; - if ppr.is_none() { + if ppr.is_err() { // Empty message. return Ok(PacketPile::from(Vec::new())); } @@ -414,7 +414,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { container.children_mut().unwrap().push(packet); - if ppr.is_none() { + if ppr.is_err() { break 'outer; } @@ -561,7 +561,7 @@ mod test { .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); - while ppr.is_some() { + while ppr.is_ok() { ppr = ppp.recurse().unwrap(); } let pile = ppp.finish(); @@ -576,7 +576,7 @@ mod test { .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); - while let Some(pp) = ppr.as_mut() { + while let Ok(pp) = ppr.as_mut() { eprintln!("{:?}", pp); ppr = ppp.recurse().unwrap(); } @@ -620,13 +620,13 @@ mod test { let mut count = 0; loop { - if let PacketParserResult::Some(pp2) = ppr { + if let Ok(pp2) = ppr { count += 1; let packet_depth = pp2.recursion_depth(); let pp2 = pp2.recurse().unwrap().1; assert_eq!(packet_depth, count - 1); - if pp2.is_some() { + if pp2.is_ok() { assert_eq!(pp2.as_ref().unwrap().recursion_depth(), count); } ppr = pp2; @@ -664,7 +664,7 @@ mod test { // recurse should now not recurse. Since there is nothing // following the compressed packet, ppr should be EOF. let (packet, ppr) = pp.next().unwrap(); - assert!(ppr.is_none()); + assert!(ppr.is_err()); // Get the rest of the content and put the initial byte that // we stole back. @@ -680,7 +680,7 @@ mod test { // And we're done... let ppr = pp.next().unwrap().1; - assert!(ppr.is_none()); + assert!(ppr.is_err()); } #[test] diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index c8c42a29..fb556ad2 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -212,13 +212,13 @@ macro_rules! impl_parse_generic_packet { pp.buffer_unread_content()?; match pp.next()? { - (Packet::$typ(o), PacketParserResult::EOF(_)) + (Packet::$typ(o), Err(_)) => Ok(o), - (p, PacketParserResult::EOF(_)) => + (p, Err(_)) => Err(Error::InvalidOperation( format!("Not a {} packet: {:?}", stringify!($typ), p)).into()), - (_, PacketParserResult::Some(_)) => + (_, Ok(_)) => Err(Error::InvalidOperation( "Excess data after packet".into()).into()), } @@ -1821,7 +1821,7 @@ fn one_pass_sig_test () { let mut one_pass_sigs = 0; let mut sigs = 0; - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { if let Packet::OnePassSig(_) = pp.packet { one_pass_sigs += 1; } else if let Packet::Signature(ref sig) = pp.packet { @@ -2065,14 +2065,14 @@ impl<'a> Parse<'a, key::UnspecifiedKey> for key::UnspecifiedKey { pp.buffer_unread_content()?; match pp.next()? { - (Packet::PublicKey(o), PacketParserResult::EOF(_)) => Ok(o.into()), - (Packet::PublicSubkey(o), PacketParserResult::EOF(_)) => Ok(o.into()), - (Packet::SecretKey(o), PacketParserResult::EOF(_)) => Ok(o.into()), - (Packet::SecretSubkey(o), PacketParserResult::EOF(_)) => Ok(o.into()), - (p, PacketParserResult::EOF(_)) => + (Packet::PublicKey(o), Err(_)) => Ok(o.into()), + (Packet::PublicSubkey(o), Err(_)) => Ok(o.into()), + (Packet::SecretKey(o), Err(_)) => Ok(o.into()), + (Packet::SecretSubkey(o), Err(_)) => Ok(o.into()), + (p, Err(_)) => Err(Error::InvalidOperation( format!("Not a Key packet: {:?}", p)).into()), - (_, PacketParserResult::Some(_)) => + (_, Ok(_)) => Err(Error::InvalidOperation( "Excess data after packet".into()).into()), } @@ -2331,7 +2331,7 @@ fn compressed_data_parser_test () { } // And, we're done... - assert!(ppr.is_none()); + assert!(ppr.is_err()); } } @@ -2673,18 +2673,18 @@ impl<'a> Parse<'a, Packet> for Packet { ?.buffer_unread_content().build()?; let (p, ppr) = match ppr { - PacketParserResult::Some(pp) => { + Ok(pp) => { pp.next()? }, - PacketParserResult::EOF(_) => + Err(_) => return Err(Error::InvalidOperation( "Unexpected EOF".into()).into()), }; match (p, ppr) { - (p, PacketParserResult::EOF(_)) => + (p, Err(_)) => Ok(p), - (_, PacketParserResult::Some(_)) => + (_, Ok(_)) => Err(Error::InvalidOperation( "Excess data after packet".into()).into()), } @@ -2754,12 +2754,12 @@ impl PacketParserState { /// # extern crate sequoia_openpgp as openpgp; /// # use openpgp::Result; /// # use openpgp::Packet; -/// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; +/// # use openpgp::parse::{Parse, PacketParser}; /// # let _ = f(include_bytes!("../tests/data/keys/public-key.gpg")); /// # /// # fn f(message_data: &[u8]) -> Result<()> { /// let mut ppr = PacketParser::from_bytes(message_data)?; -/// while let PacketParserResult::Some(mut pp) = ppr { +/// while let Ok(mut pp) = ppr { /// // Process the packet. /// /// if let Packet::Literal(_) = pp.packet { @@ -2916,90 +2916,21 @@ impl PacketParserEOF { /// We don't use an `Option`, because when we reach the end of the /// packet sequence, some information about the message needs to /// remain accessible. -#[derive(Debug)] -pub enum PacketParserResult<'a> { - /// A `PacketParser` for the next packet. - Some(PacketParser<'a>), - /// Information about a fully parsed packet sequence. - EOF(PacketParserEOF), -} - -impl<'a> PacketParserResult<'a> { - /// Like `Option::is_none`(). - pub fn is_none(&self) -> bool { - if let PacketParserResult::EOF(_) = self { - true - } else { - false - } - } - - /// An alias for `is_none`(). - pub fn is_eof(&self) -> bool { - Self::is_none(self) - } - - /// Like `Option::is_some`(). - pub fn is_some(&self) -> bool { - ! Self::is_none(self) - } - - /// Like `Option::expect`(). - pub fn expect(self, msg: &str) -> PacketParser<'a> { - if let PacketParserResult::Some(pp) = self { - return pp; - } else { - panic!("{}", msg); - } - } - - /// Like `Option::unwrap`(). - pub fn unwrap(self) -> PacketParser<'a> { - self.expect("called `PacketParserResult::unwrap()` on a \ - `PacketParserResult::PacketParserEOF` value") - } +pub type PacketParserResult<'a> = + std::result::Result<PacketParser<'a>, PacketParserEOF>; - /// Like `Option::as_ref`(). - pub fn as_ref(&self) -> Option<&PacketParser<'a>> { - if let PacketParserResult::Some(ref pp) = self { - Some(pp) - } else { - None - } - } - - /// Like `Option::as_mut`(). - pub fn as_mut(&mut self) -> Option<&mut PacketParser<'a>> { - if let PacketParserResult::Some(ref mut pp) = self { - Some(pp) - } else { - None - } - } - - /// Like `Option::take`(). - /// - /// `self` is replaced with a `PacketParserEOF` with default - /// values. - pub fn take(&mut self) -> Self { - mem::replace( - self, - PacketParserResult::EOF( - PacketParserEOF::new( - PacketParserState::new(Default::default())))) - } - - /// Like `Option::map`(). - pub fn map<U, F>(self, f: F) -> Option<U> - where F: FnOnce(PacketParser<'a>) -> U - { - match self { - PacketParserResult::Some(x) => Some(f(x)), - PacketParserResult::EOF(_) => None, - } - } +/// Like `Option::take`() for PacketParserResult. +/// +/// `self` is replaced with a `PacketParserEOF` with default values. +fn packet_parser_result_take<'a>(ppr: &mut PacketParserResult<'a>) + -> PacketParserResult<'a> { + mem::replace( + ppr, + Err(PacketParserEOF::new( + PacketParserState::new(Default::default())))) } + impl<'a> Parse<'a, PacketParserResult<'a>> for PacketParser<'a> { /// Starts parsing an OpenPGP message stored in a `std::io::Read` object. /// @@ -3533,7 +3464,7 @@ impl <'a> PacketParser<'a> { let mut eof = PacketParserEOF::new(state_); eof.last_path = self.last_path; return Ok((self.packet, - PacketParserResult::EOF(eof))); + Err(eof))); } else { self.state = state_; self.finish()?; @@ -3556,7 +3487,7 @@ impl <'a> PacketParser<'a> { pp.last_path = self.last_path; - return Ok((self.packet, PacketParserResult::Some(pp))); + return Ok((self.packet, Ok(pp))); } } } @@ -3626,7 +3557,7 @@ impl <'a> PacketParser<'a> { pp.last_path = last_path; return Ok((self.packet, - PacketParserResult::Some(pp))); + Ok(pp))); }, ParserResult::EOF(_) => { return Err(Error::MalformedPacket( @@ -3667,13 +3598,13 @@ impl <'a> PacketParser<'a> { /// # extern crate sequoia_openpgp as openpgp; /// # use openpgp::Result; /// # use openpgp::Packet; - /// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; + /// # use openpgp::parse::{Parse, PacketParser}; /// # use std::string::String; /// # f(include_bytes!("../tests/data/messages/literal-mode-t-partial-body.gpg")); /// # /// # fn f(message_data: &[u8]) -> Result<()> { /// let mut ppr = PacketParser::from_bytes(message_data)?; - /// while let PacketParserResult::Some(mut pp) = ppr { + /// while let Ok(mut pp) = ppr { /// // Process the packet. /// /// if let Packet::Literal(_) = pp.packet { @@ -4019,7 +3950,7 @@ fn packet_parser_reader_interface() { // Make sure we can still get the next packet (which in this case // is just EOF). let (packet, ppr) = pp.recurse().unwrap(); - assert!(ppr.is_none()); + assert!(ppr.is_err()); // Since we read all of the data, we expect content to be None. assert_eq!(packet.unprocessed_body().unwrap().len(), 0); } @@ -4353,11 +4284,11 @@ mod test { ppr = ppr.unwrap().recurse().unwrap().1; } - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { let tag = pp.packet.tag(); for t in keep.iter() { if *t == tag { - return PacketParserResult::Some(pp); + return Ok(pp); } } @@ -4401,7 +4332,7 @@ mod test { let mut ppr = consume_until( ppr, false, &[ Tag::SEIP, Tag::AED ][..], &[ Tag::SKESK, Tag::PKESK ][..] ); - if let PacketParserResult::Some(ref mut pp) = ppr { + if let Ok(ref mut pp) = ppr { let key = crate::fmt::from_hex(test.key_hex, false) .unwrap().into(); @@ -4413,7 +4344,7 @@ mod test { let mut ppr = consume_until( ppr, true, &[ Tag::Literal ][..], &[ Tag::OnePassSig, Tag::CompressedData ][..]); - if let PacketParserResult::Some(ref mut pp) = ppr { + if let Ok(ref mut pp) = ppr { if stream { let mut body = Vec::new(); loop { @@ -4442,20 +4373,20 @@ mod test { let ppr = consume_until( ppr, true, &[ Tag::MDC ][..], &[ Tag::Signature ][..]); - if let PacketParserResult::Some( + if let Ok( PacketParser { packet: Packet::MDC(ref mdc), .. }) = ppr { assert_eq!(mdc.computed_digest(), mdc.digest(), "MDC doesn't match"); } - if ppr.is_none() { + if ppr.is_err() { // AED packets don't have an MDC packet. continue; } let ppr = consume_until( ppr, true, &[][..], &[][..]); - assert!(ppr.is_none()); + assert!(ppr.is_err()); } } @@ -4469,7 +4400,7 @@ mod test { // Make sure we actually decrypted... let mut saw_literal = false; - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { assert!(pp.possible_message().is_ok()); match pp.packet { @@ -4488,7 +4419,7 @@ mod test { ppr = pp.recurse().unwrap().1; } assert!(saw_literal); - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { assert!(eof.is_message().is_ok()); } else { unreachable!(); @@ -4510,11 +4441,11 @@ mod test { .build() .expect(&format!("Error reading {:?}", test)); - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { assert!(pp.possible_keyring().is_ok()); ppr = pp.recurse().unwrap().1; } - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { assert!(eof.is_keyring().is_ok()); assert!(eof.is_cert().is_err()); } else { @@ -4535,12 +4466,12 @@ mod test { .build() .expect(&format!("Error reading {:?}", test)); - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { assert!(pp.possible_keyring().is_ok()); assert!(pp.possible_cert().is_ok()); ppr = pp.recurse().unwrap().1; } - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { assert!(eof.is_keyring().is_ok()); assert!(eof.is_cert().is_ok()); } else { @@ -4560,7 +4491,7 @@ mod test { .expect(&format!("Error reading {}", test.filename)[..]); let mut saw_literal = false; - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { assert!(pp.possible_message().is_ok()); match pp.packet { @@ -4574,7 +4505,7 @@ mod test { ppr = pp.recurse().unwrap().1; } assert!(! saw_literal); - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { eprintln!("eof: {:?}; message: {:?}", eof, eof.is_message()); assert!(eof.is_message().is_ok()); } else { @@ -4599,7 +4530,7 @@ mod test { // We pop from the end. paths.reverse(); - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { let path = paths.pop().expect("Message longer than expect"); assert_eq!(path.0, pp.packet.tag()); assert_eq!(path.1, pp.path()); @@ -4626,7 +4557,7 @@ mod test { "Message shorter than expected (expecting: {:?})", paths); - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { assert_eq!(last_path, eof.last_path()); } else { panic!("Expect an EOF"); @@ -4650,7 +4581,7 @@ mod test { let mut userids = 0; let mut uas = 0; let mut unknown = 0; - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { match pp.packet { Packet::Signature(_) => sigs += 1, Packet::PublicSubkey(_) => subkeys += 1, @@ -4682,7 +4613,7 @@ mod test { let ppr = PacketParserBuilder::from_bytes(msg).unwrap() .dearmor(packet_parser_builder::Dearmor::Disabled) .build(); - assert_match!(Ok(PacketParserResult::Some(ref _pp)) = ppr); + assert_match!(Ok(Ok(ref _pp)) = ppr); // Prepend an invalid byte and make sure we fail. Note: we @@ -4709,14 +4640,14 @@ mod test { let ppr = PacketParserBuilder::from_bytes(msg).unwrap() .dearmor(packet_parser_builder::Dearmor::Disabled) .build(); - assert_match!(Ok(PacketParserResult::Some(ref _pp)) = ppr); + assert_match!(Ok(Ok(ref _pp)) = ppr); // Now truncate the packet. let msg2 = &msg[..msg.len() - 1]; let ppr = PacketParserBuilder::from_bytes(msg2).unwrap() .dearmor(packet_parser_builder::Dearmor::Disabled) .build().unwrap(); - if let PacketParserResult::Some(pp) = ppr { + if let Ok(pp) = ppr { let err = pp.next().err().unwrap(); assert_match!(Some(&Error::MalformedPacket(_)) = err.downcast_ref()); @@ -4736,7 +4667,7 @@ mod test { // Make sure we can read it. let ppr = PacketParserBuilder::from_bytes(&buf).unwrap() .build().unwrap(); - if let PacketParserResult::Some(pp) = ppr { + if let Ok(pp) = ppr { assert_eq!(Packet::UserID("foobar".into()), pp.packet); } else { panic!("failed to parse userid"); @@ -4747,7 +4678,7 @@ mod test { let ppr = PacketParserBuilder::from_bytes(&buf).unwrap() .max_packet_size(5) .build().unwrap(); - if let PacketParserResult::Some(pp) = ppr { + if let Ok(pp) = ppr { if let Packet::Unknown(ref u) = pp.packet { assert_eq!(u.tag(), Tag::UserID); assert_match!(Some(&Error::PacketTooLarge(_, _, _)) diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs index f22469bd..93bf20eb 100644 --- a/openpgp/src/parse/packet_parser_builder.rs +++ b/openpgp/src/parse/packet_parser |