[][src]Enum sequoia_openpgp::packet::Key

pub enum Key<P: KeyParts, R: KeyRole> {
    V4(Key4<P, R>),
}

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

See Section 5.5 of RFC 4880 for details.

Variants

V4(Key4<P, R>)

Key packet version 4.

Methods

impl<P, R> Key<P, R> where
    P: KeyParts,
    R: KeyRole
[src]

pub fn mark_parts_public(self) -> Key<PublicParts, R>[src]

Changes the key's parts tag to PublicParts.

pub fn mark_parts_public_ref(&self) -> &Key<PublicParts, R>[src]

Changes the key's parts tag to PublicParts.

pub fn mark_parts_secret(self) -> Key<SecretParts, R>[src]

Changes the key's parts tag to SecretParts.

pub fn mark_parts_secret_ref(&self) -> &Key<SecretParts, R>[src]

Changes the key's parts tag to SecretParts.

pub fn mark_parts_unspecified(self) -> Key<UnspecifiedParts, R>[src]

Changes the key's parts tag to UnspecifiedParts.

pub fn mark_parts_unspecified_ref(&self) -> &Key<UnspecifiedParts, R>[src]

Changes the key's parts tag to UnspecifiedParts.

impl<P, R> Key<P, R> where
    P: KeyParts,
    R: KeyRole
[src]

pub fn mark_role_primary(self) -> Key<P, PrimaryRole>[src]

Changes the key's role tag to PrimaryRole.

pub fn mark_role_primary_ref(&self) -> &Key<P, PrimaryRole>[src]

Changes the key's role tag to PrimaryRole.

pub fn mark_role_secondary(self) -> Key<P, SubordinateRole>[src]

Changes the key's role tag to SubordinateRole.

pub fn mark_role_secondary_ref(&self) -> &Key<P, SubordinateRole>[src]

Changes the key's role tag to SubordinateRole.

pub fn mark_role_unspecified(self) -> Key<P, UnspecifiedRole>[src]

Changes the key's role tag to UnspecifiedRole.

pub fn mark_role_unspecified_ref(&self) -> &Key<P, UnspecifiedRole>[src]

Changes the key's role tag to UnspecifiedRole.

impl<P: KeyParts, R: KeyRole> Key<P, R>[src]

pub fn version(&self) -> u8[src]

Gets the version.

pub fn public_cmp(a: &Self, b: &Self) -> Ordering[src]

Compares the public bits of two keys.

This returns Ordering::Equal if the public MPIs, version, creation time and algorithm of the two Keys match. This does not consider the packet's encoding, packet's tag or the secret key material.

impl<R: KeyRole> Key<SecretParts, R>[src]

pub fn into_keypair(self) -> Result<KeyPair<R>>[src]

Creates a new key pair from a Key packet with an unencrypted secret key.

Errors

Fails if the secret key is missing, or encrypted.

impl Key<PublicParts, SubordinateRole>[src]

pub fn bind<H, T, R>(
    &self,
    signer: &mut dyn Signer<R>,
    tpk: &TPK,
    signature: Builder,
    hash_algo: H,
    creation_time: T
) -> Result<Signature> where
    H: Into<Option<HashAlgorithm>>,
    T: Into<Option<Tm>>,
    R: KeyRole
[src]

Creates a binding signature.

The signature binds this userid to tpk. signer will be used to create a signature using signature as builder. Thehash_algo defaults to SHA512, creation_time to the current time.

This function adds a creation time subpacket, a issuer fingerprint subpacket, and a issuer subpacket to the signature.

Example

This example demonstrates how to bind this key to a TPK. Note that in general, the TPKBuilder is a better way to add subkeys to a TPK.

// Generate a TPK, and create a keypair from the primary key.
let (tpk, _) = TPKBuilder::new().generate()?;
let mut keypair = tpk.primary().clone()
    .mark_parts_secret().into_keypair()?;

// Let's add an encryption subkey.
let flags = KeyFlags::default().set_encrypt_at_rest(true);
assert_eq!(tpk.keys_valid().key_flags(flags.clone()).count(), 0);

// Generate a subkey and a binding signature.
let subkey : key::PublicSubkey
    = Key::V4(Key4::generate_ecc(false, Curve::Cv25519)?);
let builder = signature::Builder::new(SignatureType::SubkeyBinding)
    .set_key_flags(&flags)?;
let binding = subkey.bind(&mut keypair, &tpk, builder, None, None)?;

// Now merge the key and binding signature into the TPK.
let tpk = tpk.merge_packets(vec![subkey.into(),
                                 binding.into()])?;

// Check that we have an encryption subkey.
assert_eq!(tpk.keys_valid().key_flags(flags).count(), 1);

Methods from Deref<Target = Key4<P, R>>

pub fn mark_parts_public_ref(&self) -> &Key4<PublicParts, R>[src]

Changes the key's parts tag to PublicParts.

pub fn mark_parts_secret_ref(&self) -> &Key4<SecretParts, R>[src]

Changes the key's parts tag to SecretParts.

pub fn mark_parts_unspecified_ref(&self) -> &Key4<UnspecifiedParts, R>[src]

Changes the key's parts tag to UnspecifiedParts.

pub fn mark_role_primary_ref(&self) -> &Key4<P, PrimaryRole>[src]

Changes the key's role tag to PrimaryRole.

pub fn mark_role_secondary_ref(&self) -> &Key4<P, SubordinateRole>[src]

Changes the key's role tag to SubordinateRole.

pub fn mark_role_unspecified_ref(&self) -> &Key4<P, UnspecifiedRole>[src]

Changes the key's role tag to UnspecifiedRole.

pub fn creation_time(&self) -> &Tm[src]

Gets the key packet's creation time field.

pub fn set_creation_time(&mut self, timestamp: Tm) -> Tm[src]

Sets the key packet's creation time field.

pub fn pk_algo(&self) -> PublicKeyAlgorithm[src]

Gets the public key algorithm.

pub fn set_pk_algo(&mut self, pk_algo: PublicKeyAlgorithm) -> PublicKeyAlgorithm[src]

Sets the public key algorithm.

pub fn mpis(&self) -> &PublicKey[src]

Gets the key packet's MPIs.

pub fn mpis_mut(&mut self) -> &mut PublicKey[src]

Gets a mutable reference to the key packet's MPIs.

pub fn set_mpis(&mut self, mpis: PublicKey) -> PublicKey[src]

Sets the key packet's MPIs.

pub fn secret(&self) -> Option<&SecretKeyMaterial>[src]

Gets the key packet's SecretKeyMaterial.

pub fn secret_mut(&mut self) -> Option<&mut SecretKeyMaterial>[src]

Gets a mutable reference to the key packet's SecretKeyMaterial.

pub fn set_secret(
    &mut self,
    secret: Option<SecretKeyMaterial>
) -> Option<SecretKeyMaterial>
[src]

Sets the key packet's SecretKeyMaterial.

Returns the old value.

pub fn fingerprint(&self) -> Fingerprint[src]

Computes and returns the key's fingerprint as per Section 12.2 of RFC 4880.

pub fn keyid(&self) -> KeyID[src]

Computes and returns the key's key ID as per Section 12.2 of RFC 4880.

Trait Implementations

impl<P: KeyParts, R: KeyRole> Serialize for Key<P, R>[src]

fn export(&self, o: &mut dyn Write) -> Result<()>[src]

Exports a serialized version of the object to o. Read more

impl<P: KeyParts, R: KeyRole> SerializeInto for Key<P, R>[src]

fn to_vec(&self) -> Result<Vec<u8>>[src]

Serializes the packet to a vector.

fn export_into(&self, buf: &mut [u8]) -> Result<usize>[src]

Exports into the given buffer. Read more

fn export_to_vec(&self) -> Result<Vec<u8>>[src]

Exports to a vector. Read more

impl<'a> Parse<'a, Key<UnspecifiedParts, UnspecifiedRole>> for UnspecifiedKey[src]

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

Reads from the given file. Read more

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

Reads from the given slice. Read more

impl<R> From<KeyPair<R>> for Key<SecretParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<PublicParts, R>> for Key<SecretParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<PublicParts, R>> for &'_ Key<SecretParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<PublicParts, R>> for Key<UnspecifiedParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<PublicParts, R>> for &'_ Key<UnspecifiedParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<SecretParts, R>> for Key<PublicParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<SecretParts, R>> for &'_ Key<PublicParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<SecretParts, R>> for Key<UnspecifiedParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<SecretParts, R>> for &'_ Key<UnspecifiedParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<UnspecifiedParts, R>> for Key<PublicParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<UnspecifiedParts, R>> for &'_ Key<PublicParts, R> where
    R: KeyRole
[src]

impl<R> From<Key<UnspecifiedParts, R>> for Key<SecretParts, R> where
    R: KeyRole
[src]

impl<R, '_, '_> From<&'_ Key<UnspecifiedParts, R>> for &'_ Key<SecretParts, R> where
    R: KeyRole
[src]

impl<P> From<Key<P, PrimaryRole>> for Key<P, SubordinateRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, PrimaryRole>> for &'_ Key<P, SubordinateRole> where
    P: KeyParts
[src]

impl<P> From<Key<P, PrimaryRole>> for Key<P, UnspecifiedRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, PrimaryRole>> for &'_ Key<P, UnspecifiedRole> where
    P: KeyParts
[src]

impl<P> From<Key<P, SubordinateRole>> for Key<P, PrimaryRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, SubordinateRole>> for &'_ Key<P, PrimaryRole> where
    P: KeyParts
[src]

impl<P> From<Key<P, SubordinateRole>> for Key<P, UnspecifiedRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, SubordinateRole>> for &'_ Key<P, UnspecifiedRole> where
    P: KeyParts
[src]

impl<P> From<Key<P, UnspecifiedRole>> for Key<P, PrimaryRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, UnspecifiedRole>> for &'_ Key<P, PrimaryRole> where
    P: KeyParts
[src]

impl<P> From<Key<P, UnspecifiedRole>> for Key<P, SubordinateRole> where
    P: KeyParts
[src]

impl<P, '_, '_> From<&'_ Key<P, UnspecifiedRole>> for &'_ Key<P, SubordinateRole> where
    P: KeyParts
[src]

impl From<Key<PublicParts, PrimaryRole>> for Key<SecretParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, PrimaryRole>> for &'_ Key<SecretParts, SubordinateRole>[src]

impl From<Key<PublicParts, PrimaryRole>> for Key<SecretParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, PrimaryRole>> for &'_ Key<SecretParts, UnspecifiedRole>[src]

impl From<Key<PublicParts, PrimaryRole>> for Key<UnspecifiedParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, PrimaryRole>> for &'_ Key<UnspecifiedParts, SubordinateRole>[src]

impl From<Key<PublicParts, PrimaryRole>> for Key<UnspecifiedParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, PrimaryRole>> for &'_ Key<UnspecifiedParts, UnspecifiedRole>[src]

impl From<Key<PublicParts, SubordinateRole>> for Key<SecretParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, SubordinateRole>> for &'_ Key<SecretParts, PrimaryRole>[src]

impl From<Key<PublicParts, SubordinateRole>> for Key<SecretParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, SubordinateRole>> for &'_ Key<SecretParts, UnspecifiedRole>[src]

impl From<Key<PublicParts, SubordinateRole>> for Key<UnspecifiedParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, SubordinateRole>> for &'_ Key<UnspecifiedParts, PrimaryRole>[src]

impl From<Key<PublicParts, SubordinateRole>> for Key<UnspecifiedParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, SubordinateRole>> for &'_ Key<UnspecifiedParts, UnspecifiedRole>[src]

impl From<Key<PublicParts, UnspecifiedRole>> for Key<SecretParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, UnspecifiedRole>> for &'_ Key<SecretParts, PrimaryRole>[src]

impl From<Key<PublicParts, UnspecifiedRole>> for Key<SecretParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, UnspecifiedRole>> for &'_ Key<SecretParts, SubordinateRole>[src]

impl From<Key<PublicParts, UnspecifiedRole>> for Key<UnspecifiedParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, UnspecifiedRole>> for &'_ Key<UnspecifiedParts, PrimaryRole>[src]

impl From<Key<PublicParts, UnspecifiedRole>> for Key<UnspecifiedParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<PublicParts, UnspecifiedRole>> for &'_ Key<UnspecifiedParts, SubordinateRole>[src]

impl From<Key<SecretParts, PrimaryRole>> for Key<PublicParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, PrimaryRole>> for &'_ Key<PublicParts, SubordinateRole>[src]

impl From<Key<SecretParts, PrimaryRole>> for Key<PublicParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, PrimaryRole>> for &'_ Key<PublicParts, UnspecifiedRole>[src]

impl From<Key<SecretParts, PrimaryRole>> for Key<UnspecifiedParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, PrimaryRole>> for &'_ Key<UnspecifiedParts, SubordinateRole>[src]

impl From<Key<SecretParts, PrimaryRole>> for Key<UnspecifiedParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, PrimaryRole>> for &'_ Key<UnspecifiedParts, UnspecifiedRole>[src]

impl From<Key<SecretParts, SubordinateRole>> for Key<PublicParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, SubordinateRole>> for &'_ Key<PublicParts, PrimaryRole>[src]

impl From<Key<SecretParts, SubordinateRole>> for Key<PublicParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, SubordinateRole>> for &'_ Key<PublicParts, UnspecifiedRole>[src]

impl From<Key<SecretParts, SubordinateRole>> for Key<UnspecifiedParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, SubordinateRole>> for &'_ Key<UnspecifiedParts, PrimaryRole>[src]

impl From<Key<SecretParts, SubordinateRole>> for Key<UnspecifiedParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, SubordinateRole>> for &'_ Key<UnspecifiedParts, UnspecifiedRole>[src]

impl From<Key<SecretParts, UnspecifiedRole>> for Key<PublicParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, UnspecifiedRole>> for &'_ Key<PublicParts, PrimaryRole>[src]

impl From<Key<SecretParts, UnspecifiedRole>> for Key<PublicParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, UnspecifiedRole>> for &'_ Key<PublicParts, SubordinateRole>[src]

impl From<Key<SecretParts, UnspecifiedRole>> for Key<UnspecifiedParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, UnspecifiedRole>> for &'_ Key<UnspecifiedParts, PrimaryRole>[src]

impl From<Key<SecretParts, UnspecifiedRole>> for Key<UnspecifiedParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<SecretParts, UnspecifiedRole>> for &'_ Key<UnspecifiedParts, SubordinateRole>[src]

impl From<Key<UnspecifiedParts, PrimaryRole>> for Key<PublicParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, PrimaryRole>> for &'_ Key<PublicParts, SubordinateRole>[src]

impl From<Key<UnspecifiedParts, PrimaryRole>> for Key<PublicParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, PrimaryRole>> for &'_ Key<PublicParts, UnspecifiedRole>[src]

impl From<Key<UnspecifiedParts, PrimaryRole>> for Key<SecretParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, PrimaryRole>> for &'_ Key<SecretParts, SubordinateRole>[src]

impl From<Key<UnspecifiedParts, PrimaryRole>> for Key<SecretParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, PrimaryRole>> for &'_ Key<SecretParts, UnspecifiedRole>[src]

impl From<Key<UnspecifiedParts, SubordinateRole>> for Key<PublicParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, SubordinateRole>> for &'_ Key<PublicParts, PrimaryRole>[src]

impl From<Key<UnspecifiedParts, SubordinateRole>> for Key<PublicParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, SubordinateRole>> for &'_ Key<PublicParts, UnspecifiedRole>[src]

impl From<Key<UnspecifiedParts, SubordinateRole>> for Key<SecretParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, SubordinateRole>> for &'_ Key<SecretParts, PrimaryRole>[src]

impl From<Key<UnspecifiedParts, SubordinateRole>> for Key<SecretParts, UnspecifiedRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, SubordinateRole>> for &'_ Key<SecretParts, UnspecifiedRole>[src]

impl From<Key<UnspecifiedParts, UnspecifiedRole>> for Key<PublicParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, UnspecifiedRole>> for &'_ Key<PublicParts, PrimaryRole>[src]

impl From<Key<UnspecifiedParts, UnspecifiedRole>> for Key<PublicParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, UnspecifiedRole>> for &'_ Key<PublicParts, SubordinateRole>[src]

impl From<Key<UnspecifiedParts, UnspecifiedRole>> for Key<SecretParts, PrimaryRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, UnspecifiedRole>> for &'_ Key<SecretParts, PrimaryRole>[src]

impl From<Key<UnspecifiedParts, UnspecifiedRole>> for Key<SecretParts, SubordinateRole>[src]

impl<'_, '_> From<&'_ Key<UnspecifiedParts, UnspecifiedRole>> for &'_ Key<SecretParts, SubordinateRole>[src]

impl<P, R> From<Key4<P, R>> for Key<P, R> where
    P: KeyParts,
    R: KeyRole
[src]

impl From<Key<PublicParts, PrimaryRole>> for Packet[src]

fn from(k: Key<PublicParts, PrimaryRole>) -> Self[src]

Convert the Key struct to a Packet.

impl From<Key<PublicParts, SubordinateRole>> for Packet[src]

fn from(k: Key<PublicParts, SubordinateRole>) -> Self[src]

Convert the Key struct to a Packet.

impl From<Key<SecretParts, PrimaryRole>> for Packet[src]

fn from(k: Key<SecretParts, PrimaryRole>) -> Self[src]

Convert the Key struct to a Packet.

impl From<Key<SecretParts, SubordinateRole>> for Packet[src]

fn from(k: Key<SecretParts, SubordinateRole>) -> Self[src]

Convert the Key struct to a Packet.

impl<'a> From<&'a Key<PublicParts, UnspecifiedRole>> for Recipient<'a>[src]

impl<P: Eq + KeyParts, R: Eq + KeyRole> Eq for Key<P, R>[src]

impl<P: PartialEq + KeyParts, R: PartialEq + KeyRole> PartialEq<Key<P, R>> for Key<P, R>[src]

impl<P: Clone + KeyParts, R: Clone + KeyRole> Clone for Key<P, R>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<P: KeyParts, R: KeyRole> Display for Key<P, R>[src]

impl<P: KeyParts, R: KeyRole> Deref for Key<P, R>[src]

type Target = Key4<P, R>

The resulting type after dereferencing.

impl<P: Hash + KeyParts, R: Hash + KeyRole> Hash for Key<P, R>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<P: KeyParts, R: KeyRole> DerefMut for Key<P, R>[src]

impl<P: Debug + KeyParts, R: Debug + KeyRole> Debug for Key<P, R>[src]

Auto Trait Implementations

impl<P, R> Send for Key<P, R> where
    P: Send,
    R: Send

impl<P, R> Sync for Key<P, R> where
    P: Sync,
    R: Sync

Blanket Implementations

impl<T> From for T[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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 for T where
    V: MultiLane<T>,