use std::fmt;
use std::convert::TryInto;
use std::time::SystemTime;
use std::borrow::Borrow;
use std::slice;
use crate::{
KeyHandle,
types::RevocationStatus,
packet::key,
packet::key::SecretKeyMaterial,
types::KeyFlags,
cert::prelude::*,
policy::Policy,
};
/// An iterator over all `Key`s (both the primary key and the subkeys)
/// in a certificate.
///
/// Returned by `Cert::keys()`.
///
/// `KeyIter` follows the builder pattern. There is no need to
/// explicitly finalize it, however: it already implements the
/// `Iterator` trait.
///
/// By default, `KeyIter` returns all keys. `KeyIter` provides some
/// filters to control what it returns. For instance,
/// `KeyIter::secret` causes the iterator to only returns keys that
/// include secret key material. Of course, since `KeyIter`
/// implements `Iterator`, it is possible to use `Iterator::filter` to
/// implement custom filters.
pub struct KeyIter<'a, P, R>
where P: key::KeyParts,
R: key::KeyRole,
{
// This is an option to make it easier to create an empty KeyIter.
cert: Option<&'a Cert>,
primary: bool,
subkey_iter: slice::Iter<'a, KeyBundle<key::PublicParts,
key::SubordinateRole>>,
// If not None, filters by whether a key has a secret.
secret: Option<bool>,
// If not None, filters by whether a key has an unencrypted
// secret.
unencrypted_secret: Option<bool>,
// Only return keys in this set.
key_handles: Vec<KeyHandle>,
_p: std::marker::PhantomData<P>,
_r: std::marker::PhantomData<R>,
}
impl<'a, P, R> fmt::Debug for KeyIter<'a, P, R>
where P: key::KeyParts,
R: key::KeyRole,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("KeyIter")