From 96dfdae428197dd180cf10cff54b96ce8bc35d7b Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 8 Dec 2020 10:34:21 +0100 Subject: openpgp: Add assert_send_and_sync! for more types. - All types that are `Send` and `Sync` are checked now. - Fixes #627. --- openpgp/src/armor.rs | 2 +- openpgp/src/cert/amalgamation/key.rs | 10 ++++++++++ openpgp/src/cert/amalgamation/key/iter.rs | 8 ++++++++ openpgp/src/cert/parser/low_level/lexer.rs | 2 ++ openpgp/src/cert/parser/low_level/mod.rs | 1 + openpgp/src/crypto/backend/cng/symmetric.rs | 1 + openpgp/src/message/lexer.rs | 2 ++ openpgp/src/packet/mdc.rs | 1 + openpgp/src/packet/skesk.rs | 2 ++ openpgp/src/parse/stream.rs | 2 ++ openpgp/src/policy.rs | 1 + openpgp/src/serialize/stream/partial_body.rs | 1 + openpgp/src/serialize/stream/writer/mod.rs | 5 +++++ openpgp/src/serialize/stream/writer/writer_bzip2.rs | 1 + openpgp/src/serialize/stream/writer/writer_deflate.rs | 2 ++ openpgp/src/types/mod.rs | 11 +++++++++++ openpgp/src/types/revocation_key.rs | 1 + 17 files changed, 52 insertions(+), 1 deletion(-) diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 3f14cb00..c3002e7f 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -71,7 +71,6 @@ pub enum Kind { /// A generic file. This is a GnuPG extension. File, } - assert_send_and_sync!(Kind); #[cfg(test)] @@ -452,6 +451,7 @@ pub enum ReaderMode { /// text that the user cut and pasted into a text area. VeryTolerant, } +assert_send_and_sync!(ReaderMode); /// A filter that strips ASCII Armor from a stream of data. pub struct Reader<'a> { diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index 7071829e..d3dc085f 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -449,6 +449,11 @@ pub struct KeyAmalgamation<'a, P, R, R2> ca: ComponentAmalgamation<'a, Key>, primary: R2, } +assert_send_and_sync!(KeyAmalgamation<'_, P, R, R2>, + P: key::KeyParts, + R: key::KeyRole, + R2 +); // derive(Clone) doesn't work with generic parameters that don't // implement clone. But, we don't need to require that C implements @@ -942,6 +947,11 @@ pub struct ValidKeyAmalgamation<'a, P, R, R2> // The binding signature at time `time`. (This is just a cache.) binding_signature: &'a Signature, } +assert_send_and_sync!(ValidKeyAmalgamation<'_, P, R, R2>, + P: key::KeyParts, + R: key::KeyRole, + R2: Copy +); /// A Valid primary Key, and its associated data. /// diff --git a/openpgp/src/cert/amalgamation/key/iter.rs b/openpgp/src/cert/amalgamation/key/iter.rs index a41673bd..45d3c618 100644 --- a/openpgp/src/cert/amalgamation/key/iter.rs +++ b/openpgp/src/cert/amalgamation/key/iter.rs @@ -82,6 +82,10 @@ pub struct KeyAmalgamationIter<'a, P, R> _p: std::marker::PhantomData

, _r: std::marker::PhantomData, } +assert_send_and_sync!(KeyAmalgamationIter<'_, P, R>, + P: key::KeyParts, + R: key::KeyRole +); impl<'a, P, R> fmt::Debug for KeyAmalgamationIter<'a, P, R> where P: key::KeyParts, @@ -680,6 +684,10 @@ pub struct ValidKeyAmalgamationIter<'a, P, R> _p: std::marker::PhantomData

, _r: std::marker::PhantomData, } +assert_send_and_sync!(ValidKeyAmalgamationIter<'_, P, R>, + P: key::KeyParts, + R: key::KeyRole +); impl<'a, P, R> fmt::Debug for ValidKeyAmalgamationIter<'a, P, R> where P: key::KeyParts, diff --git a/openpgp/src/cert/parser/low_level/lexer.rs b/openpgp/src/cert/parser/low_level/lexer.rs index 27df8b6b..a8fad2e8 100644 --- a/openpgp/src/cert/parser/low_level/lexer.rs +++ b/openpgp/src/cert/parser/low_level/lexer.rs @@ -46,6 +46,7 @@ pub enum Token { /// An `Unknown` packet. Unknown(Tag, Option), } +assert_send_and_sync!(Token); /// Internal data-structure used by the parser. /// @@ -58,6 +59,7 @@ pub enum Component { UserAttributeBundle(UserAttributeBundle), UnknownBundle(UnknownBundle), } +assert_send_and_sync!(Component); impl<'a> From<&'a Token> for Tag { fn from(token: &'a Token) -> Self { diff --git a/openpgp/src/cert/parser/low_level/mod.rs b/openpgp/src/cert/parser/low_level/mod.rs index a1cd2002..b89ce7bf 100644 --- a/openpgp/src/cert/parser/low_level/mod.rs +++ b/openpgp/src/cert/parser/low_level/mod.rs @@ -74,6 +74,7 @@ pub enum CertParserError { /// An OpenPGP error. OpenPGP(Error), } +assert_send_and_sync!(CertParserError); impl From for anyhow::Error { fn from(err: CertParserError) -> Self { diff --git a/openpgp/src/crypto/backend/cng/symmetric.rs b/openpgp/src/crypto/backend/cng/symmetric.rs index 432e6679..d3215eec 100644 --- a/openpgp/src/crypto/backend/cng/symmetric.rs +++ b/openpgp/src/crypto/backend/cng/symmetric.rs @@ -77,6 +77,7 @@ impl Mode for Mutex { #[derive(Debug, thiserror::Error)] #[error("Unsupported algorithm: {0}")] pub struct UnsupportedAlgorithm(SymmetricAlgorithm); +assert_send_and_sync!(UnsupportedAlgorithm); impl From for Error { fn from(value: UnsupportedAlgorithm) -> Error { diff --git a/openpgp/src/message/lexer.rs b/openpgp/src/message/lexer.rs index 623dc05d..e1ac7194 100644 --- a/openpgp/src/message/lexer.rs +++ b/openpgp/src/message/lexer.rs @@ -42,6 +42,7 @@ pub enum Token { /// A container's unparsed content. OpaqueContent, } +assert_send_and_sync!(Token); impl fmt::Display for Token { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -53,6 +54,7 @@ impl fmt::Display for Token { pub enum LexicalError { // There are no lexing errors. } +assert_send_and_sync!(LexicalError); impl fmt::Display for LexicalError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/packet/mdc.rs b/openpgp/src/packet/mdc.rs index 9f07dafe..16fdcd7b 100644 --- a/openpgp/src/packet/mdc.rs +++ b/openpgp/src/packet/mdc.rs @@ -22,6 +22,7 @@ pub struct MDC { /// A 20-octet SHA-1 hash of the preceding plaintext data. digest: [u8; 20], } +assert_send_and_sync!(MDC); impl PartialEq for MDC { fn eq(&self, other: &MDC) -> bool { diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs index 3d00822f..36b98323 100644 --- a/openpgp/src/packet/skesk.rs +++ b/openpgp/src/packet/skesk.rs @@ -77,6 +77,7 @@ pub struct SKESK4 { esk: std::result::Result>, // optional ciphertext. Box<[u8]>>, // S2K body + maybe ciphertext. } +assert_send_and_sync!(SKESK4); // Because the S2K and ESK cannot be cleanly separated at parse time, // we need to carefully compare and hash SKESK4 packets. @@ -334,6 +335,7 @@ pub struct SKESK5 { /// Digest for the AEAD algorithm. aead_digest: Box<[u8]>, } +assert_send_and_sync!(SKESK5); // Because the S2K, IV, and ESK cannot be cleanly separated at parse // time, we need to carefully compare and hash SKESK5 packets. diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 3cb1ae78..a55f263f 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -302,6 +302,7 @@ pub enum VerificationError<'a> { error: anyhow::Error, }, } +assert_send_and_sync!(VerificationError<'_>); impl<'a> std::fmt::Display for VerificationError<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -570,6 +571,7 @@ pub enum MessageLayer<'a> { results: Vec>, } } +assert_send_and_sync!(MessageLayer<'_>); /// Internal version of the message structure. /// diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index 2a891fd2..29715451 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -911,6 +911,7 @@ pub enum AsymmetricAlgorithm { /// Unknown algorithm. Unknown, } +assert_send_and_sync!(AsymmetricAlgorithm); impl std::fmt::Display for AsymmetricAlgorithm { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/openpgp/src/serialize/stream/partial_body.rs b/openpgp/src/serialize/stream/partial_body.rs index 52752fcb..cc9afa89 100644 --- a/openpgp/src/serialize/stream/partial_body.rs +++ b/openpgp/src/serialize/stream/partial_body.rs @@ -45,6 +45,7 @@ pub struct PartialBodyFilter<'a, C: 'a> { // The number of bytes written to this filter. position: u64, } +assert_send_and_sync!(PartialBodyFilter<'_, C>, C); const PARTIAL_BODY_FILTER_MAX_CHUNK_SIZE : usize = 1 << 30; diff --git a/openpgp/src/serialize/stream/writer/mod.rs b/openpgp/src/serialize/stream/writer/mod.rs index e1453f56..c2f9f518 100644 --- a/openpgp/src/serialize/stream/writer/mod.rs +++ b/openpgp/src/serialize/stream/writer/mod.rs @@ -189,6 +189,7 @@ pub struct Identity<'a, C> { inner: Option>, cookie: C, } +assert_send_and_sync!(Identity<'_, C>, C); impl<'a> Identity<'a, Cookie> { /// Makes an identity writer. @@ -269,6 +270,7 @@ pub struct Generic { cookie: C, position: u64, } +assert_send_and_sync!(Generic, W: io::Write, C); impl<'a, W: 'a + io::Write + Send + Sync> Generic { /// Wraps an `io::Write`r. @@ -353,6 +355,7 @@ impl<'a, W: io::Write + Send + Sync, C> Stackable<'a, C> for Generic { pub struct Armorer<'a, C: 'a> { inner: Generic>, C>, } +assert_send_and_sync!(Armorer<'_, C>, C); impl<'a> Armorer<'a, Cookie> { /// Makes an armoring writer. @@ -425,6 +428,7 @@ impl<'a, C: 'a> Stackable<'a, C> for Armorer<'a, C> { pub struct Encryptor<'a, C: 'a> { inner: Generic + Send + Sync + 'a>>, C>, } +assert_send_and_sync!(Encryptor<'_, C>, C); impl<'a> Encryptor<'a, Cookie> { /// Makes an encrypting writer. @@ -496,6 +500,7 @@ impl<'a, C: 'a> Stackable<'a, C> for Encryptor<'a, C> { pub struct AEADEncryptor<'a, C: 'a> { inner: Generic>, C>, } +assert_send_and_sync!(AEADEncryptor<'_, C>, C); impl<'a> AEADEncryptor<'a, Cookie> { /// Makes an encrypting writer. diff --git a/openpgp/src/serialize/stream/writer/writer_bzip2.rs b/openpgp/src/serialize/stream/writer/writer_bzip2.rs index a13ad61f..b38d8f7e 100644 --- a/openpgp/src/serialize/stream/writer/writer_bzip2.rs +++ b/openpgp/src/serialize/stream/writer/writer_bzip2.rs @@ -10,6 +10,7 @@ use super::{Generic, Message, BoxStack, Stackable, Cookie}; pub struct BZ<'a, C: 'a> { inner: Generic>, C>, } +assert_send_and_sync!(BZ<'_, C>, C); impl<'a> BZ<'a, Cookie> { /// Makes a BZ compressing writer. diff --git a/openpgp/src/serialize/stream/writer/writer_deflate.rs b/openpgp/src/serialize/stream/writer/writer_deflate.rs index 92226302..27b4bd6b 100644 --- a/openpgp/src/serialize/stream/writer/writer_deflate.rs +++ b/openpgp/src/serialize/stream/writer/writer_deflate.rs @@ -10,6 +10,7 @@ use super::{Generic, Message, BoxStack, Stackable, Cookie}; pub struct ZIP<'a, C: 'a> { inner: Generic>, C>, } +assert_send_and_sync!(ZIP<'_, C>, C); impl<'a> ZIP<'a, Cookie> { /// Makes a ZIP compressing writer. @@ -78,6 +79,7 @@ impl<'a, C: 'a> Stackable<'a, C> for ZIP<'a, C> { pub struct ZLIB<'a, C: 'a> { inner: Generic>, C>, } +assert_send_and_sync!(ZLIB<'_, C>, C); impl<'a> ZLIB<'a, Cookie> { /// Makes a ZLIB compressing writer. diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 630cbd9a..8e5319cd 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -126,6 +126,7 @@ pub enum PublicKeyAlgorithm { /// Unknown algorithm identifier. Unknown(u8), } +assert_send_and_sync!(PublicKeyAlgorithm); impl PublicKeyAlgorithm { /// Returns true if the algorithm can sign data. @@ -313,6 +314,7 @@ pub enum Curve { /// Unknown curve. Unknown(Box<[u8]>), } +assert_send_and_sync!(Curve); impl Curve { /// Returns the length of public keys over this curve in bits. @@ -575,6 +577,7 @@ pub enum SymmetricAlgorithm { /// Unknown algorithm identifier. Unknown(u8), } +assert_send_and_sync!(SymmetricAlgorithm); impl Default for SymmetricAlgorithm { fn default() -> Self { @@ -711,6 +714,7 @@ pub enum AEADAlgorithm { /// Unknown algorithm identifier. Unknown(u8), } +assert_send_and_sync!(AEADAlgorithm); impl AEADAlgorithm { /// Returns whether this algorithm is supported. @@ -831,6 +835,7 @@ pub enum CompressionAlgorithm { /// Unknown compression algorithm identifier. Unknown(u8), } +assert_send_and_sync!(CompressionAlgorithm); impl Default for CompressionAlgorithm { fn default() -> Self { @@ -964,6 +969,7 @@ pub enum HashAlgorithm { /// Unknown hash algorithm identifier. Unknown(u8), } +assert_send_and_sync!(HashAlgorithm); impl Default for HashAlgorithm { fn default() -> Self { @@ -1117,6 +1123,7 @@ pub enum SignatureType { /// Catchall. Unknown(u8), } +assert_send_and_sync!(SignatureType); impl From for SignatureType { fn from(u: u8) -> Self { @@ -1291,6 +1298,7 @@ pub enum ReasonForRevocation { /// Unknown reason identifier. Unknown(u8), } +assert_send_and_sync!(ReasonForRevocation); impl From for ReasonForRevocation { fn from(u: u8) -> Self { @@ -1440,6 +1448,7 @@ pub enum RevocationType { /// revocations. Soft, } +assert_send_and_sync!(RevocationType); impl ReasonForRevocation { /// Returns the revocation's `RevocationType`. @@ -1527,6 +1536,7 @@ pub enum DataFormat { /// Unknown format specifier. Unknown(char), } +assert_send_and_sync!(DataFormat); impl Default for DataFormat { fn default() -> Self { @@ -1656,6 +1666,7 @@ pub enum RevocationStatus<'a> { /// us from seeing the revocation certificate. NotAsFarAsWeKnow, } +assert_send_and_sync!(RevocationStatus<'_>); #[cfg(test)] mod tests { diff --git a/openpgp/src/types/revocation_key.rs b/openpgp/src/types/revocation_key.rs index f4dc7c49..c0457b24 100644 --- a/openpgp/src/types/revocation_key.rs +++ b/openpgp/src/types/revocation_key.rs @@ -68,6 +68,7 @@ pub struct RevocationKey { /// authorizations. unknown: u8, } +assert_send_and_sync!(RevocationKey); impl From<&Cert> for RevocationKey { fn from(cert: &Cert) -> Self { -- cgit v1.2.3