[][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 TPK, 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 TPK's primary key that allows using the
// secret key material.
use std::convert::TryInto;
let sk : &key::SecretKey = tpk.primary().try_into()?;

// Make the conversion explicit.
let sk : &key::SecretKey = tpk.primary().mark_parts_secret_ref()?;

Structs

Encrypted

The secret key is encrypted with a password.

Key4

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

PrimaryRole

Indicates that a Key should treated like a primary key.

PublicParts

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

SecretParts

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

SubordinateRole

Indicates that a Key should treated like a subkey key.

Unencrypted

Unencrypted secret key. Can be used as-is.

UnspecifiedParts

Indicates that a Key's parts are unspecified.

UnspecifiedRole

Indicates that a Key's role is unknown.

Enums

SecretKeyMaterial

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

Traits

KeyParts

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

KeyRole

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

Type Definitions

PublicKey

A Public Key.

PublicSubkey

A Public Subkey.

SecretKey

A Secret Key.

SecretSubkey

A Secret Subkey.

UnspecifiedKey

A key whose parts and role are unspecified (UnspecifiedParts, UnspecifiedRole).

UnspecifiedPrimary

A primary key with unspecified parts (UnspecifiedParts).

UnspecifiedPublic

A key with public parts, and an unspecified role (UnspecifiedRole).

UnspecifiedSecondary

A subkey key with unspecified parts (UnspecifiedParts).

UnspecifiedSecret

A key with secret parts, and an unspecified role (UnspecifiedRole).