From 8bb6ca2b4a99cc2824c7fb6d8f34d8086e99e852 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Thu, 20 Feb 2020 16:16:02 +0100 Subject: openpgp: Split the ValidAmalgamation trait. - Split the ValidAmalgamation trait into two traits, Amalgamation and ValidAmalgamation, so that the functionality made available by the Amalgamation trait can be provided by a ComponentAmalgamation, which doesn't have a policy. --- ipc/examples/gpg-agent-decrypt.rs | 1 + openpgp-ffi/src/parse/stream.rs | 5 ++++- openpgp/examples/decrypt-with.rs | 1 + openpgp/src/cert/amalgamation.rs | 23 +++++++++++++++-------- openpgp/src/cert/components.rs | 1 + openpgp/src/cert/key_amalgamation.rs | 25 +++++++++++++++++-------- openpgp/src/parse/stream.rs | 1 + sqv/src/sqv.rs | 1 + tool/src/commands/mod.rs | 1 + 9 files changed, 42 insertions(+), 17 deletions(-) diff --git a/ipc/examples/gpg-agent-decrypt.rs b/ipc/examples/gpg-agent-decrypt.rs index 16d3a85a..a42803d8 100644 --- a/ipc/examples/gpg-agent-decrypt.rs +++ b/ipc/examples/gpg-agent-decrypt.rs @@ -7,6 +7,7 @@ extern crate clap; extern crate sequoia_openpgp as openpgp; extern crate sequoia_ipc as ipc; +use crate::openpgp::cert::components::Amalgamation; use crate::openpgp::crypto::SessionKey; use crate::openpgp::types::SymmetricAlgorithm; use crate::openpgp::packet::key; diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs index 9c6a8de5..419c5c5d 100644 --- a/openpgp-ffi/src/parse/stream.rs +++ b/openpgp-ffi/src/parse/stream.rs @@ -16,7 +16,10 @@ use libc::{c_int, c_void, time_t}; extern crate sequoia_openpgp as openpgp; use self::openpgp::{ - cert::components::ValidAmalgamation, + cert::components::{ + Amalgamation, + ValidAmalgamation, + }, crypto::SessionKey, types::SymmetricAlgorithm, packet::{ diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs index ca84a918..e74bcac2 100644 --- a/openpgp/examples/decrypt-with.rs +++ b/openpgp/examples/decrypt-with.rs @@ -8,6 +8,7 @@ use std::io; extern crate failure; extern crate sequoia_openpgp as openpgp; +use crate::openpgp::cert::components::Amalgamation; use crate::openpgp::crypto::{KeyPair, SessionKey}; use crate::openpgp::types::SymmetricAlgorithm; use crate::openpgp::parse::{ diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index 64f5adf3..380abbeb 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -31,6 +31,13 @@ impl<'a, C> std::ops::Deref for ComponentAmalgamation<'a, C> { } } +impl<'a, C> Amalgamation<'a> for ComponentAmalgamation<'a, C> { + /// Returns the certificate that the component came from. + fn cert(&self) -> &'a Cert { + self.cert + } +} + impl<'a, C> ComponentAmalgamation<'a, C> { /// Creates a new amalgamation. pub(crate) fn new(cert: &'a Cert, bundle: &'a ComponentBundle) -> Self @@ -41,11 +48,6 @@ impl<'a, C> ComponentAmalgamation<'a, C> { } } - /// Returns the certificate that the component came from. - pub fn cert(&self) -> &'a Cert { - self.cert - } - /// Returns this component's bundle. pub fn bundle(&self) -> &'a ComponentBundle { &self.bundle @@ -199,11 +201,14 @@ impl<'a, C> ValidComponentAmalgamation<'a, C> } } -/// Represents a component under a given policy. -pub trait ValidAmalgamation<'a> { +/// Represents a component. +pub trait Amalgamation<'a> { /// Returns the certificate that the component came from. fn cert(&self) -> &'a Cert; +} +/// Represents a component under a given policy. +pub trait ValidAmalgamation<'a> : Amalgamation<'a>{ /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this @@ -377,13 +382,15 @@ pub trait ValidAmalgamation<'a> { } } -impl<'a, C> ValidAmalgamation<'a> for ValidComponentAmalgamation<'a, C> { +impl<'a, C> Amalgamation<'a> for ValidComponentAmalgamation<'a, C> { // NOTE: No docstring, because ComponentAmalgamation has the same method. // Returns the certificate that the component came from. fn cert(&self) -> &'a Cert { self.cert } +} +impl<'a, C> ValidAmalgamation<'a> for ValidComponentAmalgamation<'a, C> { /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this diff --git a/openpgp/src/cert/components.rs b/openpgp/src/cert/components.rs index 3965e65f..365c3f1c 100644 --- a/openpgp/src/cert/components.rs +++ b/openpgp/src/cert/components.rs @@ -25,6 +25,7 @@ use super::{ canonical_signature_order, }; pub use super::amalgamation::{ + Amalgamation, ComponentAmalgamation, ValidAmalgamation, ValidComponentAmalgamation, diff --git a/openpgp/src/cert/key_amalgamation.rs b/openpgp/src/cert/key_amalgamation.rs index f0e5c50b..dcc74599 100644 --- a/openpgp/src/cert/key_amalgamation.rs +++ b/openpgp/src/cert/key_amalgamation.rs @@ -7,6 +7,7 @@ use failure::ResultExt; use crate::{ Cert, cert::components::{ + Amalgamation, KeyBundle, ValidAmalgamation, }, @@ -46,6 +47,12 @@ impl<'a, P: key::KeyParts> Deref for KeyAmalgamation<'a, P> { } } +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for KeyAmalgamation<'a, P> { + fn cert(&self) -> &'a Cert { + self.cert + } +} + impl<'a, P: 'a + key::KeyParts> KeyAmalgamation<'a, P> { pub(crate) fn new_primary(cert: &'a Cert) -> Self { KeyAmalgamation { @@ -87,12 +94,6 @@ impl<'a, P: 'a + key::KeyParts> KeyAmalgamation<'a, P> { } } - /// Returns the certificate that the key came from. - pub fn cert(&self) -> &'a Cert - { - self.cert - } - /// Returns this key's bundle. pub fn bundle(&self) -> &'a KeyBundle { match self { @@ -273,7 +274,7 @@ impl<'a, P: key::KeyParts> From> } } -impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for ValidKeyAmalgamation<'a, P> { // NOTE: No docstring, because KeyAmalgamation has the same method. @@ -281,7 +282,11 @@ impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> fn cert(&self) -> &'a Cert { self.cert } +} +impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> + for ValidKeyAmalgamation<'a, P> +{ /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this @@ -452,7 +457,7 @@ impl<'a, P: key::KeyParts> ValidPrimaryKeyAmalgamation<'a, P> { } } -impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for ValidPrimaryKeyAmalgamation<'a, P> { // NOTE: No docstring, because KeyAmalgamation has the same method. @@ -460,7 +465,11 @@ impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> fn cert(&self) -> &'a Cert { self.a.cert() } +} +impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> + for ValidPrimaryKeyAmalgamation<'a, P> +{ /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index ceca3e3c..646da1fe 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -44,6 +44,7 @@ use crate::{ packet::Signature, Cert, cert::components::{ + Amalgamation, ValidAmalgamation, ValidKeyAmalgamation, }, diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs index 286a9550..232c8994 100644 --- a/sqv/src/sqv.rs +++ b/sqv/src/sqv.rs @@ -15,6 +15,7 @@ extern crate sequoia_openpgp as openpgp; use crate::openpgp::{ Cert, + cert::components::Amalgamation, KeyHandle, Result, parse::Parse, diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index 1e0faf85..dfb1dfdd 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -13,6 +13,7 @@ use crate::openpgp::types::{ }; use crate::openpgp::crypto; use crate::openpgp::{Cert, KeyID, Result}; +use crate::openpgp::cert::components::Amalgamation; use crate::openpgp::packet::prelude::*; use crate::openpgp::parse::{ Parse, -- cgit v1.2.3