From 405e43ee06d69e3dd19f6f5116ff0c46f3076de6 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 4 Dec 2020 20:06:17 +0100 Subject: openpgp: Ensure public types are Send and Sync. - See #627. --- openpgp/src/armor.rs | 4 +++ openpgp/src/cert.rs | 8 ++---- openpgp/src/cert/amalgamation.rs | 1 + openpgp/src/cert/amalgamation/iter.rs | 1 + openpgp/src/cert/builder.rs | 9 +++---- openpgp/src/cert/bundle.rs | 1 + openpgp/src/cert/revoke.rs | 4 +++ openpgp/src/crypto/aead.rs | 2 ++ openpgp/src/crypto/asymmetric.rs | 1 + openpgp/src/crypto/mem.rs | 1 + openpgp/src/crypto/mod.rs | 2 ++ openpgp/src/crypto/mpi.rs | 7 +++++ openpgp/src/crypto/s2k.rs | 1 + openpgp/src/fingerprint.rs | 8 +----- openpgp/src/fmt.rs | 2 ++ openpgp/src/keyhandle.rs | 8 +----- openpgp/src/keyid.rs | 7 +---- openpgp/src/lib.rs | 6 +---- openpgp/src/macros.rs | 42 ++++++++++++++++++++++++++++++ openpgp/src/message/mod.rs | 8 ++---- openpgp/src/packet/aed.rs | 1 + openpgp/src/packet/compressed_data.rs | 1 + openpgp/src/packet/container.rs | 4 +++ openpgp/src/packet/header/ctb.rs | 4 +++ openpgp/src/packet/header/mod.rs | 2 ++ openpgp/src/packet/key.rs | 20 ++++++++++++++ openpgp/src/packet/literal.rs | 1 + openpgp/src/packet/marker.rs | 1 + openpgp/src/packet/mod.rs | 16 +++++++----- openpgp/src/packet/one_pass_sig.rs | 1 + openpgp/src/packet/pkesk.rs | 2 ++ openpgp/src/packet/seip.rs | 2 ++ openpgp/src/packet/signature.rs | 3 +++ openpgp/src/packet/signature/subpacket.rs | 7 +++++ openpgp/src/packet/tag.rs | 1 + openpgp/src/packet/trust.rs | 2 ++ openpgp/src/packet/unknown.rs | 2 ++ openpgp/src/packet/user_attribute.rs | 4 +++ openpgp/src/packet/userid.rs | 2 ++ openpgp/src/packet_pile.rs | 8 ++---- openpgp/src/parse/map.rs | 2 ++ openpgp/src/parse/packet_parser_builder.rs | 3 ++- openpgp/src/policy.rs | 4 +++ openpgp/src/serialize/stream.rs | 1 + openpgp/src/types/compression_level.rs | 1 + openpgp/src/types/features.rs | 1 + openpgp/src/types/key_flags.rs | 1 + openpgp/src/types/mod.rs | 3 +++ openpgp/src/types/server_preferences.rs | 1 + openpgp/src/types/timestamp.rs | 2 ++ 50 files changed, 170 insertions(+), 56 deletions(-) diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 9ff4c538..e901cc1b 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -72,6 +72,8 @@ pub enum Kind { File, } +assert_send_and_sync!{Kind} + #[cfg(test)] impl Arbitrary for Kind { fn arbitrary(g: &mut G) -> Self { @@ -172,6 +174,8 @@ pub struct Writer { dirty: bool, } +assert_send_and_sync!{Writer>} + impl Writer { /// Constructs a new filter for the given type of data. /// diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index bc274021..7492cf04 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -726,6 +726,8 @@ pub struct Cert { } } // doc-hack, see above +assert_send_and_sync!{Cert} + impl std::str::FromStr for Cert { type Err = anyhow::Error; @@ -4882,12 +4884,6 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= assert!(Cert::from_bytes(&keyring).is_err()); } - #[test] - fn cert_is_send_and_sync() { - fn f(_: T) {} - f(Cert::from_bytes(crate::tests::key("testy-new.pgp")).unwrap()); - } - #[test] fn primary_userid() { // 'really-revoked-userid' has two user ids. One of them is diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index bfd634ef..9980784b 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -647,6 +647,7 @@ pub struct ComponentAmalgamation<'a, C> { cert: &'a Cert, bundle: &'a ComponentBundle, } +assert_send_and_sync!{ComponentAmalgamation<'a, UserID>, 'a} /// A User ID and its associated data. /// diff --git a/openpgp/src/cert/amalgamation/iter.rs b/openpgp/src/cert/amalgamation/iter.rs index b35bd48e..7af884d3 100644 --- a/openpgp/src/cert/amalgamation/iter.rs +++ b/openpgp/src/cert/amalgamation/iter.rs @@ -90,6 +90,7 @@ pub struct ComponentAmalgamationIter<'a, C> { cert: &'a Cert, iter: slice::Iter<'a, ComponentBundle>, } +assert_send_and_sync!{ComponentAmalgamationIter<'a, UserID>, 'a} /// An iterator over `UserIDAmalgamtion`s. /// diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 660b9cfa..b84f02df 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -65,6 +65,7 @@ pub enum CipherSuite { /// 4096 bit RSA with SHA512 and AES256 RSA4k, } +assert_send_and_sync!{CipherSuite} impl Default for CipherSuite { fn default() -> Self { @@ -133,6 +134,7 @@ pub struct KeyBlueprint { // CertBuilder::ciphersuite. ciphersuite: Option, } +assert_send_and_sync!{KeyBlueprint} /// Simplifies the generation of OpenPGP certificates. /// @@ -173,6 +175,7 @@ pub struct CertBuilder<'a> { revocation_keys: Option>, phantom: PhantomData<&'a ()>, } +assert_send_and_sync!{CertBuilder<'a>, 'a} impl CertBuilder<'_> { /// Returns a new `CertBuilder`. @@ -1432,10 +1435,4 @@ mod tests { revokers.iter().collect::>()); Ok(()) } - - #[test] - fn cert_builder_is_send_and_sync() { - fn f(_: T) {} - f(CertBuilder::new().generate().unwrap()); - } } diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index 798a82c8..d8944777 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -125,6 +125,7 @@ pub struct ComponentBundle { // Third-party revocations (e.g., designated revokers). pub(crate) other_revocations: Vec, } +assert_send_and_sync!{ComponentBundle} /// A key (primary or subkey, public or private) and any associated /// signatures. diff --git a/openpgp/src/cert/revoke.rs b/openpgp/src/cert/revoke.rs index a77e8885..24fdb55b 100644 --- a/openpgp/src/cert/revoke.rs +++ b/openpgp/src/cert/revoke.rs @@ -81,6 +81,7 @@ use crate::cert::prelude::*; pub struct CertRevocationBuilder { builder: signature::SignatureBuilder, } +assert_send_and_sync!{CertRevocationBuilder} impl CertRevocationBuilder { /// Returns a new `CertRevocationBuilder`. @@ -318,6 +319,7 @@ impl Deref for CertRevocationBuilder { pub struct SubkeyRevocationBuilder { builder: signature::SignatureBuilder, } +assert_send_and_sync!{SubkeyRevocationBuilder} impl SubkeyRevocationBuilder { /// Returns a new `SubkeyRevocationBuilder`. @@ -549,6 +551,7 @@ impl Deref for SubkeyRevocationBuilder { pub struct UserIDRevocationBuilder { builder: signature::SignatureBuilder, } +assert_send_and_sync!{UserIDRevocationBuilder} impl UserIDRevocationBuilder { /// Returns a new `UserIDRevocationBuilder`. @@ -794,6 +797,7 @@ impl Deref for UserIDRevocationBuilder { pub struct UserAttributeRevocationBuilder { builder: signature::SignatureBuilder, } +assert_send_and_sync!{UserAttributeRevocationBuilder} impl UserAttributeRevocationBuilder { /// Returns a new `UserAttributeRevocationBuilder`. diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index ac658046..d98c8a53 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -116,6 +116,7 @@ pub struct Decryptor<'a> { buffer: Vec, } + impl<'a> Decryptor<'a> { /// Instantiate a new AEAD decryptor. /// @@ -543,6 +544,7 @@ pub struct Encryptor { // A place to write encrypted data into. scratch: Vec, } +assert_send_and_sync!{Encryptor>} impl Encryptor { /// Instantiate a new AEAD encryptor. diff --git a/openpgp/src/crypto/asymmetric.rs b/openpgp/src/crypto/asymmetric.rs index 1934f3be..39440408 100644 --- a/openpgp/src/crypto/asymmetric.rs +++ b/openpgp/src/crypto/asymmetric.rs @@ -126,6 +126,7 @@ pub struct KeyPair { public: Key, secret: packet::key::Unencrypted, } +assert_send_and_sync!{KeyPair} impl KeyPair { /// Creates a new key pair. diff --git a/openpgp/src/crypto/mem.rs b/openpgp/src/crypto/mem.rs index 96f80483..330ca0b5 100644 --- a/openpgp/src/crypto/mem.rs +++ b/openpgp/src/crypto/mem.rs @@ -218,6 +218,7 @@ pub struct Encrypted { ciphertext: Protected, iv: Protected, } +assert_send_and_sync!{Encrypted} impl PartialEq for Encrypted { fn eq(&self, other: &Self) -> bool { diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs index 2177d327..5193fcca 100644 --- a/openpgp/src/crypto/mod.rs +++ b/openpgp/src/crypto/mod.rs @@ -48,6 +48,7 @@ pub(crate) mod symmetric; /// [`From`]: https://doc.rust-lang.org/std/convert/trait.From.html #[derive(Clone, PartialEq, Eq)] pub struct SessionKey(mem::Protected); +assert_send_and_sync!{SessionKey} impl SessionKey { /// Creates a new session key. @@ -170,6 +171,7 @@ impl fmt::Debug for SessionKey { /// ``` #[derive(Clone, PartialEq, Eq)] pub struct Password(mem::Encrypted); +assert_send_and_sync!{Password} impl From> for Password { fn from(v: Vec) -> Self { diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index 8f9cfb2a..2c381f71 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -42,6 +42,7 @@ pub struct MPI { /// Integer value as big-endian with leading zeros stripped. value: Box<[u8]>, } +assert_send_and_sync!{MPI} impl From> for MPI { fn from(v: Vec) -> Self { @@ -295,6 +296,7 @@ pub struct ProtectedMPI { /// Integer value as big-endian. value: Protected, } +assert_send_and_sync!{ProtectedMPI} impl From> for ProtectedMPI { fn from(m: Vec) -> Self { @@ -503,6 +505,7 @@ pub enum PublicKey { rest: Box<[u8]>, }, } +assert_send_and_sync!{PublicKey} impl PublicKey { /// Returns the length of the public key in bits. @@ -662,6 +665,7 @@ pub enum SecretKeyMaterial { rest: Protected, }, } +assert_send_and_sync!{SecretKeyMaterial} impl fmt::Debug for SecretKeyMaterial { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -861,6 +865,7 @@ pub enum SecretKeyChecksum { /// Sum of the decrypted secret key octets modulo 65536. Sum16, } +assert_send_and_sync!{SecretKeyChecksum} impl Default for SecretKeyChecksum { fn default() -> Self { @@ -910,6 +915,7 @@ pub enum Ciphertext { rest: Box<[u8]>, }, } +assert_send_and_sync!{Ciphertext} impl Ciphertext { /// Returns, if known, the public-key algorithm for this @@ -1019,6 +1025,7 @@ pub enum Signature { rest: Box<[u8]>, }, } +assert_send_and_sync!{Signature} impl Hash for Signature { fn hash(&self, hash: &mut hash::Context) { diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index ecc6313e..a282c402 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -113,6 +113,7 @@ pub enum S2K { parameters: Option>, }, } +assert_send_and_sync!{S2K} impl Default for S2K { fn default() -> Self { diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index 3af4a70e..bd6d0ffe 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -53,6 +53,7 @@ pub enum Fingerprint { /// V3 fingerprint (deprecated) or otherwise wrong-length data. Invalid(Box<[u8]>), } +assert_send_and_sync!{Fingerprint} impl fmt::Display for Fingerprint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -331,11 +332,4 @@ mod tests { assert_eq!(format!("{:X}", fp), "0123456789ABCDEF0123456789ABCDEF01234567"); assert_eq!(format!("{:x}", fp), "0123456789abcdef0123456789abcdef01234567"); } - - #[test] - fn fingerprint_is_send_and_sync() { - fn f(_: T) {} - f("0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567" - .parse::().unwrap()); - } } diff --git a/openpgp/src/fmt.rs b/openpgp/src/fmt.rs index d36217d2..c06c6faf 100644 --- a/openpgp/src/fmt.rs +++ b/openpgp/src/fmt.rs @@ -61,6 +61,8 @@ pub mod hex { offset: usize, } + assert_send_and_sync!{Dumper>} + impl Dumper { /// Creates a new dumper. /// diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs index cfa78f3a..2eb8bb94 100644 --- a/openpgp/src/keyhandle.rs +++ b/openpgp/src/keyhandle.rs @@ -79,6 +79,7 @@ pub enum KeyHandle { /// A KeyID. KeyID(KeyID), } +assert_send_and_sync!{KeyHandle} impl std::fmt::Display for KeyHandle { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -313,11 +314,4 @@ mod tests { let handle = KeyHandle::KeyID(KeyID::Invalid(Box::new([10, 2]))); assert_eq!(format!("{:x}", handle), "0a02"); } - - #[test] - fn key_handle_is_send_and_sync() { - fn f(_: T) {} - f(KeyHandle::from("0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567" - .parse::().unwrap())); - } } diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 973b059e..3e7f38cc 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -65,6 +65,7 @@ pub enum KeyID { /// e.g. wrong number of bytes. Invalid(Box<[u8]>), } +assert_send_and_sync!{KeyID} impl fmt::Display for KeyID { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -412,10 +413,4 @@ mod test { assert_eq!(format!("{:X}", keyid), "FB3751F1587DAEF1"); assert_eq!(format!("{:x}", keyid), "fb3751f1587daef1"); } - - #[test] - fn keyid_is_send_and_sync() { - fn f(_: T) {} - f("89AB CDEF 0123 4567".parse::().unwrap()); - } } diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 4dc01d06..a0b5c642 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -303,8 +303,4 @@ pub enum Error { PolicyViolation(String, Option), } -#[test] -fn error_is_send_and_sync() { - fn f(_: T) {} - f(Error::IndexOutOfRange); -} +assert_send_and_sync!{Error} diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs index 822312f2..7bc93b01 100644 --- a/openpgp/src/macros.rs +++ b/openpgp/src/macros.rs @@ -108,3 +108,45 @@ macro_rules! time_it { time_it!("", $body) }; } + +/// A simple shortcut for ensuring a type is send and sync. +/// +/// For most types just call it after defining the type: +/// +/// ``` +/// pub struct MyStruct {} +/// assert_send_and_sync!{MyStruct} +/// ``` +/// +/// For types with lifetimes, specify the lifetime as a second argument: +/// +/// ``` +/// pub struct WithLifetime<'a> {} +/// assert_send_and_sync!{MyStruct, 'a} +/// ``` +/// +/// For types generic over other types, call it with a concrete type: +/// +/// ``` +/// pub struct MyWriter {} +/// assert_send_and_sync!{MyWriterStruct>} +/// ``` +/// +/// You can also combine the two: +/// +/// ``` +/// pub struct MyWriterWithLifetime {} +/// assert_send_and_sync!{MyWriterStruct>, a'} +/// ``` +/// +macro_rules! assert_send_and_sync { + ( $x:ty, $l:lifetime ) => { + impl<$l> crate::types::Sendable for $x {} + impl<$l> crate::types::Syncable for $x {} + }; + ( $x:ty ) => { + impl crate::types::Sendable for $x {} + impl crate::types::Syncable for $x {} + }; +} + diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 5b35f161..587a7e59 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -56,6 +56,7 @@ pub enum MessageParserError { /// An OpenPGP error. OpenPGP(Error), } +assert_send_and_sync!{MessageParserError} impl From for anyhow::Error { fn from(err: MessageParserError) -> Self { @@ -346,6 +347,7 @@ pub struct Message { pub(super) pile: PacketPile, } } // doc-hack, see above +assert_send_and_sync!{Message} impl fmt::Debug for Message { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -1192,12 +1194,6 @@ mod tests { assert!(message.is_ok(), "{:#?}", message); } - #[test] - fn message_is_send_and_sync() { - fn f(_: T) {} - f(Message::try_from(vec![])); - } - #[test] fn basic_message_validator() { use crate::message::{MessageValidator, MessageValidity, Token}; diff --git a/openpgp/src/packet/aed.rs b/openpgp/src/packet/aed.rs index b7f6e58c..de44d2fd 100644 --- a/openpgp/src/packet/aed.rs +++ b/openpgp/src/packet/aed.rs @@ -124,6 +124,7 @@ pub struct AED1 { /// This is a container packet. container: packet::Container, } +assert_send_and_sync!{AED1} impl std::ops::Deref for AED1 { type Target = packet::Container; diff --git a/openpgp/src/packet/compressed_data.rs b/openpgp/src/packet/compressed_data.rs index bc673890..cbf94b51 100644 --- a/openpgp/src/packet/compressed_data.rs +++ b/openpgp/src/packet/compressed_data.rs @@ -29,6 +29,7 @@ pub struct CompressedData { /// This is a container packet. container: packet::Container, } +assert_send_and_sync!{CompressedData} impl std::ops::Deref for CompressedData { type Target = packet::Container; diff --git a/openpgp/src/packet/container.rs b/openpgp/src/packet/container.rs index a06d84cc..e54b8a3c 100644 --- a/openpgp/src/packet/container.rs +++ b/openpgp/src/packet/container.rs @@ -95,6 +95,8 @@ pub enum Body { Structured(Vec), } +assert_send_and_sync!{Body} + /// Holds packet bodies. /// /// This is used by OpenPGP container packets, like the compressed @@ -108,6 +110,8 @@ pub struct Container { body_digest: Vec, } +assert_send_and_sync!{Container} + impl std::ops::Deref for Container { type Target = Body; fn deref(&self) -> &Self::Target { diff --git a/openpgp/src/packet/header/ctb.rs b/openpgp/src/packet/header/ctb.rs index fb423436..8dc2e949 100644 --- a/openpgp/src/packet/header/ctb.rs +++ b/openpgp/src/packet/header/ctb.rs @@ -39,6 +39,7 @@ pub struct CTBNew { /// Packet CTB fields common: CTBCommon, } +assert_send_and_sync!{CTBNew} impl CTBNew { /// Constructs a new-style CTB. @@ -90,6 +91,7 @@ pub enum PacketLengthType { /// from the context, e.g., EOF. Indeterminate, } +assert_send_and_sync!{PacketLengthType} impl TryFrom for PacketLengthType { type Error = anyhow::Error; @@ -129,6 +131,7 @@ pub struct CTBOld { /// Type of length specifier. length_type: PacketLengthType, } +assert_send_and_sync!{CTBOld} impl CTBOld { /// Constructs an old-style CTB. @@ -204,6 +207,7 @@ pub enum CTB { /// Old PGP 2.6 header format. Old(CTBOld), } +assert_send_and_sync!{CTB} impl CTB { /// Constructs a new-style CTB. diff --git a/openpgp/src/packet/header/mod.rs b/openpgp/src/packet/header/mod.rs index 95f2986b..8f455b1c 100644 --- a/openpgp/src/packet/header/mod.rs +++ b/openpgp/src/packet/header/mod.rs @@ -38,6 +38,7 @@ pub struct Header { /// The packet's length. length: BodyLength, } +assert_send_and_sync!{Header} impl Header { /// Creates a new header. @@ -245,3 +246,4 @@ pub enum BodyLength { /// This type is only used with old format packets. Indeterminate, } +assert_send_and_sync!{BodyLength} diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 34fbedc0..846cf045 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -441,6 +441,8 @@ pub trait KeyRole: fmt::Debug + seal::Sealed { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct PublicParts; +assert_send_and_sync!{PublicParts} + impl seal::Sealed for PublicParts {} impl KeyParts for PublicParts { fn convert_key(key: Key) @@ -492,6 +494,8 @@ impl KeyParts for PublicParts { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct SecretParts; +assert_send_and_sync!{SecretParts} + impl seal::Sealed for SecretParts {} impl KeyParts for SecretParts { fn convert_key(key: Key) @@ -551,6 +555,8 @@ impl KeyParts for SecretParts { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct UnspecifiedParts; +assert_send_and_sync!{UnspecifiedParts} + impl seal::Sealed for UnspecifiedParts {} impl KeyParts for UnspecifiedParts { fn convert_key(key: Key) @@ -594,6 +600,8 @@ impl KeyParts for UnspecifiedParts { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct PrimaryRole; +assert_send_and_sync!{PrimaryRole} + impl seal::Sealed for PrimaryRole {} impl KeyRole for PrimaryRole { fn convert_key(key: Key) @@ -626,6 +634,8 @@ impl KeyRole for PrimaryRole { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct SubordinateRole; +assert_send_and_sync!{SubordinateRole} + impl seal::Sealed for SubordinateRole {} impl KeyRole for SubordinateRole { fn convert_key(key: Key) @@ -664,6 +674,8 @@ impl KeyRole for SubordinateRole { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct UnspecifiedRole; +assert_send_and_sync!{UnspecifiedRole} + impl seal::Sealed for UnspecifiedRole {} impl KeyRole for UnspecifiedRole { fn convert_key(key: Key) @@ -770,6 +782,8 @@ pub struct Key4 r: std::marker::PhantomData, } +assert_send_and_sync!{Key4} + impl PartialEq for Key4 { fn eq(&self, other: &Key4) -> bool { self.creation_time == other.creation_time @@ -1222,6 +1236,8 @@ pub enum SecretKeyMaterial { Encrypted(Encrypted), } +assert_send_and_sync!{SecretKeyMaterial} + impl From for SecretKeyMaterial { fn from(mpis: mpi::SecretKeyMaterial) -> Self { SecretKeyMaterial::Unencrypted(mpis.into()) @@ -1348,6 +1364,8 @@ pub struct Unencrypted { mpis: mem::Encrypted, } +assert_send_and_sync!{Unencrypted} + impl From for Unencrypted { fn from(mpis: mpi::SecretKeyMaterial) -> Self { use crate::serialize::Marshal; @@ -1433,6 +1451,8 @@ pub struct Encrypted { Box<[u8]>>, // S2K body + IV + ciphertext. } +assert_send_and_sync!{Encrypted} + // Because the S2K and ciphertext cannot be cleanly separated at parse // time, we need to carefully compare and hash encrypted key packets. diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs index f9865fbc..acf388c0 100644 --- a/openpgp/src/packet/literal.rs +++ b/openpgp/src/packet/literal.rs @@ -47,6 +47,7 @@ pub struct Literal { /// if `buffer_unread_content` is used. container: packet::Container, } +assert_send_and_sync!{Literal} impl fmt::Debug for Literal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/packet/marker.rs b/openpgp/src/packet/marker.rs index ecd50dbe..98d5557c 100644 --- a/openpgp/src/packet/marker.rs +++ b/openpgp/src/packet/marker.rs @@ -16,6 +16,7 @@ pub struct Marker { /// CTB packet header fields. pub(crate) common: packet::Common, } +assert_send_and_sync!{Marker} impl Marker { pub(crate) const BODY: &'static [u8] = &[0x50, 0x47, 0x50]; diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 93538a7e..62123105 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -284,6 +284,7 @@ pub enum Packet { AED(AED), } } // doc-hack, see above +assert_send_and_sync!{Packet} macro_rules! impl_into_iterator { ($t:ty) => { @@ -519,6 +520,7 @@ pub struct Common { /// this structure actually gains some fields. dummy: std::marker::PhantomData<()>, } +assert_send_and_sync!{Common} #[cfg(test)] impl Arbitrary for Common { @@ -597,6 +599,7 @@ pub struct Iter<'a> { // `paths` iter. depth: usize, } +assert_send_and_sync!{Iter<'a>, 'a} impl<'a> Default for Iter<'a> { fn default() -> Self { @@ -917,6 +920,7 @@ pub enum Signature { /// Signature packet version 4. V4(self::signature::Signature4), } +assert_send_and_sync!{Signature} impl Signature { /// Gets the version. @@ -974,6 +978,7 @@ pub enum OnePassSig { /// OnePassSig packet version 3. V3(self::one_pass_sig::OnePassSig3), } +assert_send_and_sync!{OnePassSig} impl OnePassSig { /// Gets the version. @@ -1035,6 +1040,7 @@ pub enum PKESK { /// PKESK packet version 3. V3(self::pkesk::PKESK3), } +assert_send_and_sync!{PKESK} impl PKESK { /// Gets the version. @@ -1100,6 +1106,7 @@ pub enum SKESK { /// This feature is [experimental](../index.html#experimental-features). V5(self::skesk::SKESK5), } +assert_send_and_sync!{SKESK} impl SKESK { /// Gets the version. @@ -1431,6 +1438,7 @@ pub enum Key { /// A version 4 `Key` packet. V4(Key4), } +assert_send_and_sync!{Key} impl fmt::Display for Key { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -1810,6 +1818,7 @@ pub enum SEIP { /// SEIP packet version 1. V1(self::seip::SEIP1), } +assert_send_and_sync!{SEIP} impl SEIP { /// Gets the version. @@ -1871,6 +1880,7 @@ pub enum AED { /// AED packet version 1. V1(self::aed::AED1), } +assert_send_and_sync!{AED} impl AED { /// Gets the version. @@ -1913,12 +1923,6 @@ mod test { use crate::serialize::SerializeInto; use crate::parse::Parse; - #[test] - fn packet_is_send_and_sync() { - fn f(_: T) {} - f(Packet::Marker(Default::default())); - } - quickcheck! { fn roundtrip(p: Packet) -> bool { let buf = p.to_vec().expect("Failed to serialize packet"); diff --git a/openpgp/src/packet/one_pass_sig.rs b/openpgp/src/packet/one_pass_sig.rs index 281747e1..ef5123e1 100644 --- a/openpgp/src/packet/one_pass_sig.rs +++ b/openpgp/src/packet/one_pass_sig.rs @@ -47,6 +47,7 @@ pub struct OnePassSig3 { /// is nested. last: u8, } +assert_send_and_sync!{OnePassSig3} impl fmt::Debug for OnePassSig3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index 5ea6ff66..59c2a459 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -41,6 +41,8 @@ pub struct PKESK3 { esk: Ciphertext, } +assert_send_and_sync!{PKESK3} + impl PKESK3 { /// Creates a new PKESK3 packet. pub fn new(recipient: KeyID, pk_algo: PublicKeyAlgorithm, diff --git a/openpgp/src/packet/seip.rs b/openpgp/src/packet/seip.rs index b71937ae..4263e6ae 100644 --- a/openpgp/src/packet/seip.rs +++ b/openpgp/src/packet/seip.rs @@ -31,6 +31,8 @@ pub struct SEIP1 { container: packet::Container, } +assert_send_and_sync!{SEIP1} + impl std::ops::Deref for SEIP1 { type Target = packet::Container; fn deref(&self) -> &Self::Target { diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index ff952c7b..321200e4 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -223,6 +223,7 @@ pub struct SignatureFields { /// Subpackets. subpackets: SubpacketAreas, } +assert_send_and_sync!{SignatureFields} #[cfg(test)] impl ArbitraryBounded for SignatureFields { @@ -452,6 +453,7 @@ pub struct SignatureBuilder { original_creation_time: Option, fields: SignatureFields, } +assert_send_and_sync!{SignatureBuilder} impl Deref for SignatureBuilder { type Target = SignatureFields; @@ -1688,6 +1690,7 @@ pub struct Signature4 { /// verification is usually expected to be idempotent. additional_issuers: Vec, } +assert_send_and_sync!{Signature4} impl fmt::Debug for Signature4 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index e747bd05..672d6a57 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -324,6 +324,7 @@ pub enum SubpacketTag { /// Unknown subpacket tag. Unknown(u8), } +assert_send_and_sync!{SubpacketTag} impl fmt::Display for SubpacketTag { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -500,6 +501,7 @@ pub struct SubpacketArea { // This is an option, because we parse the subpacket area lazily. parsed: Mutex>>>, } +assert_send_and_sync!{SubpacketArea} #[cfg(test)] impl ArbitraryBounded for SubpacketArea { @@ -1075,6 +1077,7 @@ pub struct NotationData { name: String, value: Vec, } +assert_send_and_sync!{NotationData} #[cfg(test)] impl Arbitrary for NotationData { @@ -1120,6 +1123,7 @@ impl NotationData { /// Flags for the Notation Data subpacket. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct NotationDataFlags(crate::types::Bitfield); +assert_send_and_sync!{NotationDataFlags} #[cfg(test)] impl Arbitrary for NotationDataFlags { @@ -1515,6 +1519,7 @@ pub enum SubpacketValue { /// [Section 5.2.3.29 of RFC 4880bis]: https://www.ietf.org/id/draft-ietf-openpgp-rfc4880bis-09.html#section-5.2.3.29 IntendedRecipient(Fingerprint), } +assert_send_and_sync!{SubpacketValue} #[cfg(test)] impl ArbitraryBounded for SubpacketValue { @@ -1673,6 +1678,7 @@ pub struct Subpacket { /// authenticated in the context of its signature. authenticated: bool, } +assert_send_and_sync!{Subpacket} impl PartialEq for Subpacket { fn eq(&self, other: &Subpacket) -> bool { @@ -1956,6 +1962,7 @@ pub struct SubpacketAreas { /// Subpackets that are _not_ part of the signature. unhashed_area: SubpacketArea, } +assert_send_and_sync!{SubpacketAreas} #[cfg(test)] impl ArbitraryBounded for SubpacketAreas { diff --git a/openpgp/src/packet/tag.rs b/openpgp/src/packet/tag.rs index 7ea8c2c0..b08fd9c8 100644 --- a/openpgp/src/packet/tag.rs +++ b/openpgp/src/packet/tag.rs @@ -59,6 +59,7 @@ pub enum Tag { /// Experimental packets. Private(u8), } +assert_send_and_sync!{Tag} impl Eq for Tag {} diff --git a/openpgp/src/packet/trust.rs b/openpgp/src/packet/trust.rs index 08ab6fe8..3455fdfd 100644 --- a/openpgp/src/packet/trust.rs +++ b/openpgp/src/packet/trust.rs @@ -23,6 +23,8 @@ pub struct Trust { value: Vec, } +assert_send_and_sync!{Trust} + impl From> for Trust { fn from(u: Vec) -> Self { Trust { diff --git a/openpgp/src/packet/unknown.rs b/openpgp/src/packet/unknown.rs index 1deab130..35686da2 100644 --- a/openpgp/src/packet/unknown.rs +++ b/openpgp/src/packet/unknown.rs @@ -32,6 +32,8 @@ pub struct Unknown { container: packet::Container, } +assert_send_and_sync!{Unknown} + impl PartialEq for Unknown { fn eq(&self, other: &Unknown) -> bool { self.tag == other.tag diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs index 246c1be6..09fc8749 100644 --- a/openpgp/src/packet/user_attribute.rs +++ b/openpgp/src/packet/user_attribute.rs @@ -38,6 +38,7 @@ pub struct UserAttribute { /// The user attribute. value: Vec, } +assert_send_and_sync!{UserAttribute} impl From> for UserAttribute { fn from(u: Vec) -> Self { @@ -117,6 +118,7 @@ impl Arbitrary for UserAttribute { pub struct SubpacketIterator<'a> { reader: buffered_reader::Memory<'a, ()>, } +assert_send_and_sync!{SubpacketIterator<'a>, 'a} impl<'a> Iterator for SubpacketIterator<'a> { type Item = Result; @@ -191,6 +193,7 @@ pub enum Subpacket { /// Unknown subpacket. Unknown(u8, Box<[u8]>), } +assert_send_and_sync!{Subpacket} #[cfg(test)] impl Arbitrary for Subpacket { @@ -224,6 +227,7 @@ pub enum Image { /// Unknown image format. Unknown(u8, Box<[u8]>), } +assert_send_and_sync!{Image} #[cfg(test)] impl Arbitrary for Image { diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index 139f3cff..a0962b8c 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -26,6 +26,7 @@ pub struct ConventionallyParsedUserID { email: Option<(usize, usize)>, uri: Option<(usize, usize)>, } +assert_send_and_sync!{ConventionallyParsedUserID} impl ConventionallyParsedUserID { /// Parses the userid according to the usual conventions. @@ -475,6 +476,7 @@ pub struct UserID { parsed: Mutex>>, } +assert_send_and_sync!{UserID} impl From> for UserID { fn from(u: Vec) -> Self { diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 259716d6..3df9581a 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -113,6 +113,8 @@ pub struct PacketPile { top_level: Container, } +assert_send_and_sync!{PacketPile} + impl fmt::Debug for PacketPile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("PacketPile") @@ -1122,10 +1124,4 @@ mod test { assert!(pile.replace(&[ 0, 0 ], 0, Vec::new()).is_ok()); assert!(pile.replace(&[ 0, 1 ], 0, Vec::new()).is_err()); } - - #[test] - fn packet_pile_is_send_and_sync() { - fn f(_: T) {} - f(PacketPile::from(vec![])); - } } diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index 5a106305..edc6cf4b 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -34,6 +34,7 @@ pub struct Map { header: Vec, data: Vec, } +assert_send_and_sync!{Map} /// Represents an entry in the map. #[derive(Clone, Debug)] @@ -113,6 +114,7 @@ pub struct Field<'a> { /// Value of the field. data: &'a [u8], } +assert_send_and_sync!{Field<'a>, 'a} impl<'a> Field<'a> { fn new(map: &'a Map, i: usize) -> Option> { diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs index 344dbd3f..dfea3e25 100644 --- a/openpgp/src/parse/packet_parser_builder.rs +++ b/openpgp/src/parse/packet_parser_builder.rs @@ -51,6 +51,7 @@ pub enum Dearmor { /// [`ReaderMode`]: ../armor/enum.ReaderMode.html Auto(armor::ReaderMode), } +assert_send_and_sync!{Dearmor} impl Default for Dearmor { fn default() -> Self { @@ -420,7 +421,7 @@ impl<'a> PacketParserBuilder<'a> { if let Some(mode) = dearmor_mode { // Add a top-level filter so that it is peeled off when - // the packet parser is finished. We use level -2 for that. + // the packet parser is finished. We use level -2 for that. self.bio = armor::Reader::from_buffered_reader(self.bio, Some(mode), Cookie::new(ARMOR_READER_LEVEL)) diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index cc268d17..f626078b 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -188,6 +188,8 @@ pub struct StandardPolicy<'a> { asymmetric_algos: AsymmetricAlgorithmCutoffList, } +assert_send_and_sync!{StandardPolicy<'a>, 'a} + impl<'a> Default for StandardPolicy<'a> { fn default() -> Self { Self::new() @@ -954,6 +956,8 @@ impl From for u8 { pub struct NullPolicy { } +assert_send_and_sync!{NullPolicy} + impl NullPolicy { /// Instantiates a new `NullPolicy`. pub const fn new() -> Self { diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index ed32e4c2..172e25e7 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1799,6 +1799,7 @@ pub struct Recipient<'a> { keyid: KeyID, key: &'a Key, } +assert_send_and_sync!{Recipient<'a>, 'a} impl<'a, P, R> From<&'a Key> for Recipient<'a> where P: key::KeyParts, diff --git a/openpgp/src/types/compression_level.rs b/openpgp/src/types/compression_level.rs index 069d2bd4..b414ef74 100644 --- a/openpgp/src/types/compression_level.rs +++ b/openpgp/src/types/compression_level.rs @@ -50,6 +50,7 @@ use crate::{ /// ``` #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CompressionLevel(u8); +assert_send_and_sync!{CompressionLevel} impl Default for CompressionLevel { fn default() -> Self { diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs index 948a5cb0..4d15766c 100644 --- a/openpgp/src/types/features.rs +++ b/openpgp/src/types/features.rs @@ -55,6 +55,7 @@ use crate::types::Bitfield; /// ``` #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Features(Bitfield); +assert_send_and_sync!{Features} impl fmt::Debug for Features { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/types/key_flags.rs b/openpgp/src/types/key_flags.rs index cca9ac92..24583114 100644 --- a/openpgp/src/types/key_flags.rs +++ b/openpgp/src/types/key_flags.rs @@ -49,6 +49,7 @@ use crate::types::Bitfield; /// ``` #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct KeyFlags(Bitfield); +assert_send_and_sync!{KeyFlags} impl fmt::Debug for KeyFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 4fd25e50..630cbd9a 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -71,6 +71,9 @@ mod timestamp; pub use timestamp::{Timestamp, Duration}; pub(crate) use timestamp::normalize_systemtime; +pub(crate) trait Sendable : Send {} +pub(crate) trait Syncable : Sync {} + /// The OpenPGP public key algorithms as defined in [Section 9.1 of /// RFC 4880], and [Section 5 of RFC 6637]. /// diff --git a/openpgp/src/types/server_preferences.rs b/openpgp/src/types/server_preferences.rs index fdac56fc..06813b37 100644 --- a/openpgp/src/types/server_preferences.rs +++ b/openpgp/src/types/server_preferences.rs @@ -56,6 +56,7 @@ use crate::types::Bitfield; /// ``` #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct KeyServerPreferences(Bitfield); +assert_send_and_sync!{KeyServerPreferences} impl fmt::Debug for KeyServerPreferences { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/types/timestamp.rs b/openpgp/src/types/timestamp.rs index 33518df7..c34ff1cd 100644 --- a/openpgp/src/types/timestamp.rs +++ b/openpgp/src/types/timestamp.rs @@ -63,6 +63,7 @@ use crate::{ /// [`Timestamp::round_down`]: ../types/struct.Timestamp.html#method.round_down #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Timestamp(u32); +assert_send_and_sync!{Timestamp} impl From for u32 { fn from(t: Timestamp) -> Self { @@ -280,6 +281,7 @@ impl Arbitrary for Timestamp { /// ``` #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Duration(u32); +assert_send_and_sync!{Duration} impl From for u32 { fn from(d: Duration) -> Self { -- cgit v1.2.3