summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-31 11:00:31 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-03-31 11:52:31 +0200
commit7f4eb0b55bb20b771d8ccfc5e0541ff95f83757c (patch)
tree724fe301502d11c782eed54ec14d4ebb9c4ff5f0
parent13da17b51764dfb285d5febdbcdee24a2d6c4021 (diff)
openpgp: Move definition of struct PacketPile.
- Implement Default for PacketPile, add internal accessor for the top-level.
-rw-r--r--openpgp/src/lib.rs20
-rw-r--r--openpgp/src/packet_pile.rs26
-rw-r--r--openpgp/src/parse/packet_pile_parser.rs4
3 files changed, 27 insertions, 23 deletions
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<Packet> 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<PacketPileParser<'a>>
{
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);