summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openpgp-ffi/src/amalgamation.rs4
-rw-r--r--openpgp/src/cert/amalgamation.rs61
-rw-r--r--openpgp/src/cert/amalgamation/iter.rs43
-rw-r--r--openpgp/src/cert/mod.rs19
-rw-r--r--openpgp/src/cert/prelude.rs12
5 files changed, 118 insertions, 21 deletions
diff --git a/openpgp-ffi/src/amalgamation.rs b/openpgp-ffi/src/amalgamation.rs
index 248fe24f..c737da0c 100644
--- a/openpgp-ffi/src/amalgamation.rs
+++ b/openpgp-ffi/src/amalgamation.rs
@@ -26,7 +26,7 @@ use crate::maybe_time;
/// A local alias to appease the proc macro transformation.
type UserIDAmalgamationType<'a>
- = openpgp::cert::amalgamation::ComponentAmalgamation<'a, openpgp::packet::UserID>;
+ = openpgp::cert::amalgamation::UserIDAmalgamation<'a>;
/// A `UserIDAmalgamation` holds a `UserID` and associated data.
///
@@ -49,7 +49,7 @@ pub extern "C" fn pgp_user_id_amalgamation_user_id<'a>(ua: *const UserIDAmalgama
/// A local alias to appease the proc macro transformation.
type ValidUserIDAmalgamationType<'a>
- = openpgp::cert::amalgamation::ValidComponentAmalgamation<'a, openpgp::packet::UserID>;
+ = openpgp::cert::amalgamation::ValidUserIDAmalgamation<'a>;
/// A `ValidUserIDAmalgamation` holds a `UserID` and associated data
/// including a policy and a reference time.
diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs
index deb3ae06..5d10e485 100644
--- a/openpgp/src/cert/amalgamation.rs
+++ b/openpgp/src/cert/amalgamation.rs
@@ -18,7 +18,12 @@ use std::clone::Clone;
use crate::{
cert::prelude::*,
Error,
- packet::Signature,
+ packet::{
+ Signature,
+ Unknown,
+ UserAttribute,
+ UserID,
+ },
Result,
policy::Policy,
types::{
@@ -37,7 +42,13 @@ use crate::{
mod iter;
pub use iter::{
ComponentAmalgamationIter,
+ UnknownComponentAmalgamationIter,
+ UserAttributeAmalgamationIter,
+ UserIDAmalgamationIter,
ValidComponentAmalgamationIter,
+ ValidUnknownComponentAmalgamationIter,
+ ValidUserAttributeAmalgamationIter,
+ ValidUserIDAmalgamationIter,
};
mod keyiter;
@@ -208,6 +219,23 @@ pub struct ComponentAmalgamation<'a, C> {
bundle: &'a ComponentBundle<C>,
}
+/// A User ID and its associated data.
+///
+/// This is just a specialized version of `ComponentAmalgamation`.
+pub type UserIDAmalgamation<'a> = ComponentAmalgamation<'a, UserID>;
+
+/// A User Attribute and its associated data.
+///
+/// This is just a specialized version of `ComponentAmalgamation`.
+pub type UserAttributeAmalgamation<'a>
+ = ComponentAmalgamation<'a, UserAttribute>;
+
+/// An Unknown component and its associated data.
+///
+/// This is just a specialized version of `ComponentAmalgamation`.
+pub type UnknownComponentAmalgamation<'a>
+ = ComponentAmalgamation<'a, Unknown>;
+
// derive(Clone) doesn't work with generic parameters that don't
// implement clone. But, we don't need to require that C implements
// Clone, because we're not cloning C, just the reference.
@@ -487,16 +515,16 @@ impl<'a, C> ComponentAmalgamation<'a, C> {
}
}
-impl<'a> ComponentAmalgamation<'a, crate::packet::UserID> {
+impl<'a> UserIDAmalgamation<'a> {
/// Returns a reference to the User ID.
- pub fn userid(&self) -> &'a crate::packet::UserID {
+ pub fn userid(&self) -> &'a UserID {
self.component()
}
}
-impl<'a> ComponentAmalgamation<'a, crate::packet::UserAttribute> {
+impl<'a> UserAttributeAmalgamation<'a> {
/// Returns a reference to the User Attribute.
- pub fn user_attribute(&self) -> &'a crate::packet::UserAttribute {
+ pub fn user_attribute(&self) -> &'a UserAttribute {
self.component()
}
}
@@ -510,6 +538,23 @@ pub struct ValidComponentAmalgamation<'a, C> {
binding_signature: &'a Signature,
}
+/// A User ID and its associated data.
+///
+/// This is just a specialized version of `ValidComponentAmalgamation`.
+pub type ValidUserIDAmalgamation<'a> = ValidComponentAmalgamation<'a, UserID>;
+
+/// A User Attribute and its associated data.
+///
+/// This is just a specialized version of `ValidComponentAmalgamation`.
+pub type ValidUserAttributeAmalgamation<'a>
+ = ValidComponentAmalgamation<'a, UserAttribute>;
+
+/// An Unknown component and its associated data.
+///
+/// This is just a specialized version of `ValidComponentAmalgamation`.
+pub type ValidUnknownComponentAmalgamation<'a>
+ = ValidComponentAmalgamation<'a, Unknown>;
+
// derive(Clone) doesn't work with generic parameters that don't
// implement clone. But, we don't need to require that C implements
// Clone, because we're not cloning C, just the reference.
@@ -750,7 +795,6 @@ impl<'a, C> crate::cert::Preferences<'a>
mod test {
use crate::policy::StandardPolicy as P;
use crate::cert::prelude::*;
- use crate::packet::UserID;
// derive(Clone) doesn't work with generic parameters that don't
// implement clone. Make sure that our custom implementations
@@ -766,11 +810,10 @@ mod test {
.generate()
.unwrap();
- let userid : ComponentAmalgamation<UserID>
- = cert.userids().nth(0).unwrap();
+ let userid : UserIDAmalgamation = cert.userids().nth(0).unwrap();
assert_eq!(userid.userid(), userid.clone().userid());
- let userid : ValidComponentAmalgamation<UserID>
+ let userid : ValidUserIDAmalgamation
= userid.with_policy(p, None).unwrap();
let c = userid.clone();
assert_eq!(userid.userid(), c.userid());
diff --git a/openpgp/src/cert/amalgamation/iter.rs b/openpgp/src/cert/amalgamation/iter.rs
index 34eca638..0c06cbb7 100644
--- a/openpgp/src/cert/amalgamation/iter.rs
+++ b/openpgp/src/cert/amalgamation/iter.rs
@@ -5,6 +5,11 @@ use std::time::SystemTime;
use crate::{
types::RevocationStatus,
cert::prelude::*,
+ packet::{
+ Unknown,
+ UserAttribute,
+ UserID,
+ },
policy::Policy,
};
@@ -20,6 +25,25 @@ pub struct ComponentAmalgamationIter<'a, C> {
iter: slice::Iter<'a, ComponentBundle<C>>,
}
+/// An iterator over `UserIDAmalgamtion`s.
+///
+/// This is just a specialized version of `ComponentAmalgamationIter`.
+pub type UserIDAmalgamationIter<'a>
+ = ComponentAmalgamationIter<'a, UserID>;
+
+/// An iterator over `UserAttributeAmalgamtion`s.
+///
+/// This is just a specialized version of `ComponentAmalgamationIter`.
+pub type UserAttributeAmalgamationIter<'a>
+ = ComponentAmalgamationIter<'a, UserAttribute>;
+
+/// An iterator over `UnknownComponentAmalgamtion`s.
+///
+/// This is just a specialized version of `ComponentAmalgamationIter`.
+pub type UnknownComponentAmalgamationIter<'a>
+ = ComponentAmalgamationIter<'a, Unknown>;
+
+
impl<'a, C> fmt::Debug for ComponentAmalgamationIter<'a, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ComponentAmalgamationIter")
@@ -90,6 +114,25 @@ pub struct ValidComponentAmalgamationIter<'a, C> {
revoked: Option<bool>,
}
+/// An iterator over `ValidUserIDAmalgamtion`s.
+///
+/// This is just a specialized version of `ValidComponentAmalgamationIter`.
+pub type ValidUserIDAmalgamationIter<'a>
+ = ValidComponentAmalgamationIter<'a, UserID>;
+
+/// An iterator over `ValidUserAttributeAmalgamtion`s.
+///
+/// This is just a specialized version of `ValidComponentAmalgamationIter`.
+pub type ValidUserAttributeAmalgamationIter<'a>
+ = ValidComponentAmalgamationIter<'a, UserAttribute>;
+
+/// An iterator over `ValidUnknownComponentAmalgamtion`s.
+///
+/// This is just a specialized version of `ValidComponentAmalgamationIter`.
+pub type ValidUnknownComponentAmalgamationIter<'a>
+ = ValidComponentAmalgamationIter<'a, Unknown>;
+
+
impl<'a, C> fmt::Debug for ValidComponentAmalgamationIter<'a, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ValidComponentAmalgamationIter")
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs
index fdae149a..861fdd83 100644
--- a/openpgp/src/cert/mod.rs
+++ b/openpgp/src/cert/mod.rs
@@ -624,7 +624,7 @@ impl Cert {
/// Returns the amalgamated primary userid at `t`, if any.
fn primary_userid_relaxed<'a, T>(&'a self, policy: &'a dyn Policy, t: T,
valid_cert: bool)
- -> Result<ValidComponentAmalgamation<'a, UserID>>
+ -> Result<ValidUserIDAmalgamation<'a>>
where T: Into<Option<std::time::SystemTime>>
{
let t = t.into().unwrap_or_else(std::time::SystemTime::now);
@@ -634,20 +634,20 @@ impl Cert {
/// Returns the amalgamated primary userid at `t`, if any.
pub fn primary_userid<'a, T>(&'a self, policy: &'a dyn Policy, t: T)
- -> Result<ValidComponentAmalgamation<'a, UserID>>
+ -> Result<ValidUserIDAmalgamation<'a>>
where T: Into<Option<std::time::SystemTime>>
{
self.primary_userid_relaxed(policy, t, true)
}
/// Returns an iterator over the Cert's userids.
- pub fn userids(&self) -> ComponentAmalgamationIter<UserID> {
+ pub fn userids(&self) -> UserIDAmalgamationIter {
ComponentAmalgamationIter::new(self, self.userids.iter())
}
/// Returns the amalgamated primary user attribute at `t`, if any.
pub fn primary_user_attribute<'a, T>(&'a self, policy: &'a dyn Policy, t: T)
- -> Result<ValidComponentAmalgamation<'a, UserAttribute>>
+ -> Result<ValidUserAttributeAmalgamation<'a>>
where T: Into<Option<std::time::SystemTime>>
{
let t = t.into().unwrap_or_else(std::time::SystemTime::now);
@@ -656,7 +656,7 @@ impl Cert {
}
/// Returns an iterator over the Cert's `UserAttributeBundle`s.
- pub fn user_attributes(&self) -> ComponentAmalgamationIter<UserAttribute> {
+ pub fn user_attributes(&self) -> UserAttributeAmalgamationIter {
ComponentAmalgamationIter::new(self, self.user_attributes.iter())
}
@@ -668,7 +668,7 @@ impl Cert {
}
/// Returns an iterator over the Cert's unknown components.
- pub fn unknowns(&self) -> ComponentAmalgamationIter<Unknown> {
+ pub fn unknowns(&self) -> UnknownComponentAmalgamationIter {
ComponentAmalgamationIter::new(self, self.unknowns.iter())
}
@@ -1475,14 +1475,13 @@ impl<'a> ValidCert<'a> {
}
/// Returns the amalgamated primary userid, if any.
- pub fn primary_userid(&self)
- -> Result<ValidComponentAmalgamation<'a, UserID>>
+ pub fn primary_userid(&self) -> Result<ValidUserIDAmalgamation<'a>>
{
self.cert.primary_userid(self.policy, self.time)
}
/// Returns an iterator over the Cert's userids.
- pub fn userids(&self) -> ValidComponentAmalgamationIter<UserID> {
+ pub fn userids(&self) -> ValidUserIDAmalgamationIter<'a> {
self.cert.userids().with_policy(self.policy, self.time)
}
@@ -1494,7 +1493,7 @@ impl<'a> ValidCert<'a> {
}
/// Returns an iterator over the Cert's `UserAttributeBundle`s.
- pub fn user_attributes(&self) -> ValidComponentAmalgamationIter<UserAttribute> {
+ pub fn user_attributes(&self) -> ValidUserAttributeAmalgamationIter<'a> {
self.cert.user_attributes().with_policy(self.policy, self.time)
}
diff --git a/openpgp/src/cert/prelude.rs b/openpgp/src/cert/prelude.rs
index 15e06129..6e29cfaf 100644
--- a/openpgp/src/cert/prelude.rs
+++ b/openpgp/src/cert/prelude.rs
@@ -36,6 +36,12 @@ pub use crate::cert::{
amalgamation::PrimaryKey as _,
amalgamation::PrimaryKeyAmalgamation,
amalgamation::SubordinateKeyAmalgamation,
+ amalgamation::UnknownComponentAmalgamation,
+ amalgamation::UnknownComponentAmalgamationIter,
+ amalgamation::UserAttributeAmalgamation,
+ amalgamation::UserAttributeAmalgamationIter,
+ amalgamation::UserIDAmalgamation,
+ amalgamation::UserIDAmalgamationIter,
amalgamation::ValidAmalgamation as _,
amalgamation::ValidComponentAmalgamation,
amalgamation::ValidComponentAmalgamationIter,
@@ -44,6 +50,12 @@ pub use crate::cert::{
amalgamation::ValidKeyAmalgamationIter,
amalgamation::ValidPrimaryKeyAmalgamation,
amalgamation::ValidSubordinateKeyAmalgamation,
+ amalgamation::ValidUnknownComponentAmalgamation,
+ amalgamation::ValidUnknownComponentAmalgamationIter,
+ amalgamation::ValidUserAttributeAmalgamation,
+ amalgamation::ValidUserAttributeAmalgamationIter,
+ amalgamation::ValidUserIDAmalgamation,
+ amalgamation::ValidUserIDAmalgamationIter,
amalgamation::ValidateAmalgamation as _,
bundle::ComponentBundle,
bundle::KeyBundle,