From 7f4eb0b55bb20b771d8ccfc5e0541ff95f83757c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 31 Mar 2020 11:00:31 +0200 Subject: openpgp: Move definition of struct PacketPile. - Implement Default for PacketPile, add internal accessor for the top-level. --- openpgp/src/lib.rs | 20 +------------------- openpgp/src/packet_pile.rs | 26 ++++++++++++++++++++++++-- openpgp/src/parse/packet_pile_parser.rs | 4 ++-- 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'openpgp/src') diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 880819aa..0cd474da 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -152,6 +152,7 @@ pub use cert::Cert; pub mod serialize; mod packet_pile; +pub use packet_pile::PacketPile; pub mod message; pub mod types; @@ -431,25 +432,6 @@ impl Packet { } } -/// A `PacketPile` holds a deserialized sequence of OpenPGP messages. -/// -/// To deserialize an OpenPGP usage, use either [`PacketParser`], -/// [`PacketPileParser`], or [`PacketPile::from_file`] (or related -/// routines). -/// -/// Normally, you'll want to convert the `PacketPile` to a Cert or a -/// `Message`. -/// -/// [`PacketParser`]: parse/struct.PacketParser.html -/// [`PacketPileParser`]: parse/struct.PacketPileParser.html -/// [`PacketPile::from_file`]: struct.PacketPile.html#method.from_file -#[derive(PartialEq, Clone)] -pub struct PacketPile { - /// At the top level, we have a sequence of packets, which may be - /// containers. - top_level: Container, -} - /// An OpenPGP message. /// /// An OpenPGP message is a structured sequence of OpenPGP packets. diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 3e0a4cc1..c339095e 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -10,13 +10,30 @@ use crate::Result; use crate::Error; use crate::Packet; use crate::packet::{self, Container}; -use crate::PacketPile; use crate::parse::PacketParserResult; use crate::parse::PacketParserBuilder; use crate::parse::Parse; use crate::parse::Cookie; - +/// A `PacketPile` holds a deserialized sequence of OpenPGP messages. +/// +/// To deserialize an OpenPGP usage, use either [`PacketParser`], +/// [`PacketPileParser`], or [`PacketPile::from_file`] (or related +/// routines). +/// +/// Normally, you'll want to convert the `PacketPile` to a Cert or a +/// `Message`. +/// +/// [`PacketParser`]: parse/struct.PacketParser.html +/// [`PacketPileParser`]: parse/struct.PacketPileParser.html +/// [`PacketPile::from_file`]: struct.PacketPile.html#method.from_file +#[derive(PartialEq, Clone, Default)] +pub struct PacketPile { + /// At the top level, we have a sequence of packets, which may be + /// containers. + top_level: Container, +} + impl fmt::Debug for PacketPile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("PacketPile") @@ -85,6 +102,11 @@ impl From for PacketPile { } impl PacketPile { + /// Accessor for PacketPileParser. + pub(crate) fn top_level_mut(&mut self) -> &mut Container { + &mut self.top_level + } + /// Returns an error if operating on a non-container packet. fn error() -> crate::Error { crate::Error::InvalidOperation("Not a container packet".into()) diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 2390a26c..c429e716 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -108,7 +108,7 @@ impl<'a> PacketPileParser<'a> { -> Result> { Ok(PacketPileParser { - pile: PacketPile { top_level: Default::default() }, + pile: Default::default(), ppr: ppr, returned_first: false, }) @@ -124,7 +124,7 @@ impl<'a> PacketPileParser<'a> { /// Inserts the next packet into the `PacketPile`. fn insert_packet(&mut self, packet: Packet, position: isize) { // Find the right container. - let mut container = &mut self.pile.top_level; + let mut container = self.pile.top_level_mut(); assert!(position >= 0); -- cgit v1.2.3