diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-02-20 22:10:48 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-02-20 22:11:54 +0100 |
commit | a57262d26636590eaec123d7b60b9efdd604a61e (patch) | |
tree | c3b24fe46302468ce68ff7317ebb2de314bfec42 | |
parent | 291edaec90f6ef8dd6daab96478bd7d33a0066ab (diff) |
openpgp: Add the bundle method to the Amalgamation trait.
- Add the `bundle()` method to the Amalgamation trait instead of
implementing it on each struct.
-rw-r--r-- | autocrypt/src/lib.rs | 5 | ||||
-rw-r--r-- | examples/guide-exploring-openpgp.rs | 1 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation.rs | 30 | ||||
-rw-r--r-- | openpgp/src/cert/builder.rs | 1 | ||||
-rw-r--r-- | openpgp/src/cert/component_iter.rs | 3 | ||||
-rw-r--r-- | openpgp/src/cert/key_amalgamation.rs | 56 | ||||
-rw-r--r-- | openpgp/src/cert/mod.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 1 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 1 | ||||
-rw-r--r-- | openpgp/src/serialize/cert.rs | 1 | ||||
-rw-r--r-- | tool/src/commands/inspect.rs | 2 |
11 files changed, 63 insertions, 42 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs index f5f5988c..cb3f32cf 100644 --- a/autocrypt/src/lib.rs +++ b/autocrypt/src/lib.rs @@ -27,7 +27,10 @@ pub use openpgp::Result; use openpgp::Packet; use openpgp::packet::SKESK; use openpgp::Cert; -use openpgp::cert::components::ValidAmalgamation; +use openpgp::cert::components::{ + Amalgamation, + ValidAmalgamation +}; use openpgp::parse::{ Parse, PacketParserResult, PacketParser, diff --git a/examples/guide-exploring-openpgp.rs b/examples/guide-exploring-openpgp.rs index 298fcd6c..c6b603dc 100644 --- a/examples/guide-exploring-openpgp.rs +++ b/examples/guide-exploring-openpgp.rs @@ -1,6 +1,7 @@ //! https://sequoia-pgp.org/guide/exploring-openpgp/ extern crate sequoia_openpgp as openpgp; +use crate::openpgp::cert::components::Amalgamation; use crate::openpgp::parse::Parse; use crate::openpgp::policy::StandardPolicy as P; diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index 380abbeb..9b7d0f1e 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -31,11 +31,14 @@ 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. +impl<'a, C> Amalgamation<'a, C> for ComponentAmalgamation<'a, C> { fn cert(&self) -> &'a Cert { self.cert } + + fn bundle(&self) -> &'a ComponentBundle<C> { + &self.bundle + } } impl<'a, C> ComponentAmalgamation<'a, C> { @@ -48,11 +51,6 @@ impl<'a, C> ComponentAmalgamation<'a, C> { } } - /// Returns this component's bundle. - pub fn bundle(&self) -> &'a ComponentBundle<C> { - &self.bundle - } - /// Returns the components's binding signature as of the reference /// time, if any. /// @@ -202,13 +200,17 @@ impl<'a, C> ValidComponentAmalgamation<'a, C> } /// Represents a component. -pub trait Amalgamation<'a> { +pub trait Amalgamation<'a, C> { /// Returns the certificate that the component came from. fn cert(&self) -> &'a Cert; + + + /// Returns this component's bundle. + fn bundle(&self) -> &'a ComponentBundle<C>; } /// Represents a component under a given policy. -pub trait ValidAmalgamation<'a> : Amalgamation<'a>{ +pub trait ValidAmalgamation<'a, C> : Amalgamation<'a, C>{ /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this @@ -382,15 +384,19 @@ pub trait ValidAmalgamation<'a> : Amalgamation<'a>{ } } -impl<'a, C> Amalgamation<'a> for ValidComponentAmalgamation<'a, C> { +impl<'a, C> Amalgamation<'a, C> 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 } + + fn bundle(&self) -> &'a ComponentBundle<C> { + self.bundle + } } -impl<'a, C> ValidAmalgamation<'a> for ValidComponentAmalgamation<'a, C> { +impl<'a, C> ValidAmalgamation<'a, C> for ValidComponentAmalgamation<'a, C> { /// Returns the amalgamation's reference time. /// /// For queries that are with respect to a point in time, this @@ -461,5 +467,5 @@ impl<'a, C> ValidAmalgamation<'a> for ValidComponentAmalgamation<'a, C> { } } -impl<'a, C> crate::cert::Preferences<'a> +impl<'a, C> crate::cert::Preferences<'a, C> for ValidComponentAmalgamation<'a, C> {} diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 00676576..1a8ea4be 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -428,6 +428,7 @@ impl CertBuilder { #[cfg(test)] mod tests { use super::*; + use crate::cert::components::Amalgamation; use crate::cert::components::ValidAmalgamation; use crate::packet::signature::subpacket::{SubpacketTag, SubpacketValue}; use crate::types::PublicKeyAlgorithm; diff --git a/openpgp/src/cert/component_iter.rs b/openpgp/src/cert/component_iter.rs index ff844ac8..ec017fe9 100644 --- a/openpgp/src/cert/component_iter.rs +++ b/openpgp/src/cert/component_iter.rs @@ -6,6 +6,7 @@ use crate::{ cert::{ Cert, components::{ + Amalgamation, ComponentBundle, ComponentBundleIter, ComponentAmalgamation, @@ -182,7 +183,7 @@ impl<'a, C> ValidComponentIter<'a, C> { /// # use openpgp::Result; /// # use openpgp::cert::CertBuilder; /// use openpgp::types::RevocationStatus; - /// use openpgp::cert::components::ValidAmalgamation; + /// use openpgp::cert::components::{Amalgamation, ValidAmalgamation}; /// use sequoia_openpgp::policy::StandardPolicy; /// /// # fn main() { f().unwrap(); } diff --git a/openpgp/src/cert/key_amalgamation.rs b/openpgp/src/cert/key_amalgamation.rs index dcc74599..be72ebe2 100644 --- a/openpgp/src/cert/key_amalgamation.rs +++ b/openpgp/src/cert/key_amalgamation.rs @@ -47,10 +47,25 @@ impl<'a, P: key::KeyParts> Deref for KeyAmalgamation<'a, P> { } } -impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for KeyAmalgamation<'a, P> { +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a, Key<P, key::UnspecifiedRole>> + for KeyAmalgamation<'a, P> +{ fn cert(&self) -> &'a Cert { self.cert } + + fn bundle(&self) -> &'a KeyBundle<P, key::UnspecifiedRole> { + match self { + KeyAmalgamation { bundle: KeyAmalgamationBundle::Primary(), .. } => + P::convert_bundle_ref((&self.cert.primary).into()) + .expect("secret key amalgamations contain secret keys"), + KeyAmalgamation { bundle: KeyAmalgamationBundle::Subordinate(bundle), .. } => + P::convert_bundle_ref((*bundle) + .mark_parts_unspecified_ref() + .mark_role_unspecified_ref()) + .expect("secret key amalgamations contain secret keys"), + } + } } impl<'a, P: 'a + key::KeyParts> KeyAmalgamation<'a, P> { @@ -94,20 +109,6 @@ impl<'a, P: 'a + key::KeyParts> KeyAmalgamation<'a, P> { } } - /// Returns this key's bundle. - pub fn bundle(&self) -> &'a KeyBundle<P, key::UnspecifiedRole> { - match self { - KeyAmalgamation { bundle: KeyAmalgamationBundle::Primary(), .. } => - P::convert_bundle_ref((&self.cert.primary).into()) - .expect("secret key amalgamations contain secret keys"), - KeyAmalgamation { bundle: KeyAmalgamationBundle::Subordinate(bundle), .. } => - P::convert_bundle_ref((*bundle) - .mark_parts_unspecified_ref() - .mark_role_unspecified_ref()) - .expect("secret key amalgamations contain secret keys"), - } - } - /// Returns the key's binding signature as of the reference time, /// if any. /// @@ -274,17 +275,21 @@ impl<'a, P: key::KeyParts> From<ValidKeyAmalgamation<'a, P>> } } -impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a, Key<P, key::UnspecifiedRole>> for ValidKeyAmalgamation<'a, P> { // NOTE: No docstring, because KeyAmalgamation has the same method. // Returns the certificate that the component came from. fn cert(&self) -> &'a Cert { - self.cert + self.a.cert + } + + fn bundle(&self) -> &'a KeyBundle<P, key::UnspecifiedRole> { + self.a.bundle() } } -impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> +impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a, Key<P, key::UnspecifiedRole>> for ValidKeyAmalgamation<'a, P> { /// Returns the amalgamation's reference time. @@ -364,11 +369,6 @@ impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> } impl<'a, P: 'a + key::KeyParts> ValidKeyAmalgamation<'a, P> { - /// Returns this key's bundle. - pub fn bundle(&self) -> &'a KeyBundle<P, key::UnspecifiedRole> { - self.a.bundle() - } - /// Returns whether the key is alive as of the amalgamtion's /// reference time. /// @@ -457,7 +457,7 @@ impl<'a, P: key::KeyParts> ValidPrimaryKeyAmalgamation<'a, P> { } } -impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> +impl<'a, P: 'a + key::KeyParts> Amalgamation<'a, Key<P, key::UnspecifiedRole>> for ValidPrimaryKeyAmalgamation<'a, P> { // NOTE: No docstring, because KeyAmalgamation has the same method. @@ -465,9 +465,13 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> fn cert(&self) -> &'a Cert { self.a.cert() } + + fn bundle(&self) -> &'a KeyBundle<P, key::UnspecifiedRole> { + &self.a.bundle() + } } -impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> +impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a, Key<P, key::UnspecifiedRole>> for ValidPrimaryKeyAmalgamation<'a, P> { /// Returns the amalgamation's reference time. @@ -541,5 +545,5 @@ impl<'a, P: 'a + key::KeyParts> ValidAmalgamation<'a> } } -impl<'a, P: key::KeyParts> crate::cert::Preferences<'a> +impl<'a, P: key::KeyParts> crate::cert::Preferences<'a, Key<P, key::UnspecifiedRole>> for ValidPrimaryKeyAmalgamation<'a, P> {} diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 988ef3fb..b640b8b5 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -48,6 +48,7 @@ mod builder; mod bindings; pub mod components; use components::{ + Amalgamation, ComponentBundle, PrimaryKeyBundle, UnfilteredKeyBundleIter, @@ -252,7 +253,7 @@ type UnknownBindings = ComponentBundles<Unknown>; /// on self signatures can be used to express preferences for /// algorithms and key management. Furthermore, the key holder's /// OpenPGP implementation can express its feature set. -pub trait Preferences<'a>: components::ValidAmalgamation<'a> { +pub trait Preferences<'a, C>: components::ValidAmalgamation<'a, C> { /// Returns symmetric algorithms that the key holder prefers. /// /// The algorithms are ordered according by the key holder's @@ -349,6 +350,7 @@ use super::*; /// ```rust /// # extern crate sequoia_openpgp as openpgp; /// # use openpgp::Result; +/// # use openpgp::cert::components::Amalgamation; /// # use openpgp::parse::{Parse, PacketParserResult, PacketParser}; /// use openpgp::{Cert, cert::CertBuilder}; /// diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 004eba7d..71fb5da7 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1126,6 +1126,7 @@ impl From<Signature4> for super::Signature { mod test { use super::*; use crate::KeyID; + use crate::cert::components::Amalgamation; use crate::crypto; use crate::crypto::mpis::MPI; use crate::Cert; diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index e55d3ba5..d8971a48 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -540,6 +540,7 @@ mod test { use crate::Error; use crate::Fingerprint; use crate::cert::{Cert, CertBuilder, CipherSuite}; + use crate::cert::components::Amalgamation; use crate::crypto::SessionKey; use crate::packet::key::Key4; use crate::packet::signature; diff --git a/openpgp/src/serialize/cert.rs b/openpgp/src/serialize/cert.rs index a74ebc35..63414d8e 100644 --- a/openpgp/src/serialize/cert.rs +++ b/openpgp/src/serialize/cert.rs @@ -1,5 +1,6 @@ use crate::Result; use crate::Cert; +use crate::cert::components::Amalgamation; use crate::packet::{key, Signature, Tag}; use crate::serialize::{ PacketRef, Serialize, SerializeInto, diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index c0e038c6..6d423239 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -4,7 +4,7 @@ use clap; extern crate sequoia_openpgp as openpgp; use crate::openpgp::{Packet, Result}; -use crate::openpgp::cert::components::ValidAmalgamation; +use crate::openpgp::cert::components::{Amalgamation, ValidAmalgamation}; use openpgp::packet::key::PublicParts; use crate::openpgp::parse::{Parse, PacketParserResult}; use crate::openpgp::policy::Policy; |