From c51d96b98f1ed92fe7bc6d964abb0d2a8616bae1 Mon Sep 17 00:00:00 2001 From: Nora Widdecke Date: Tue, 12 May 2020 17:07:44 +0200 Subject: openpgp: Introduce feature flag for quickcheck. - Make quickcheck dependency optional. - Make quickcheck a dev-dependency for tests. - Fix doctests for - cert::ValidCert::user_attributes, - cert::builder::CertBuilder::add_user_attribute, - cert::revoke::UserAttributeRevocationBuilder - cert::revoke::UserAttributeRevocationBuilder::build. Doctests do not use cfg(test), so we cannot use quickcheck in there. --- openpgp/Cargo.toml | 3 ++- openpgp/src/armor.rs | 3 +++ openpgp/src/cert/builder.rs | 20 ++++++++++++-------- openpgp/src/cert/mod.rs | 10 +++++++--- openpgp/src/cert/revoke.rs | 16 ++++++++++------ openpgp/src/crypto/mpi.rs | 7 +++++++ openpgp/src/crypto/s2k.rs | 3 +++ openpgp/src/crypto/sexp.rs | 4 ++++ openpgp/src/fingerprint.rs | 3 +++ openpgp/src/keyid.rs | 3 +++ openpgp/src/packet/compressed_data.rs | 3 +++ openpgp/src/packet/key.rs | 5 +++++ openpgp/src/packet/literal.rs | 3 +++ openpgp/src/packet/marker.rs | 2 ++ openpgp/src/packet/mod.rs | 3 +++ openpgp/src/packet/one_pass_sig.rs | 4 ++++ openpgp/src/packet/pkesk.rs | 3 +++ openpgp/src/packet/signature/mod.rs | 11 +++++++++++ openpgp/src/packet/signature/subpacket.rs | 16 +++++++++++++++- openpgp/src/packet/skesk.rs | 5 +++++ openpgp/src/packet/tag.rs | 2 ++ openpgp/src/packet/trust.rs | 3 +++ openpgp/src/packet/user_attribute.rs | 5 +++++ openpgp/src/packet/userid/mod.rs | 3 +++ openpgp/src/types/features.rs | 3 +++ openpgp/src/types/key_flags.rs | 3 +++ openpgp/src/types/mod.rs | 11 +++++++++++ openpgp/src/types/revocation_key.rs | 2 ++ openpgp/src/types/server_preferences.rs | 3 +++ openpgp/src/types/timestamp.rs | 4 ++++ 30 files changed, 147 insertions(+), 19 deletions(-) diff --git a/openpgp/Cargo.toml b/openpgp/Cargo.toml index 104cb6c5..0698a7bb 100644 --- a/openpgp/Cargo.toml +++ b/openpgp/Cargo.toml @@ -33,7 +33,7 @@ lazy_static = "1.3" libc = "0.2" memsec = "0.5.6" nettle = { version = "7", optional = true } -quickcheck = { version = "0.9", default-features = false } +quickcheck = { version = "0.9", default-features = false, optional = true } rand = { version = "0.7", default-features = false } regex = "1" thiserror = "1" @@ -44,6 +44,7 @@ lalrpop = "0.17" [dev-dependencies] rpassword = "=4.0.3" +quickcheck = { version = "0.9", default-features = false } [features] default = ["compression", "crypto-nettle"] diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index f7ece759..2425c804 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -34,6 +34,8 @@ use std::path::Path; use std::cmp; use std::str; use std::borrow::Cow; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::vec_truncate; @@ -68,6 +70,7 @@ pub enum Kind { File, } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Kind { fn arbitrary(g: &mut G) -> Self { use self::Kind::*; diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 751abb55..4243cb2f 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -426,7 +426,7 @@ impl CertBuilder { /// primary User ID flag set: /// /// ``` - /// # use quickcheck::{Arbitrary, StdThreadGen}; + /// # use openpgp::packet::user_attribute::Subpacket; /// use sequoia_openpgp as openpgp; /// use openpgp::cert::prelude::*; /// use openpgp::packet::prelude::*; @@ -434,9 +434,11 @@ impl CertBuilder { /// /// # fn main() -> openpgp::Result<()> { /// let p = &StandardPolicy::new(); - /// - /// # let mut gen = StdThreadGen::new(16); - /// # let user_attribute : UserAttribute = UserAttribute::arbitrary(&mut gen); + /// # + /// # // Create some user attribute. Doctests do not pass cfg(test), + /// # // so UserAttribute::arbitrary is not available + /// # let sp = Subpacket::Unknown(7, vec![7; 7].into_boxed_slice()); + /// # let user_attribute = UserAttribute::new(&[sp])?; /// /// let (cert, rev) = /// CertBuilder::new() @@ -455,7 +457,7 @@ impl CertBuilder { /// set: /// /// ``` - /// # use quickcheck::{Arbitrary, StdThreadGen}; + /// # use openpgp::packet::user_attribute::Subpacket; /// use sequoia_openpgp as openpgp; /// use openpgp::cert::prelude::*; /// use openpgp::packet::prelude::*; @@ -463,9 +465,11 @@ impl CertBuilder { /// /// # fn main() -> openpgp::Result<()> { /// let p = &StandardPolicy::new(); - /// - /// # let mut gen = StdThreadGen::new(16); - /// # let user_attribute : UserAttribute = UserAttribute::arbitrary(&mut gen); + /// # + /// # // Create some user attribute. Doctests do not pass cfg(test), + /// # // so UserAttribute::arbitrary is not available + /// # let sp = Subpacket::Unknown(7, vec![7; 7].into_boxed_slice()); + /// # let user_attribute = UserAttribute::new(&[sp])?; /// /// let (cert, rev) = /// CertBuilder::new() diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 7de9f286..36d54451 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -3041,10 +3041,10 @@ impl<'a> ValidCert<'a> { /// # Examples /// /// ``` - /// # use quickcheck::{Arbitrary, StdThreadGen}; /// use sequoia_openpgp as openpgp; /// # use openpgp::cert::prelude::*; /// # use openpgp::packet::prelude::*; + /// # use openpgp::packet::user_attribute::Subpacket; /// use openpgp::policy::StandardPolicy; /// /// # fn main() -> openpgp::Result<()> { @@ -3053,8 +3053,12 @@ impl<'a> ValidCert<'a> { /// # let (cert, _) = /// # CertBuilder::general_purpose(None, Some("alice@example.org")) /// # .generate()?; - /// # let mut gen = StdThreadGen::new(16); - /// # let ua : UserAttribute = UserAttribute::arbitrary(&mut gen); + /// # + /// # // Create some user attribute. Doctests do not pass cfg(test), + /// # // so UserAttribute::arbitrary is not available + /// # let sp = Subpacket::Unknown(7, vec![7; 7].into_boxed_slice()); + /// # let ua = UserAttribute::new(&[sp]); + /// # /// // Add a User Attribute without a self-signature to the certificate. /// let cert = cert.merge_packets(ua)?; /// assert_eq!(cert.user_attributes().count(), 1); diff --git a/openpgp/src/cert/revoke.rs b/openpgp/src/cert/revoke.rs index 50130510..ba46fd1b 100644 --- a/openpgp/src/cert/revoke.rs +++ b/openpgp/src/cert/revoke.rs @@ -750,7 +750,7 @@ impl Deref for UserIDRevocationBuilder { /// Revoke a User Attribute that is no longer valid: /// /// ```rust -/// # use quickcheck::{Arbitrary, StdThreadGen}; +/// # use openpgp::packet::user_attribute::Subpacket; /// use sequoia_openpgp as openpgp; /// # use openpgp::Result; /// use openpgp::cert::prelude::*; @@ -763,8 +763,10 @@ impl Deref for UserIDRevocationBuilder { /// # fn main() -> Result<()> { /// let p = &StandardPolicy::new(); /// -/// # let mut gen = StdThreadGen::new(16); -/// # let user_attribute : UserAttribute = UserAttribute::arbitrary(&mut gen); +/// # // Create some user attribute. Doctests do not pass cfg(test), +/// # // so UserAttribute::arbitrary is not available +/// # let sp = Subpacket::Unknown(7, vec![7; 7].into_boxed_slice()); +/// # let user_attribute = UserAttribute::new(&[sp])?; /// # /// # let (cert, _) = CertBuilder::new() /// # .add_user_attribute(user_attribute) @@ -905,7 +907,7 @@ impl UserAttributeRevocationBuilder { /// valid: /// /// ```rust - /// # use quickcheck::{Arbitrary, StdThreadGen}; + /// # use openpgp::packet::user_attribute::Subpacket; /// use sequoia_openpgp as openpgp; /// # use openpgp::Result; /// use openpgp::cert::prelude::*; @@ -918,8 +920,10 @@ impl UserAttributeRevocationBuilder { /// # fn main() -> Result<()> { /// let p = &StandardPolicy::new(); /// - /// # let mut gen = StdThreadGen::new(16); - /// # let user_attribute : UserAttribute = UserAttribute::arbitrary(&mut gen); + /// # // Create some user attribute. Doctests do not pass cfg(test), + /// # // so UserAttribute::arbitrary is not available + /// # let sp = Subpacket::Unknown(7, vec![7; 7].into_boxed_slice()); + /// # let user_attribute = UserAttribute::new(&[sp])?; /// # /// # let (cert, _) = CertBuilder::new() /// # .add_user_attribute(user_attribute) diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index 13bc0007..1dd2cd30 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -3,7 +3,9 @@ use std::fmt; use std::cmp::Ordering; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; +#[cfg(any(test, feature = "quickcheck"))] use rand::Rng; use crate::types::{ @@ -184,6 +186,7 @@ impl Hash for MPI { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for MPI { fn arbitrary(g: &mut G) -> Self { loop { @@ -409,6 +412,7 @@ impl Hash for PublicKey { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for PublicKey { fn arbitrary(g: &mut G) -> Self { use self::PublicKey::*; @@ -678,6 +682,7 @@ impl Hash for SecretKeyMaterial { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SecretKeyMaterial { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 6) { @@ -780,6 +785,7 @@ impl Hash for Ciphertext { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Ciphertext { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 3) { @@ -865,6 +871,7 @@ impl Hash for Signature { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Signature { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 4) { diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 8dff4693..d5553ce4 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -14,7 +14,9 @@ use crate::crypto::SessionKey; use std::fmt; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; +#[cfg(any(test, feature = "quickcheck"))] use rand::Rng; /// String-to-Key (S2K) specifiers. @@ -262,6 +264,7 @@ impl fmt::Display for S2K { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for S2K { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 5) { diff --git a/openpgp/src/crypto/sexp.rs b/openpgp/src/crypto/sexp.rs index 479fb8e3..17805234 100644 --- a/openpgp/src/crypto/sexp.rs +++ b/openpgp/src/crypto/sexp.rs @@ -9,6 +9,8 @@ use std::convert::TryFrom; use std::fmt; use std::ops::Deref; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::crypto::{self, mpi, SessionKey}; @@ -293,6 +295,7 @@ impl TryFrom<&mpi::Ciphertext> for Sexp { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Sexp { fn arbitrary(g: &mut G) -> Self { if f32::arbitrary(g) < 0.7 { @@ -382,6 +385,7 @@ impl Deref for String_ { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for String_ { fn arbitrary(g: &mut G) -> Self { if bool::arbitrary(g) { diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index 6094229f..a88dafdd 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -1,4 +1,6 @@ use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; /// A long identifier for certificates and keys. @@ -206,6 +208,7 @@ impl Fingerprint { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Fingerprint { fn arbitrary(g: &mut G) -> Self { use rand::Rng; diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index fb511316..6d8e739f 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -1,4 +1,6 @@ use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -247,6 +249,7 @@ impl KeyID { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for KeyID { fn arbitrary(g: &mut G) -> Self { KeyID::new(u64::arbitrary(g)) diff --git a/openpgp/src/packet/compressed_data.rs b/openpgp/src/packet/compressed_data.rs index e86d870f..4f379496 100644 --- a/openpgp/src/packet/compressed_data.rs +++ b/openpgp/src/packet/compressed_data.rs @@ -1,4 +1,6 @@ use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::packet; @@ -94,6 +96,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for CompressedData { fn arbitrary(g: &mut G) -> Self { use rand::Rng; diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 55a9ff60..039c493f 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -54,6 +54,8 @@ use std::fmt; use std::cmp::Ordering; use std::convert::TryInto; use std::time; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -1290,6 +1292,7 @@ impl Encrypted { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for super::Key where P: KeyParts, P: Clone, R: KeyRole, R: Clone, @@ -1300,6 +1303,7 @@ impl Arbitrary for super::Key } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Key4 { fn arbitrary(g: &mut G) -> Self { let mpis = mpi::PublicKey::arbitrary(g); @@ -1316,6 +1320,7 @@ impl Arbitrary for Key4 { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Key4 { fn arbitrary(g: &mut G) -> Self { use rand::Rng; diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs index 46e6bfb0..7eb4082b 100644 --- a/openpgp/src/packet/literal.rs +++ b/openpgp/src/packet/literal.rs @@ -2,6 +2,8 @@ use std::fmt; use std::cmp; use std::convert::TryInto; use std::time; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::types::{DataFormat, Timestamp}; @@ -172,6 +174,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Literal { fn arbitrary(g: &mut G) -> Self { let mut l = Literal::new(DataFormat::arbitrary(g)); diff --git a/openpgp/src/packet/marker.rs b/openpgp/src/packet/marker.rs index 8217901c..728f115b 100644 --- a/openpgp/src/packet/marker.rs +++ b/openpgp/src/packet/marker.rs @@ -1,3 +1,4 @@ +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::packet; @@ -34,6 +35,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Marker { fn arbitrary(_: &mut G) -> Self { Self::default() diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index fec3ee2a..3c822df7 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -161,6 +161,7 @@ use std::ops::{Deref, DerefMut}; use std::slice; use std::iter::IntoIterator; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -434,6 +435,7 @@ impl<'a> DerefMut for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Packet { fn arbitrary(g: &mut G) -> Self { use rand::Rng; @@ -479,6 +481,7 @@ pub struct Common { dummy: std::marker::PhantomData<()>, } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Common { fn arbitrary(_: &mut G) -> Self { // XXX: Change if this gets interesting fields. diff --git a/openpgp/src/packet/one_pass_sig.rs b/openpgp/src/packet/one_pass_sig.rs index dc40cf64..a6861d6e 100644 --- a/openpgp/src/packet/one_pass_sig.rs +++ b/openpgp/src/packet/one_pass_sig.rs @@ -5,6 +5,8 @@ //! [Section 5.4 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.4 use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -166,12 +168,14 @@ impl<'a> std::convert::TryFrom<&'a Signature> for OnePassSig3 { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for super::OnePassSig { fn arbitrary(g: &mut G) -> Self { OnePassSig3::arbitrary(g).into() } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for OnePassSig3 { fn arbitrary(g: &mut G) -> Self { let mut ops = OnePassSig3::new(SignatureType::arbitrary(g)); diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index f92c596e..81c0f9ae 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -5,6 +5,7 @@ //! //! [Section 5.1 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.1 +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -189,12 +190,14 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for super::PKESK { fn arbitrary(g: &mut G) -> Self { PKESK3::arbitrary(g).into() } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for PKESK3 { fn arbitrary(g: &mut G) -> Self { let (ciphertext, pk_algo) = loop { diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index d0829a5d..74be7900 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -2,6 +2,8 @@ use std::fmt; use std::ops::{Deref, DerefMut}; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -28,6 +30,7 @@ use crate::packet::signature::subpacket::{ SubpacketAreas, }; +#[cfg(any(test, feature = "quickcheck"))] /// Like quickcheck::Arbitrary, but bounded. trait ArbitraryBounded { /// Generates an arbitrary value, but only recurses if `depth > @@ -35,9 +38,11 @@ trait ArbitraryBounded { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self; } +#[cfg(any(test, feature = "quickcheck"))] /// Default depth when implementing Arbitrary using ArbitraryBounded. const DEFAULT_ARBITRARY_DEPTH: usize = 2; +#[cfg(any(test, feature = "quickcheck"))] macro_rules! impl_arbitrary_with_bound { ($typ:path) => { impl Arbitrary for $typ { @@ -101,6 +106,7 @@ pub struct SignatureBuilder { subpackets: SubpacketAreas, } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for SignatureBuilder { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { SignatureBuilder { @@ -115,6 +121,7 @@ impl ArbitraryBounded for SignatureBuilder { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(SignatureBuilder); impl Deref for SignatureBuilder { @@ -1212,14 +1219,17 @@ impl From for super::Signature { } } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for super::Signature { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { Signature4::arbitrary_bounded(g, depth).into() } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(super::Signature); +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for Signature4 { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { use mpi::MPI; @@ -1262,6 +1272,7 @@ impl ArbitraryBounded for Signature4 { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(Signature4); #[cfg(test)] diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index b37d2a35..7d1ae2e5 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -65,13 +65,16 @@ use std::io; use std::cmp; use std::time; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; +#[cfg(any(test, feature = "quickcheck"))] +use crate::packet::signature::ArbitraryBounded; use crate::{ Error, Result, packet::Signature, - packet::signature::{self, Signature4, ArbitraryBounded}, + packet::signature::{self, Signature4}, packet::key, packet::Key, Fingerprint, @@ -293,6 +296,7 @@ impl From for u8 { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SubpacketTag { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -340,6 +344,7 @@ pub struct SubpacketArea { parsed: Mutex>>>, } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for SubpacketArea { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { use rand::Rng; @@ -353,6 +358,7 @@ impl ArbitraryBounded for SubpacketArea { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(SubpacketArea); impl Default for SubpacketArea { @@ -531,6 +537,7 @@ pub struct NotationData { value: Vec, } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for NotationData { fn arbitrary(g: &mut G) -> Self { NotationData { @@ -587,6 +594,7 @@ impl From for NotationDataFlags { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for NotationDataFlags { fn arbitrary(g: &mut G) -> Self { u32::arbitrary(g).into() @@ -747,6 +755,7 @@ pub enum SubpacketValue { #[doc(hidden)] __Nonexhaustive, } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for SubpacketValue { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { use rand::Rng; @@ -797,6 +806,7 @@ impl ArbitraryBounded for SubpacketValue { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(SubpacketValue); impl SubpacketValue { @@ -861,6 +871,7 @@ pub struct Subpacket { value: SubpacketValue, } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for Subpacket { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { Subpacket::new(ArbitraryBounded::arbitrary_bounded(g, depth), @@ -868,6 +879,7 @@ impl ArbitraryBounded for Subpacket { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(Subpacket); impl fmt::Debug for Subpacket { @@ -1645,6 +1657,7 @@ pub struct SubpacketAreas { unhashed_area: SubpacketArea, } +#[cfg(any(test, feature = "quickcheck"))] impl ArbitraryBounded for SubpacketAreas { fn arbitrary_bounded(g: &mut G, depth: usize) -> Self { SubpacketAreas::new(ArbitraryBounded::arbitrary_bounded(g, depth), @@ -1652,6 +1665,7 @@ impl ArbitraryBounded for SubpacketAreas { } } +#[cfg(any(test, feature = "quickcheck"))] impl_arbitrary_with_bound!(SubpacketAreas); impl Deref for SubpacketAreas { diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs index 9ba48c39..ad907abe 100644 --- a/openpgp/src/packet/skesk.rs +++ b/openpgp/src/packet/skesk.rs @@ -7,6 +7,8 @@ //! [Section 5.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.3 use std::ops::{Deref, DerefMut}; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Result; @@ -37,6 +39,7 @@ impl SKESK { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SKESK { fn arbitrary(g: &mut G) -> Self { if bool::arbitrary(g) { @@ -211,6 +214,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SKESK4 { fn arbitrary(g: &mut G) -> Self { SKESK4::new(SymmetricAlgorithm::arbitrary(g), @@ -383,6 +387,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SKESK5 { fn arbitrary(g: &mut G) -> Self { let algo = AEADAlgorithm::EAX; // The only one we dig. diff --git a/openpgp/src/packet/tag.rs b/openpgp/src/packet/tag.rs index d99b5ee5..c7c8ddcf 100644 --- a/openpgp/src/packet/tag.rs +++ b/openpgp/src/packet/tag.rs @@ -2,6 +2,7 @@ use std::fmt; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::packet::Packet; @@ -215,6 +216,7 @@ impl fmt::Display for Tag { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Tag { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() diff --git a/openpgp/src/packet/trust.rs b/openpgp/src/packet/trust.rs index 5eaf8815..af876131 100644 --- a/openpgp/src/packet/trust.rs +++ b/openpgp/src/packet/trust.rs @@ -1,4 +1,6 @@ use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::packet; @@ -58,6 +60,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Trust { fn arbitrary(g: &mut G) -> Self { Vec::::arbitrary(g).into() diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs index a4a7fdc0..34926c47 100644 --- a/openpgp/src/packet/user_attribute.rs +++ b/openpgp/src/packet/user_attribute.rs @@ -6,7 +6,9 @@ use std::fmt; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; +#[cfg(any(test, feature = "quickcheck"))] use rand::Rng; use buffered_reader::BufferedReader; @@ -101,6 +103,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for UserAttribute { fn arbitrary(g: &mut G) -> Self { UserAttribute::new( @@ -189,6 +192,7 @@ pub enum Subpacket { Unknown(u8, Box<[u8]>), } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Subpacket { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 2) { @@ -217,6 +221,7 @@ pub enum Image { Unknown(u8, Box<[u8]>), } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Image { fn arbitrary(g: &mut G) -> Self { match g.gen_range(0, 3) { diff --git a/openpgp/src/packet/userid/mod.rs b/openpgp/src/packet/userid/mod.rs index 80f67dc1..17267a5b 100644 --- a/openpgp/src/packet/userid/mod.rs +++ b/openpgp/src/packet/userid/mod.rs @@ -5,7 +5,9 @@ use std::cell::RefCell; use std::cmp::Ordering; use std::sync::Mutex; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; + use anyhow::Context; use regex::Regex; @@ -829,6 +831,7 @@ impl From for Packet { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for UserID { fn arbitrary(g: &mut G) -> Self { Vec::::arbitrary(g).into() diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs index 892cc308..9756ca70 100644 --- a/openpgp/src/types/features.rs +++ b/openpgp/src/types/features.rs @@ -1,5 +1,7 @@ use std::fmt; use std::hash::{Hash, Hasher}; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; /// Describes features supported by an OpenPGP implementation. @@ -207,6 +209,7 @@ const FEATURE_FLAG_AEAD: u8 = 0x02; /// Number of bytes with known flags. const FEATURE_FLAGS_N_KNOWN_BYTES: usize = 1; +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Features { fn arbitrary(g: &mut G) -> Self { Self::new(Vec::arbitrary(g)) diff --git a/openpgp/src/types/key_flags.rs b/openpgp/src/types/key_flags.rs index 579d11da..5a9da8f3 100644 --- a/openpgp/src/types/key_flags.rs +++ b/openpgp/src/types/key_flags.rs @@ -2,6 +2,8 @@ use std::hash::{Hash, Hasher}; use std::fmt; use std::cmp; use std::ops::{BitAnd, BitOr}; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; /// Describes how a key may be used, and stores additional information. @@ -365,6 +367,7 @@ const KEY_FLAG_GROUP_KEY: u8 = 0x80; /// Number of bytes with known flags. const KEY_FLAGS_N_KNOWN_BYTES: usize = 1; +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for KeyFlags { fn arbitrary(g: &mut G) -> Self { Self::new(Vec::arbitrary(g)) diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index ddea9239..51f8acca 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -49,6 +49,7 @@ use std::fmt; use std::str::FromStr; use std::result; +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::Error; @@ -273,12 +274,14 @@ impl fmt::Display for PublicKeyAlgorithm { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for PublicKeyAlgorithm { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() } } +#[cfg(any(test, feature = "quickcheck"))] impl PublicKeyAlgorithm { pub(crate) fn arbitrary_for_signing(g: &mut G) -> Self { use rand::Rng; @@ -509,6 +512,7 @@ impl Curve { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Curve { fn arbitrary(g: &mut G) -> Self { match u8::arbitrary(g) % 8 { @@ -703,6 +707,7 @@ impl fmt::Display for SymmetricAlgorithm { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SymmetricAlgorithm { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -819,6 +824,7 @@ impl fmt::Display for AEADAlgorithm { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for AEADAlgorithm { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -962,6 +968,7 @@ impl fmt::Display for CompressionAlgorithm { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for CompressionAlgorithm { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -1096,6 +1103,7 @@ impl fmt::Display for HashAlgorithm { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for HashAlgorithm { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -1253,6 +1261,7 @@ impl fmt::Display for SignatureType { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for SignatureType { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -1397,6 +1406,7 @@ impl fmt::Display for ReasonForRevocation { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for ReasonForRevocation { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() @@ -1644,6 +1654,7 @@ impl fmt::Display for DataFormat { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for DataFormat { fn arbitrary(g: &mut G) -> Self { u8::arbitrary(g).into() diff --git a/openpgp/src/types/revocation_key.rs b/openpgp/src/types/revocation_key.rs index 498b4315..90e65ea7 100644 --- a/openpgp/src/types/revocation_key.rs +++ b/openpgp/src/types/revocation_key.rs @@ -1,3 +1,4 @@ +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::{ @@ -148,6 +149,7 @@ const REVOCATION_KEY_FLAG_SENSITIVE: u8 = 0x40; const REVOCATION_KEY_MASK_UNKNOWN: u8 = ! (REVOCATION_KEY_FLAG_MUST_BE_SET | REVOCATION_KEY_FLAG_SENSITIVE); +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for RevocationKey { fn arbitrary(g: &mut G) -> Self { RevocationKey { diff --git a/openpgp/src/types/server_preferences.rs b/openpgp/src/types/server_preferences.rs index f0b38f7e..b97cee58 100644 --- a/openpgp/src/types/server_preferences.rs +++ b/openpgp/src/types/server_preferences.rs @@ -1,5 +1,7 @@ use std::hash::{Hash, Hasher}; use std::fmt; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; /// Describes preferences regarding key servers. @@ -165,6 +167,7 @@ const KEYSERVER_PREFERENCE_NO_MODIFY: u8 = 0x80; /// Number of bytes with known flags. const KEYSERVER_PREFERENCES_N_KNOWN_BYTES: usize = 1; +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for KeyServerPreferences { fn arbitrary(g: &mut G) -> Self { Self::new(Vec::arbitrary(g)) diff --git a/openpgp/src/types/timestamp.rs b/openpgp/src/types/timestamp.rs index bd4f3bbb..6e4aebbd 100644 --- a/openpgp/src/types/timestamp.rs +++ b/openpgp/src/types/timestamp.rs @@ -3,6 +3,8 @@ use std::convert::{TryFrom, TryInto}; use std::fmt; use std::time::{SystemTime, Duration as SystemDuration, UNIX_EPOCH}; use std::u32; + +#[cfg(any(test, feature = "quickcheck"))] use quickcheck::{Arbitrary, Gen}; use crate::{ @@ -242,6 +244,7 @@ impl Timestamp { } } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Timestamp { fn arbitrary(g: &mut G) -> Self { Timestamp(u32::arbitrary(g)) @@ -562,6 +565,7 @@ impl Timestamp { pub(crate) const Y2106 : Timestamp = Timestamp(4291747200); } +#[cfg(any(test, feature = "quickcheck"))] impl Arbitrary for Duration { fn arbitrary(g: &mut G) -> Self { Duration(u32::arbitrary(g)) -- cgit v1.2.3