[][src]Module sequoia_openpgp::packet::key

Public key, public subkey, private key and private subkey packets. Key variants.

There are four variants of OpenPGP keys: public keys, public subkeys, secret keys, and secret subkeys. These are based on the cross product of two attributes: whether the key contains any secret key material, and the key's role.

The underlying representation of these four variants is identical (even a public key and a secret key are the same: the public key variant just contains 0 bits of secret key material), and many (but not all) operations can be done on all four variants.

We separate these variants into two types: parts (public or secret) and roles (primary or secondary). We also add unspecified variants, because sometimes we want a slice of keys, and we don't care about the key's role. For instance, when iterating over all of the keys in a Cert, we want the primary and the subkeys. These can't be put in the same slice without first wrapping them, which is awkward.

For the most part, the user doesn't need to worry about the markers. Occasionally, it is necessary to change a key's markers. For these cases, it is possible to just use the From trait to get the require markers. But, it is also possible to explicitly set markers. Compare:

use openpgp::packet::{Key, key};

// Get a handle to the Cert's primary key that allows using the
// secret key material.
use std::convert::TryInto;
let sk: &Key<key::SecretParts, key::PrimaryRole> = cert.primary_key().key().try_into()?;

// Make the conversion explicit.
let sk = cert.primary_key().key().mark_parts_secret_ref()?;



The secret key is encrypted with a password.


Holds a public key, public subkey, private key or private subkey packet.


Indicates that a Key should treated like a primary key.


Indicates that a Key should be treated like a public key.


Indicates that a Key should be treated like a secret key.


Indicates that a Key should treated like a subkey key.


Unencrypted secret key. Can be used as-is.


Indicates that a Key's parts are unspecified.


Indicates that a Key's role is unknown.



Holds the secret potion of a OpenPGP secret key or secret subkey packet.



A marker trait that indicates whether a Key only contains public key material or may also contains secret key material.


A marker trait that indicates whether a Key is a primary key or subordinate key (i.e., a subkey).