summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-02-26 21:38:26 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-02-26 21:46:53 +0100
commit0e47134c4ed82e109f7045efe380a35ae9770bc3 (patch)
tree50942619f947b0a688b8983ef528c53076b179b8
parent4e2a005d85e9055d0846dcf7901ea6f76f9f2de4 (diff)
openpgp: Fix lifetime.
- The reference returned by `ComponentAmalgamation::userid` and `ComponentAmalgamation::user_attribute` is bound by the reference to the `Component` in the `ComponentAmalgamation`, not the `ComponentAmalgamation` itself. - This matters, for instance, for: cert.userids().map(|ua| ua.userid())
-rw-r--r--openpgp/src/cert/amalgamation.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs
index be5bf5dc..0a07018a 100644
--- a/openpgp/src/cert/amalgamation.rs
+++ b/openpgp/src/cert/amalgamation.rs
@@ -289,14 +289,14 @@ impl<'a, C> ComponentAmalgamation<'a, C> {
impl<'a> ComponentAmalgamation<'a, crate::packet::UserID> {
/// Returns a reference to the User ID.
- pub fn userid(&self) -> &crate::packet::UserID {
+ pub fn userid(&self) -> &'a crate::packet::UserID {
self.bundle().userid()
}
}
impl<'a> ComponentAmalgamation<'a, crate::packet::UserAttribute> {
/// Returns a reference to the User Attribute.
- pub fn user_attribute(&self) -> &crate::packet::UserAttribute {
+ pub fn user_attribute(&self) -> &'a crate::packet::UserAttribute {
self.bundle().user_attribute()
}
}
@@ -529,4 +529,23 @@ mod test {
assert_eq!(userid.userid(), c.userid());
assert_eq!(userid.time(), c.time());
}
+
+ #[test]
+ fn map() {
+ // The reference returned by `ComponentAmalgamation::userid`
+ // and `ComponentAmalgamation::user_attribute` is bound by the
+ // reference to the `Component` in the
+ // `ComponentAmalgamation`, not the `ComponentAmalgamation`
+ // itself.
+ let (cert, _) = CertBuilder::new()
+ .add_userid("test@example.example")
+ .generate()
+ .unwrap();
+
+ let _ = cert.userids().map(|ua| ua.userid())
+ .collect::<Vec<_>>();
+
+ let _ = cert.user_attributes().map(|ua| ua.user_attribute())
+ .collect::<Vec<_>>();
+ }
}