diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-02-11 15:06:11 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-02-11 15:23:41 +0100 |
commit | 54b909ef2c75f9027b5959171d4d995015f159cb (patch) | |
tree | 65b4e2acd87dadbb70d2739d511f2a5ac33bea24 /openpgp | |
parent | b43dffe86bb7e93bf548b91ff92d0565fe8981fe (diff) |
openpgp: Provide ValidKeyAmalgamation conversion in marker trait.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/packet/key/mod.rs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/openpgp/src/packet/key/mod.rs b/openpgp/src/packet/key/mod.rs index 39e339da..f01b0257 100644 --- a/openpgp/src/packet/key/mod.rs +++ b/openpgp/src/packet/key/mod.rs @@ -57,6 +57,10 @@ use std::convert::{TryFrom, TryInto}; use std::time; use crate::Error; +use crate::cert::components::{ + KeyBundle, + ValidKeyAmalgamation, +}; use crate::crypto::{self, mem::{self, Protected}, mpis, hash::Hash}; use crate::packet; use crate::packet::prelude::*; @@ -97,6 +101,20 @@ pub trait KeyParts: fmt::Debug { fn convert_bundle_ref<R: KeyRole>(bundle: &KeyBundle<UnspecifiedParts, R>) -> Result<&KeyBundle<Self, R>> where Self: Sized; + + /// Converts a key amalgamation with unspecified parts into this + /// kind of key amalgamation. + fn convert_valid_amalgamation<'a>( + amalgamation: ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<ValidKeyAmalgamation<'a, Self>> + where Self: Sized; + + /// Converts a reference to a key amalgamation with unspecified + /// parts into this kind of key amalgamation reference. + fn convert_valid_amalgamation_ref<'a>( + amalgamation: &'a ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<&'a ValidKeyAmalgamation<'a, Self>> + where Self: Sized; } /// A marker trait that indicates whether a `Key` is a primary key or @@ -154,6 +172,18 @@ impl KeyParts for PublicParts { -> Result<&KeyBundle<Self, R>> { Ok(bundle.into()) } + + fn convert_valid_amalgamation<'a>( + amalgamation: ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<ValidKeyAmalgamation<'a, Self>> { + Ok(amalgamation.into()) + } + + fn convert_valid_amalgamation_ref<'a>( + amalgamation: &'a ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<&'a ValidKeyAmalgamation<'a, Self>> { + Ok(amalgamation.into()) + } } /// Indicates that a `Key` should be treated like a secret key. @@ -184,6 +214,18 @@ impl KeyParts for SecretParts { -> Result<&KeyBundle<Self, R>> { bundle.try_into() } + + fn convert_valid_amalgamation<'a>( + amalgamation: ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<ValidKeyAmalgamation<'a, Self>> { + amalgamation.try_into() + } + + fn convert_valid_amalgamation_ref<'a>( + amalgamation: &'a ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<&'a ValidKeyAmalgamation<'a, Self>> { + amalgamation.try_into() + } } /// Indicates that a `Key`'s parts are unspecified. @@ -217,6 +259,18 @@ impl KeyParts for UnspecifiedParts { -> Result<&KeyBundle<Self, R>> { Ok(bundle) } + + fn convert_valid_amalgamation<'a>( + amalgamation: ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<ValidKeyAmalgamation<'a, Self>> { + Ok(amalgamation) + } + + fn convert_valid_amalgamation_ref<'a>( + amalgamation: &'a ValidKeyAmalgamation<'a, UnspecifiedParts>) + -> Result<&'a ValidKeyAmalgamation<'a, Self>> { + Ok(amalgamation) + } } /// Indicates that a `Key` should treated like a primary key. @@ -709,8 +763,6 @@ macro_rules! create_conversions { create_conversions!(Key); create_conversions!(Key4); - -use crate::cert::components::KeyBundle; create_conversions!(KeyBundle); /// Holds a public key, public subkey, private key or private subkey packet. |