Struct sequoia_openpgp::parse::PacketParserEOF

source ·
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 or not 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>

source

pub fn is_message(&self) -> Result<()>

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() {
        // ...
    }
}
source

pub fn is_keyring(&self) -> Result<()>

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() {
        // ...
    }
}
source

pub fn is_cert(&self) -> Result<()>

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() {
        // ...
    }
}
source

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();
}
source

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();
}
source

pub fn into_reader(self) -> Box<dyn BufferedReader<Cookie> + 'a>

Returns the exhausted reader.

Trait Implementations§

source§

impl<'a> Debug for PacketParserEOF<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PacketParserEOF<'a>

§

impl<'a> !RefUnwindSafe for PacketParserEOF<'a>

§

impl<'a> Send for PacketParserEOF<'a>

§

impl<'a> Sync for PacketParserEOF<'a>

§

impl<'a> Unpin for PacketParserEOF<'a>

§

impl<'a> !UnwindSafe for PacketParserEOF<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T