From 906a248f2a538650db0c41ec180c0ba4b1568ba6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 8 Dec 2020 16:50:44 +0100 Subject: openpgp: Make unnamed iterators Send + Sync. - See #615. --- openpgp/src/cert.rs | 9 ++++--- openpgp/src/cert/bundle.rs | 3 ++- openpgp/src/packet/mod.rs | 4 ++- openpgp/src/packet/signature/subpacket.rs | 44 ++++++++++++++++++++----------- openpgp/src/packet_pile.rs | 4 +-- openpgp/src/parse/map.rs | 2 +- openpgp/src/types/bitfield.rs | 3 ++- 7 files changed, 43 insertions(+), 26 deletions(-) diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 39a1f293..a184558e 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -1223,7 +1223,8 @@ impl Cert { /// # Ok(()) /// # } /// ``` - pub fn bad_signatures(&self) -> impl Iterator { + pub fn bad_signatures(&self) + -> impl Iterator + Send + Sync { self.bad.iter() } @@ -1313,9 +1314,9 @@ impl Cert { /// # Ok(()) /// # } /// ``` - pub fn into_packets(self) -> impl Iterator { - fn rewrite(mut p: impl Iterator) - -> impl Iterator + pub fn into_packets(self) -> impl Iterator + Send + Sync { + fn rewrite(mut p: impl Iterator + Send + Sync) + -> impl Iterator + Send + Sync { let k: Packet = match p.next().unwrap() { Packet::PublicKey(k) => { diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index fb5922f0..d755fe80 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -606,7 +606,8 @@ impl ComponentBundle { /// function uses the component's type (`C`) to determine the /// packet's type; the type is not a function of whether the key /// has secret key material. - pub(crate) fn into_packets<'a>(self) -> impl Iterator + pub(crate) fn into_packets<'a>(self) + -> impl Iterator + Send + Sync where Packet: From { let p : Packet = self.component.into(); diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 330ed9f4..45ef3d3c 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -708,7 +708,9 @@ impl<'a> Iter<'a> { /// ]); /// # Ok(()) } /// ``` - pub fn paths(self) -> impl Iterator, &'a Packet)> { + pub fn paths(self) + -> impl Iterator, &'a Packet)> + Send + Sync + { PacketPathIter { iter: self, path: None, diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index b7760de0..49271414 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -648,11 +648,13 @@ impl SubpacketArea { /// # Ok(()) /// # } /// ``` - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator + Send + Sync { self.packets.iter() } - pub(crate) fn iter_mut(&mut self) -> impl Iterator { + pub(crate) fn iter_mut(&mut self) + -> impl Iterator + Send + Sync + { self.packets.iter_mut() } @@ -820,13 +822,13 @@ impl SubpacketArea { /// # } /// ``` pub fn subpackets(&self, target: SubpacketTag) - -> impl Iterator + -> impl Iterator + Send + Sync { self.iter().filter(move |sp| sp.tag() == target) } pub(crate) fn subpackets_mut(&mut self, target: SubpacketTag) - -> impl Iterator + -> impl Iterator + Send + Sync { self.iter_mut().filter(move |sp| sp.tag() == target) } @@ -2104,7 +2106,7 @@ impl SubpacketAreas { /// hashed subpacket area. Thus, any instances of them in the /// unhashed area are ignored. pub fn subpackets(&self, tag: SubpacketTag) - -> impl Iterator + -> impl Iterator + Send + Sync { // It would be nice to do: // @@ -2132,7 +2134,7 @@ impl SubpacketAreas { } pub(crate) fn subpackets_mut(&mut self, tag: SubpacketTag) - -> impl Iterator + -> impl Iterator + Send + Sync { self.hashed_area.subpackets_mut(tag).chain( self.unhashed_area @@ -2733,7 +2735,8 @@ impl SubpacketAreas { /// /// This returns all instances of the Regular Expression subpacket /// in the hashed subpacket area. - pub fn regular_expressions(&self) -> impl Iterator { + pub fn regular_expressions(&self) -> impl Iterator + Send + Sync + { self.subpackets(SubpacketTag::RegularExpression).map(|sb| { match sb.value { SubpacketValue::RegularExpression(ref v) => &v[..], @@ -2800,7 +2803,8 @@ impl SubpacketAreas { /// /// This returns all instance of the Revocation Key subpacket in /// the hashed subpacket area. - pub fn revocation_keys(&self) -> impl Iterator + pub fn revocation_keys(&self) + -> impl Iterator + Send + Sync { self.subpackets(SubpacketTag::RevocationKey) .map(|sb| { @@ -2823,7 +2827,7 @@ impl SubpacketAreas { /// /// This returns all instances of the Issuer subpacket in both the /// hashed subpacket area and the unhashed subpacket area. - pub fn issuers(&self) -> impl Iterator { + pub fn issuers(&self) -> impl Iterator + Send + Sync { // 8-octet Key ID self.subpackets(SubpacketTag::Issuer) .map(|sb| { @@ -2847,7 +2851,8 @@ impl SubpacketAreas { /// This returns all instances of the Issuer Fingerprint subpacket /// in both the hashed subpacket area and the unhashed subpacket /// area. - pub fn issuer_fingerprints(&self) -> impl Iterator + pub fn issuer_fingerprints(&self) + -> impl Iterator + Send + Sync { // 1 octet key version number, N octets of fingerprint self.subpackets(SubpacketTag::IssuerFingerprint) @@ -2885,7 +2890,8 @@ impl SubpacketAreas { /// /// This returns all instances of the Notation Data subpacket in /// the hashed subpacket area. - pub fn notation_data(&self) -> impl Iterator + pub fn notation_data(&self) + -> impl Iterator + Send + Sync { self.subpackets(SubpacketTag::NotationData) .map(|sb| { @@ -2924,8 +2930,9 @@ impl SubpacketAreas { /// This returns the values of all instances of the Notation Data /// subpacket with the specified name in the hashed subpacket area. // name needs 'a, because the closure outlives the function call. - pub fn notation<'a, N>(&'a self, name: N) -> impl Iterator - where N: 'a + AsRef + pub fn notation<'a, N>(&'a self, name: N) + -> impl Iterator + Send + Sync + where N: 'a + AsRef + Send + Sync { self.notation_data() .filter_map(move |n| { @@ -3504,7 +3511,9 @@ impl SubpacketAreas { /// subpacket in the hashed subpacket area, the last one is /// returned. Otherwise, the last one is returned from the /// unhashed subpacket area. - pub fn embedded_signatures(&self) -> impl Iterator { + pub fn embedded_signatures(&self) + -> impl Iterator + Send + Sync + { self.subpackets(SubpacketTag::EmbeddedSignature).map(|sb| { if let SubpacketValue::EmbeddedSignature(v) = &sb.value { v @@ -3536,7 +3545,8 @@ impl SubpacketAreas { /// returned. Otherwise, the last one is returned from the /// unhashed subpacket area. pub fn embedded_signatures_mut(&mut self) - -> impl Iterator { + -> impl Iterator + Send + Sync + { self.subpackets_mut(SubpacketTag::EmbeddedSignature).map(|sb| { if let SubpacketValue::EmbeddedSignature(v) = &mut sb.value { v @@ -3576,7 +3586,9 @@ impl SubpacketAreas { /// /// This returns all instances of the Intended Recipient subpacket /// in the hashed subpacket area. - pub fn intended_recipients(&self) -> impl Iterator { + pub fn intended_recipients(&self) + -> impl Iterator + Send + Sync + { self.subpackets(SubpacketTag::IntendedRecipient) .map(|sb| { match sb.value() { diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 3d0bbe94..09a432b2 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -484,7 +484,7 @@ impl PacketPile { /// # } /// ``` pub fn children(&self) - -> impl Iterator + ExactSizeIterator + -> impl Iterator + ExactSizeIterator + Send + Sync { self.top_level.children().expect("toplevel is a container") } @@ -509,7 +509,7 @@ impl PacketPile { /// # } /// ``` pub fn into_children(self) - -> impl Iterator + ExactSizeIterator + -> impl Iterator + ExactSizeIterator + Send + Sync { self.top_level.into_children().expect("toplevel is a container") } diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index d584b16f..36fb42a9 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -91,7 +91,7 @@ impl Map { /// assert_eq!(map.iter().count(), 6); /// # Ok(()) } /// ``` - pub fn iter<'a>(&'a self) -> impl Iterator> { + pub fn iter<'a>(&'a self) -> impl Iterator> + Send + Sync { Iter::new(self) } } diff --git a/openpgp/src/types/bitfield.rs b/openpgp/src/types/bitfield.rs index d4a896bc..7de2311e 100644 --- a/openpgp/src/types/bitfield.rs +++ b/openpgp/src/types/bitfield.rs @@ -11,7 +11,8 @@ impl From> for Bitfield { } impl Bitfield { - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter<'a>(&'a self) -> impl Iterator + Send + Sync + 'a + { self.raw.iter() .flat_map(|b| { (0..8).into_iter().map(move |i| { -- cgit v1.2.3