diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-12-08 16:50:44 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-12-08 16:50:44 +0100 |
commit | 906a248f2a538650db0c41ec180c0ba4b1568ba6 (patch) | |
tree | a7a94b2ca42bd988af2d577cb88d59578afbd636 /openpgp/src | |
parent | e9439f7c4b902265d3f599c224e5e5ac9798014e (diff) |
openpgp: Make unnamed iterators Send + Sync.
- See #615.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/cert.rs | 9 | ||||
-rw-r--r-- | openpgp/src/cert/bundle.rs | 3 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 44 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 4 | ||||
-rw-r--r-- | openpgp/src/parse/map.rs | 2 | ||||
-rw-r--r-- | 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<Item = &Signature> { + pub fn bad_signatures(&self) + -> impl Iterator<Item = &Signature> + Send + Sync { self.bad.iter() } @@ -1313,9 +1314,9 @@ impl Cert { /// # Ok(()) /// # } /// ``` - pub fn into_packets(self) -> impl Iterator<Item=Packet> { - fn rewrite(mut p: impl Iterator<Item=Packet>) - -> impl Iterator<Item=Packet> + pub fn into_packets(self) -> impl Iterator<Item=Packet> + Send + Sync { + fn rewrite(mut p: impl Iterator<Item=Packet> + Send + Sync) + -> impl Iterator<Item=Packet> + 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<C> ComponentBundle<C> { /// 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<Item=Packet> + pub(crate) fn into_packets<'a>(self) + -> impl Iterator<Item=Packet> + Send + Sync where Packet: From<C> { 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<Item = (Vec<usize>, &'a Packet)> { + pub fn paths(self) + -> impl Iterator<Item = (Vec<usize>, &'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<Item = &Subpacket> { + pub fn iter(&self) -> impl Iterator<Item = &Subpacket> + Send + Sync { self.packets.iter() } - pub(crate) fn iter_mut(&mut self) -> impl Iterator<Item = &mut Subpacket> { + pub(crate) fn iter_mut(&mut self) + -> impl Iterator<Item = &mut Subpacket> + Send + Sync + { self.packets.iter_mut() } @@ -820,13 +822,13 @@ impl SubpacketArea { /// # } /// ``` pub fn subpackets(&self, target: SubpacketTag) - -> impl Iterator<Item = &Subpacket> + -> impl Iterator<Item = &Subpacket> + Send + Sync { self.iter().filter(move |sp| sp.tag() == target) } pub(crate) fn subpackets_mut(&mut self, target: SubpacketTag) - -> impl Iterator<Item = &mut Subpacket> + -> impl Iterator<Item = &mut Subpacket> + 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<Item = &Subpacket> + -> impl Iterator<Item = &Subpacket> + 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<Item = &mut Subpacket> + -> impl Iterator<Item = &mut Subpacket> + 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<Item=&[u8]> { + pub fn regular_expressions(&self) -> impl Iterator<Item=&[u8]> + 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<Item=&RevocationKey> + pub fn revocation_keys(&self) + -> impl Iterator<Item=&RevocationKey> + 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<Item=&KeyID> { + pub fn issuers(&self) -> impl Iterator<Item=&KeyID> + 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<Item=&Fingerprint> + pub fn issuer_fingerprints(&self) + -> impl Iterator<Item=&Fingerprint> + 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<Item=&NotationData> + pub fn notation_data(&self) + -> impl Iterator<Item=&NotationData> + 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<Item=&'a [u8]> - where N: 'a + AsRef<str> + pub fn notation<'a, N>(&'a self, name: N) + -> impl Iterator<Item=&'a [u8]> + Send + Sync + where N: 'a + AsRef<str> + 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<Item = &Signature> { + pub fn embedded_signatures(&self) + -> impl Iterator<Item = &Signature> + 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<Item = &mut Signature> { + -> impl Iterator<Item = &mut Signature> + 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<Item=&Fingerprint> { + pub fn intended_recipients(&self) + -> impl Iterator<Item=&Fingerprint> + 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<Item=&Packet> + ExactSizeIterator + -> impl Iterator<Item=&Packet> + 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<Item=Packet> + ExactSizeIterator + -> impl Iterator<Item=Packet> + 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<Item = Field<'a>> { + pub fn iter<'a>(&'a self) -> impl Iterator<Item = Field<'a>> + 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<Vec<u8>> for Bitfield { } impl Bitfield { - pub fn iter<'a>(&'a self) -> impl Iterator<Item = usize> + 'a { + pub fn iter<'a>(&'a self) -> impl Iterator<Item = usize> + Send + Sync + 'a + { self.raw.iter() .flat_map(|b| { (0..8).into_iter().map(move |i| { |