[][src]Trait sequoia_openpgp::packet::key::KeyParts

pub trait KeyParts: Debug {
    fn convert_key<R: KeyRole>(
        key: Key<UnspecifiedParts, R>
    ) -> Result<Key<Self, R>>
    where
        Self: Sized
;
fn convert_key_ref<R: KeyRole>(
        key: &Key<UnspecifiedParts, R>
    ) -> Result<&Key<Self, R>>
    where
        Self: Sized
;
fn convert_bundle<R: KeyRole>(
        bundle: KeyBundle<UnspecifiedParts, R>
    ) -> Result<KeyBundle<Self, R>>
    where
        Self: Sized
;
fn convert_bundle_ref<R: KeyRole>(
        bundle: &KeyBundle<UnspecifiedParts, R>
    ) -> Result<&KeyBundle<Self, R>>
    where
        Self: Sized
;
fn convert_key_amalgamation<'a, R: KeyRole>(
        ka: ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>
    ) -> Result<ComponentAmalgamation<'a, Key<Self, R>>>
    where
        Self: Sized
;
fn convert_key_amalgamation_ref<'a, R: KeyRole>(
        ka: &'a ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>
    ) -> Result<&'a ComponentAmalgamation<'a, Key<Self, R>>>
    where
        Self: Sized
; }

A marker trait that captures whether a Key definitely contains secret key material.

A Key can be treated as if it only has public key material (key::PublicParts) or also has secret key material (key::SecretParts). For those cases where the type information needs to be erased (e.g., interfaces like Cert::keys), we provide the key::UnspecifiedParts marker.

Even if a Key does not have the SecretKey marker, it may still have secret key material. But, it will generally act as if it didn't. In particular, when serializing a Key without the SecretKey marker, secret key material will be ignored. See the documentation for Key for a demonstration of this behavior.

Required methods

fn convert_key<R: KeyRole>(
    key: Key<UnspecifiedParts, R>
) -> Result<Key<Self, R>> where
    Self: Sized

Converts a key with unspecified parts into this kind of key.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key to one with key::SecretParts only succeeds if the key actually contains secret key material.

Examples

For a less construed example, refer to the source code:

use sequoia_openpgp as openpgp;
use openpgp::Result;
use openpgp::packet::prelude::*;

fn f<P>(cert: &Cert, mut key: Key<P, key::UnspecifiedRole>)
    -> Result<Key<P, key::UnspecifiedRole>>
    where P: key::KeyParts
{
    // ...

    if criterium {
        // Cert::primary_key's return type is concrete
        // (Key<key::PublicParts, key::PrimaryRole>).  We need to
        // convert it to the generic type Key<P, key::UnspecifiedRole>.
        // First, we "downcast" it to have unspecified parts and an
        // unspecified role, then we use a method defined by the
        // generic type to perform the conversion to the generic
        // type P.
        key = P::convert_key(
            cert.primary_key().key().clone()
                .parts_into_unspecified()
                .role_into_unspecified())?;
    }

    // ...

    Ok(key)
}

fn convert_key_ref<R: KeyRole>(
    key: &Key<UnspecifiedParts, R>
) -> Result<&Key<Self, R>> where
    Self: Sized

Converts a key reference with unspecified parts into this kind of key reference.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key to one with key::SecretParts only succeeds if the key actually contains secret key material.

fn convert_bundle<R: KeyRole>(
    bundle: KeyBundle<UnspecifiedParts, R>
) -> Result<KeyBundle<Self, R>> where
    Self: Sized

Converts a key bundle with unspecified parts into this kind of key bundle.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key bundle with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key bundle to one with key::SecretParts only succeeds if the key bundle actually contains secret key material.

fn convert_bundle_ref<R: KeyRole>(
    bundle: &KeyBundle<UnspecifiedParts, R>
) -> Result<&KeyBundle<Self, R>> where
    Self: Sized

Converts a key bundle reference with unspecified parts into this kind of key bundle reference.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key bundle with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key bundle to one with key::SecretParts only succeeds if the key bundle actually contains secret key material.

fn convert_key_amalgamation<'a, R: KeyRole>(
    ka: ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>
) -> Result<ComponentAmalgamation<'a, Key<Self, R>>> where
    Self: Sized

Converts a key amalgamation with unspecified parts into this kind of key amalgamation.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key amalgamation with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key amalgamation to one with key::SecretParts only succeeds if the key amalgamation actually contains secret key material.

fn convert_key_amalgamation_ref<'a, R: KeyRole>(
    ka: &'a ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>
) -> Result<&'a ComponentAmalgamation<'a, Key<Self, R>>> where
    Self: Sized

Converts a key amalgamation reference with unspecified parts into this kind of key amalgamation reference.

This function is helpful when you need to convert a concrete type into a generic type. Using From works, but requires adding a type bound to the generic type, which is ugly and invasive.

Converting a key amalgamation with key::PublicParts or key::UnspecifiedParts will always succeed. However, converting a key amalgamation to one with key::SecretParts only succeeds if the key amalgamation actually contains secret key material.

Loading content...

Implementors

impl KeyParts for PublicParts[src]

impl KeyParts for SecretParts[src]

impl KeyParts for UnspecifiedParts[src]

Loading content...