pub struct PacketParserEOF<'a> { /* private fields */ }Expand description
Information about the stream of packets parsed by the
PacketParser.
Once the PacketParser reaches the end of the input stream, it
returns a PacketParserResult::EOF with a PacketParserEOF.
This object provides information about the parsed stream, notably
whether the packet stream was a well-formed Message,
Cert or keyring.
§Examples
Parse some OpenPGP stream using a PacketParser and detects the
kind of data:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
if eof.is_message().is_ok() {
// ...
} else if eof.is_cert().is_ok() {
// ...
} else if eof.is_keyring().is_ok() {
// ...
} else {
// ...
}
}Implementations§
Source§impl<'a> PacketParserEOF<'a>
impl<'a> PacketParserEOF<'a>
Sourcepub fn is_message(&self) -> Result<(), Error>
pub fn is_message(&self) -> Result<(), Error>
Returns whether the stream is an OpenPGP Message.
A Message has a very specific structure. Returns true
if the stream is of that form, as opposed to a Cert or
just a bunch of packets.
§Examples
Parse some OpenPGP stream using a PacketParser and detects the
kind of data:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
if eof.is_message().is_ok() {
// ...
}
}Sourcepub fn is_keyring(&self) -> Result<(), Error>
pub fn is_keyring(&self) -> Result<(), Error>
Returns whether the message is an OpenPGP keyring.
A keyring has a very specific structure. Returns true if
the stream is of that form, as opposed to a Message or
just a bunch of packets.
§Examples
Parse some OpenPGP stream using a PacketParser and detects the
kind of data:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
if eof.is_keyring().is_ok() {
// ...
}
}Sourcepub fn is_cert(&self) -> Result<(), Error>
pub fn is_cert(&self) -> Result<(), Error>
Returns whether the message is an OpenPGP Cert.
A Cert has a very specific structure. Returns true if
the stream is of that form, as opposed to a Message or
just a bunch of packets.
§Examples
Parse some OpenPGP stream using a PacketParser and detects the
kind of data:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
if eof.is_cert().is_ok() {
// ...
}
}Sourcepub fn last_path(&self) -> &[usize]
pub fn last_path(&self) -> &[usize]
Returns the path of the last packet.
§Examples
Parse some OpenPGP stream using a PacketParser and returns
the path (see PacketPile::path_ref) of the last packet:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
let _ = eof.last_path();
}Sourcepub fn last_recursion_depth(&self) -> Option<isize>
pub fn last_recursion_depth(&self) -> Option<isize>
The last packet’s recursion depth.
A top-level packet has a recursion depth of 0. Packets in a top-level container have a recursion depth of 1, etc.
§Examples
Parse some OpenPGP stream using a PacketParser and returns
the recursion depth of the last packet:
use sequoia_openpgp as openpgp;
use openpgp::Packet;
use openpgp::parse::{Parse, PacketParserResult, PacketParser};
let openpgp_data: &[u8] = // ...
let mut ppr = PacketParser::from_bytes(openpgp_data)?;
while let PacketParserResult::Some(mut pp) = ppr {
// Start parsing the next packet, recursing.
ppr = pp.recurse()?.1;
}
if let PacketParserResult::EOF(eof) = ppr {
let _ = eof.last_recursion_depth();
}Sourcepub fn into_reader(self) -> Box<dyn BufferedReader<Cookie> + 'a>
pub fn into_reader(self) -> Box<dyn BufferedReader<Cookie> + 'a>
Returns the exhausted reader.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for PacketParserEOF<'a>
impl<'a> !UnwindSafe for PacketParserEOF<'a>
impl<'a> Freeze for PacketParserEOF<'a>
impl<'a> Send for PacketParserEOF<'a>
impl<'a> Sync for PacketParserEOF<'a>
impl<'a> Unpin for PacketParserEOF<'a>
impl<'a> UnsafeUnpin for PacketParserEOF<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more