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

pub enum Key {
    V4(Key4),
}

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

See Section 5.5 of RFC 4880 for details.

Variants

V4(Key4)

Key packet version 4.

Methods

impl Key[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.

pub fn into_keypair(self) -> Result<KeyPair>[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.

pub fn into_packet(self, tag: Tag) -> Result<Packet>[src]

Convert the Key struct to a Packet.

impl Key[src]

pub fn bind<H, T>(
    &self,
    signer: &mut dyn Signer,
    tpk: &TPK,
    signature: Builder,
    hash_algo: H,
    creation_time: T
) -> Result<Signature> where
    H: Into<Option<HashAlgorithm>>,
    T: Into<Option<Tm>>, 
[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().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::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_packet(Tag::SecretSubkey)?,
                                 binding.into()])?;

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

pub fn revoke<H, T>(
    &self,
    signer: &mut dyn Signer,
    tpk: &TPK,
    code: ReasonForRevocation,
    reason: &[u8],
    hash_algo: H,
    creation_time: T
) -> Result<Signature> where
    H: Into<Option<HashAlgorithm>>,
    T: Into<Option<Tm>>, 
[src]

Returns a revocation certificate for the subkey.

The revocation signature revokes the binding between this user attribute and tpk. signer will be used to create a signature with the given reason in code and reason. signature_type. hash_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

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

// Generate the revocation for the first and only Subkey.
let revocation =
    tpk.subkeys().nth(0).unwrap().subkey()
        .revoke(&mut keypair, &tpk,
                ReasonForRevocation::KeyRetired,
                b"Smells funny.", None, None)?;
assert_eq!(revocation.sigtype(), SignatureType::SubkeyRevocation);

// Now merge the revocation signature into the TPK.
let tpk = tpk.merge_packets(vec![revocation.clone().into()])?;

// Check that it is revoked.
let subkey = tpk.subkeys().nth(0).unwrap();
if let RevocationStatus::Revoked(revocations) = subkey.revoked(None) {
    assert_eq!(revocations.len(), 1);
    assert_eq!(revocations[0], revocation);
} else {
    panic!("Subkey is not revoked.");
}

Methods from Deref<Target = Key4>

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<&SecretKey>[src]

Gets the key packet's SecretKey.

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

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

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

Sets the key packet's SecretKey.

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 Clone for Key[src]

impl Debug for Key[src]

impl Deref for Key[src]

type Target = Key4

The resulting type after dereferencing.

impl DerefMut for Key[src]

impl Display for Key[src]

impl Eq for Key[src]

impl From<Key4> for Key[src]

impl From<KeyPair> for Key[src]

impl Hash for Key[src]

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

impl PartialEq<Key> for Key[src]

impl Serialize for Key[src]

impl SerializeInto for Key[src]

impl StructuralEq for Key[src]

impl StructuralPartialEq for Key[src]

Auto Trait Implementations

impl !RefUnwindSafe for Key

impl Send for Key

impl !Sync for Key

impl Unpin for Key

impl !UnwindSafe for Key

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<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.