[][src]Struct sequoia_openpgp::tpk::TPKParser

pub struct TPKParser<'a, I: Iterator<Item = Packet>> { /* fields omitted */ }

An iterator over a sequence of TPKs (e.g., an OpenPGP keyring).

The source of packets can either be a PacketParser or an iterator over Packets. (In the latter case, the underlying parser is not able to propagate errors. Thus, this is only appropriate for in-memory structures, like a vector of Packets or a PacketPile.)

Example

use openpgp::tpk::TPKParser;

for tpko in TPKParser::from_packet_parser(ppr) {
    match tpko {
        Ok(tpk) => {
            println!("Key: {}", tpk.primary());
            for binding in tpk.userids() {
                println!("User ID: {}", binding.userid());
            }
        }
        Err(err) => {
            eprintln!("Error reading keyring: {}", err);
        }
    }
}

Implementations

impl<'a> TPKParser<'a, IntoIter<Packet>>[src]

pub fn from_packet_parser(ppr: PacketParserResult<'a>) -> Self[src]

Initializes a TPKParser from a PacketParser.

impl<'a, I: Iterator<Item = Packet>> TPKParser<'a, I>[src]

pub fn from_iter(iter: I) -> Self[src]

Initializes a TPKParser from an iterator over Packets.

pub fn unvalidated_tpk_filter<F: 'a>(self, filter: F) -> Self where
    F: Fn(&TPK, bool) -> bool
[src]

Filters the TPKs prior to validation.

By default, the TPKParser only returns valdiated TPKs. Checking that a TPK's self-signatures are valid, however, is computationally expensive, and not always necessary. For example, when looking for a small number of TPKs in a large keyring, most TPKs can be immediately discarded. That is, it is more efficient to filter, validate, and double check, than to validate and filter. (It is necessary to double check, because the check might have been on an invalid part. For example, if searching for a key with a particular key ID, a matching subkey might not have any self signatures.)

If the TPKParser gave out unvalidated TPKs, and provided an interface to validate them, then the caller could implement this first-validate-double-check pattern. Giving out unvalidated TPKs, however, is too dangerous: inevitably, a TPK will be used without having been validated in a context where it should have been.

This function avoids this class of bugs while still providing a mechanism to filter TPKs prior to validation: the caller provides a callback, that is invoked on the unvalidated TPK. If the callback returns true, then the parser validates the TPK, and invokes the callback a second time to make sure the TPK is really wanted. If the callback returns false, then the TPK is skipped.

Note: calling this function multiple times on a single TPKParser will install multiple filters.

Example

use openpgp::tpk::TPKParser;
use openpgp::TPK;
use openpgp::KeyID;

for tpkr in TPKParser::from_packet_parser(ppr)
    .unvalidated_tpk_filter(|tpk, _| {
        if tpk.primary().keyid() == some_keyid {
            return true;
        }
        for binding in tpk.subkeys() {
            if binding.key().keyid() == some_keyid {
                return true;
            }
        }
        false
    })
{
    match tpkr {
        Ok(tpk) => {
            // The TPK contains the subkey.
        }
        Err(err) => {
            eprintln!("Error reading keyring: {}", err);
        }
    }
}

Trait Implementations

impl<'a, I: Iterator<Item = Packet>> Default for TPKParser<'a, I>[src]

impl<'a, I: Iterator<Item = Packet>> Iterator for TPKParser<'a, I>[src]

type Item = Result<TPK>

The type of the elements being iterated over.

impl<'a> Parse<'a, TPKParser<'a, IntoIter<Packet>>> for TPKParser<'a, IntoIter<Packet>>[src]

fn from_reader<R: 'a + Read>(reader: R) -> Result<Self>[src]

Initializes a TPKParser from a Reader.

fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>[src]

Initializes a TPKParser from a File.

fn from_bytes<D: AsRef<[u8]> + ?Sized>(data: &'a D) -> Result<Self>[src]

Initializes a TPKParser from a byte string.

Auto Trait Implementations

impl<'a, I> !RefUnwindSafe for TPKParser<'a, I>

impl<'a, I> !Send for TPKParser<'a, I>

impl<'a, I> !Sync for TPKParser<'a, I>

impl<'a, I> Unpin for TPKParser<'a, I> where
    I: Unpin

impl<'a, I> !UnwindSafe for TPKParser<'a, I>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,