diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-02-07 16:04:42 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-02-07 16:09:19 +0100 |
commit | a7623fe48011577b779917d4e528f7ec6328353b (patch) | |
tree | 9027b500ed4db74fa9216e4db358a1507f4a5f52 | |
parent | 6085525cccc8b284c62a05eb6faa7e5ec172f5c7 (diff) |
openpgp: Add trait cert::Preferences.
- This trait allows querying of the key holder's preferences. It is
implemented for ValidComponentAmalgamation and
ValidPrimaryKeyAmalgamation.
-rw-r--r-- | openpgp/src/cert/amalgamation.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/key_amalgamation.rs | 3 | ||||
-rw-r--r-- | openpgp/src/cert/mod.rs | 63 |
3 files changed, 67 insertions, 1 deletions
diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index b6b78ab7..4db585f3 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -423,3 +423,5 @@ impl<'a, C> Amalgamation<'a> for ValidComponentAmalgamation<'a, C> { } } +impl<'a, C> crate::cert::Preferences<'a> + for ValidComponentAmalgamation<'a, C> {} diff --git a/openpgp/src/cert/key_amalgamation.rs b/openpgp/src/cert/key_amalgamation.rs index 00a4570b..485529a5 100644 --- a/openpgp/src/cert/key_amalgamation.rs +++ b/openpgp/src/cert/key_amalgamation.rs @@ -689,3 +689,6 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> self.a.revoked() } } + +impl<'a, P: key::KeyParts> crate::cert::Preferences<'a> + for ValidPrimaryKeyAmalgamation<'a, P> {} diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 0e277fd3..19212f5d 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -17,7 +17,6 @@ use crate::{ Result, RevocationStatus, SignatureType, - HashAlgorithm, packet, packet::Signature, packet::signature, @@ -35,7 +34,13 @@ use crate::{ }; use crate::parse::{Parse, PacketParserResult, PacketParser}; use crate::types::{ + AEADAlgorithm, + CompressionAlgorithm, + Features, + HashAlgorithm, + KeyServerPreferences, ReasonForRevocation, + SymmetricAlgorithm, }; mod amalgamation; @@ -236,6 +241,62 @@ type UserAttributeBindings = ComponentBundles<UserAttribute>; /// Note: all signatures are stored as certifications. type UnknownBindings = ComponentBundles<Unknown>; +/// Queries certificate holder's preferences. +/// +/// A certificate's key holder controls the primary key. Subpackets +/// 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::Amalgamation<'a> { + /// Returns symmetric algorithms that the key holder prefers. + /// + /// The algorithms are ordered according by the key holder's + /// preference. + fn preferred_symmetric_algorithms(&self) + -> Option<&'a [SymmetricAlgorithm]> { + self.map(|s| s.preferred_symmetric_algorithms()) + } + + /// Returns hash algorithms that the key holder prefers. + /// + /// The algorithms are ordered according by the key holder's + /// preference. + fn preferred_hash_algorithms(&self) -> Option<&'a [HashAlgorithm]> { + self.map(|s| s.preferred_hash_algorithms()) + } + + /// Returns compression algorithms that the key holder prefers. + /// + /// The algorithms are ordered according by the key holder's + /// preference. + fn preferred_compression_algorithms(&self) + -> Option<&'a [CompressionAlgorithm]> { + self.map(|s| s.preferred_compression_algorithms()) + } + + /// Returns AEAD algorithms that the key holder prefers. + /// + /// The algorithms are ordered according by the key holder's + /// preference. + fn preferred_aead_algorithms(&self) -> Option<&'a [AEADAlgorithm]> { + self.map(|s| s.preferred_aead_algorithms()) + } + + /// Returns the key holder's keyserver preferences. + fn key_server_preferences(&self) -> Option<KeyServerPreferences> { + self.map(|s| s.key_server_preferences()) + } + + /// Returns the key holder's preferred keyserver for updates. + fn preferred_key_server(&self) -> Option<&'a [u8]> { + self.map(|s| s.preferred_key_server()) + } + + /// Returns the key holder's feature set. + fn features(&self) -> Option<Features> { + self.map(|s| s.features()) + } +} // DOC-HACK: To avoid having a top-level re-export of `Cert`, we move // it in a submodule `def`. |