use std::convert::TryFrom;
use std::fmt;
use std::vec;
use std::io;
use std::path::Path;
use std::iter::FromIterator;
use std::iter::IntoIterator;
use buffered_reader::BufferedReader;
use crate::Result;
use crate::Error;
use crate::Packet;
use crate::cert::Cert;
use crate::packet::{self, Container};
use crate::parse::PacketParserResult;
use crate::parse::PacketParserBuilder;
use crate::parse::Parse;
use crate::parse::Cookie;
/// An unstructured [packet] sequence.
///
/// To parse an OpenPGP packet stream into a `PacketPile`, you can use
/// [`PacketParser`], [`PacketPileParser`], or
/// [`PacketPile::from_file`] (or related routines).
///
/// [packet]: https://tools.ietf.org/html/rfc4880#section-4
/// [`PacketParser`]: parse/struct.PacketParser.html
/// [`PacketPileParser`]: parse/struct.PacketPileParser.html
/// [`PacketPile::from_file`]: struct.PacketPile.html#method.from_file
///
/// You can also convert a [`Cert`] into a `PacketPile` using
/// `PacketPile::from`. Unlike serializing a `Cert`, this does not
/// drop any secret key material.
///
/// [`Cert`]: ../struct.Cert.html
///
/// Normally, you'll want to convert the `PacketPile` to a `Cert` or a
/// `Message`.
///
/// # Examples
///
/// This example shows how to modify packets in PacketPile using [`pathspec`]s.
///
/// [`pathspec`]: struct.PacketPile.html#method.path_ref
///
/// ```rust
/// # use sequoia_openpgp as openpgp;
/// use std::convert::TryFrom;
/// use openpgp::{Packet, PacketPile};
/// use openpgp::packet::signature::Signature4;
/// use openpgp::packet::Signature;
/// use openpgp::cert::prelude::*;
/// use openpgp::parse::Parse;
/// use openpgp::serialize::Serialize;
/// use openpgp::policy::StandardPolicy;
/// use openpgp::crypto::mpi;
/// use openpgp::types::RevocationStatus::{Revoked, CouldBe};
///
/// # fn main() { f().unwrap(); }
/// # fn f() -> openpgp::Result<()> {
/// let (cert, revocation) = CertBuilder::new().generate()?;
///
/// le