summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-08-21 14:19:19 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-08-21 14:23:23 +0200
commit9dbaed96569e604027ae40d8cc84470db3967b71 (patch)
tree650794582f1efacce766cafbc40f315508570a3b /openpgp
parent79728f1cef0fe8a63d9137c5e0ca21cc33dc4f8b (diff)
openpgp: Add TPK::unknowns().
- See #245.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/serialize/tpk.rs8
-rw-r--r--openpgp/src/tpk/mod.rs33
2 files changed, 36 insertions, 5 deletions
diff --git a/openpgp/src/serialize/tpk.rs b/openpgp/src/serialize/tpk.rs
index ac296ce4..b429f578 100644
--- a/openpgp/src/serialize/tpk.rs
+++ b/openpgp/src/serialize/tpk.rs
@@ -123,7 +123,7 @@ impl TPK {
}
}
- for u in self.unknowns.iter() {
+ for u in self.unknowns() {
if export && ! u.certifications().iter().any(
|s| s.exportable_certification().unwrap_or(true))
{
@@ -224,7 +224,7 @@ impl SerializeInto for TPK {
}
}
- for u in self.unknowns.iter() {
+ for u in self.unknowns() {
l += PacketRef::Unknown(u.unknown()).serialized_len();
for s in u.self_revocations() {
@@ -460,7 +460,7 @@ impl<'a> TSK<'a> {
}
}
- for u in self.tpk.unknowns.iter() {
+ for u in self.tpk.unknowns() {
if export && ! u.certifications().iter().any(
|s| s.exportable_certification().unwrap_or(true))
{
@@ -594,7 +594,7 @@ impl<'a> SerializeInto for TSK<'a> {
}
}
- for u in self.tpk.unknowns.iter() {
+ for u in self.tpk.unknowns() {
l += PacketRef::Unknown(u.unknown()).serialized_len();
for s in u.self_revocations() {
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 40319bec..479da205 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -742,6 +742,31 @@ impl<'a> ExactSizeIterator for SubkeyBindingIter<'a> {
}
}
+/// An iterator over `UnknownBinding`s.
+pub struct UnknownBindingIter<'a> {
+ iter: Option<slice::Iter<'a, UnknownBinding>>,
+}
+
+impl<'a> Iterator for UnknownBindingIter<'a> {
+ type Item = &'a UnknownBinding;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ match self.iter {
+ Some(ref mut iter) => iter.next(),
+ None => None,
+ }
+ }
+}
+
+impl<'a> ExactSizeIterator for UnknownBindingIter<'a> {
+ fn len(&self) -> usize {
+ match self.iter {
+ Some(ref iter) => iter.len(),
+ None => 0,
+ }
+ }
+}
+
/// A transferable public key (TPK).
///
/// A TPK (see [RFC 4880, section 11.1]) can be used to verify
@@ -810,7 +835,6 @@ pub struct TPK {
// Unknown components, e.g., some UserAttribute++ packet from the
// future.
- pub(crate) // XXX for TSK::serialize()
unknowns: Vec<UnknownBinding>,
// Signatures that we couldn't find a place for.
pub(crate) // XXX for TSK::serialize()
@@ -1168,6 +1192,13 @@ impl TPK {
SubkeyBindingIter { iter: Some(self.subkeys.iter()) }
}
+ /// Returns an iterator over the TPK's valid unknown components.
+ ///
+ /// A valid `UnknownBinding` has at least one good self-signature.
+ pub fn unknowns(&self) -> UnknownBindingIter {
+ UnknownBindingIter { iter: Some(self.unknowns.iter()) }
+ }
+
/// Returns an iterator over the TPK's valid keys (live and
/// not-revoked).
///