[][src]Struct sequoia_openpgp::cert::CertParser

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

An iterator over a sequence of Certs (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::cert::prelude::*;

for certo in CertParser::from(ppr) {
    match certo {
        Ok(cert) => {
            println!("Key: {}", cert.fingerprint());
            for ca in cert.userids() {
                println!("User ID: {}", ca.userid());
            }
        }
        Err(err) => {
            eprintln!("Error reading keyring: {}", err);
        }
    }
}

Methods

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

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

Initializes a CertParser from an iterator over Packets.

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

Filters the Certs prior to validation.

By default, the CertParser only returns valdiated Certs. Checking that a Cert's self-signatures are valid, however, is computationally expensive, and not always necessary. For example, when looking for a small number of Certs in a large keyring, most Certs 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 CertParser gave out unvalidated Certs, and provided an interface to validate them, then the caller could implement this first-validate-double-check pattern. Giving out unvalidated Certs, however, is too dangerous: inevitably, a Cert 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 Certs prior to validation: the caller provides a callback, that is invoked on the unvalidated Cert. If the callback returns true, then the parser validates the Cert, and invokes the callback a second time to make sure the Cert is really wanted. If the callback returns false, then the Cert is skipped.

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

Example

use openpgp::cert::prelude::*;
use openpgp::Cert;
use openpgp::KeyID;

for certr in CertParser::from(ppr)
    .unvalidated_cert_filter(|cert, _| {
        for component in cert.keys() {
            if component.key().keyid() == some_keyid {
                return true;
            }
        }
        false
    })
{
    match certr {
        Ok(cert) => {
            // The Cert contains the subkey.
        }
        Err(err) => {
            eprintln!("Error reading keyring: {}", err);
        }
    }
}

Trait Implementations

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

impl<'a> From<PacketParserResult<'a>> for CertParser<'a, IntoIter<Packet>>[src]

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

Initializes a CertParser from a PacketParser.

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

type Item = Result<Cert>

The type of the elements being iterated over.

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

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

Initializes a CertParser from a Reader.

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

Initializes a CertParser from a File.

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

Initializes a CertParser from a byte string.

Auto Trait Implementations

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

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

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

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

impl<'a, I> !UnwindSafe for CertParser<'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>,