openpgp: Provide ValidKeyAmalgamation conversion in marker trait.

parent b43dffe8
Pipeline #116926998 passed with stage
in 3 minutes and 32 seconds
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment