diff options
-rw-r--r-- | openpgp/src/packet_pile.rs | 13 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 10 |
2 files changed, 15 insertions, 8 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 57a0fa16..f06e458f 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -549,11 +549,15 @@ mod test { // lutz's key is a v3 key. #[test] fn torture() { + use std::convert::TryInto; + use crate::parse::PacketPileParser; + let data = crate::tests::key("dkg.gpg"); - let mut ppp = PacketParserBuilder::from_bytes(data).unwrap() + let mut ppp: PacketPileParser = + PacketParserBuilder::from_bytes(data).unwrap() //.trace() .buffer_unread_content() - .into_packet_pile_parser().unwrap(); + .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); while ppr.is_some() { @@ -564,10 +568,11 @@ mod test { assert_eq!(pile.children().len(), 1450); let data = crate::tests::key("lutz.gpg"); - let mut ppp = PacketParserBuilder::from_bytes(data).unwrap() + let mut ppp: PacketPileParser = + PacketParserBuilder::from_bytes(data).unwrap() //.trace() .buffer_unread_content() - .into_packet_pile_parser().unwrap(); + .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); while let Some(pp) = ppr.as_mut() { diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index c429e716..201654ed 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -1,3 +1,4 @@ +use std::convert::TryFrom; use std::io; use std::path::Path; @@ -65,12 +66,13 @@ pub struct PacketPileParser<'a> { pile: PacketPile, } -impl<'a> PacketParserBuilder<'a> { +impl<'a> TryFrom<PacketParserBuilder<'a>> for PacketPileParser<'a> { + type Error = anyhow::Error; + /// Finishes configuring the `PacketParser` and returns a /// `PacketPileParser`. - pub fn into_packet_pile_parser(self) -> Result<PacketPileParser<'a>> - where Self: 'a { - PacketPileParser::from_packet_parser(self.finalize()?) + fn try_from(ppb: PacketParserBuilder<'a>) -> Result<PacketPileParser<'a>> { + Self::from_packet_parser(ppb.finalize()?) } } |