diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-07-26 12:28:29 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-12-13 19:01:14 +0100 |
commit | 321b0cc381f3c44f81cfc4a9cf502be169262d14 (patch) | |
tree | 20c5ee6c7a551872a5037d89331b642e6190f4a8 /openpgp/src/crypto | |
parent | a79a35952cb2cf92bd6ba60fa7df057fb2eae1d2 (diff) |
ipc, openpgp: Bump quickcheck to 1.0.3.
- Adapt to the new API:
- Gen is now a struct, not a Trait, and replaces StdThreadGen.
- The rand re-export has been removed. As a consequence, we need
our own function to generate an arbitrary value from a range.
Diffstat (limited to 'openpgp/src/crypto')
-rw-r--r-- | openpgp/src/crypto/mpi.rs | 28 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 20 |
2 files changed, 27 insertions, 21 deletions
diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index ecff49ac..c586e3fa 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -22,8 +22,6 @@ use std::borrow::Cow; #[cfg(test)] use quickcheck::{Arbitrary, Gen}; -#[cfg(test)] -use rand::Rng; use crate::types::{ Curve, @@ -259,7 +257,7 @@ impl Hash for MPI { #[cfg(test)] impl Arbitrary for MPI { - fn arbitrary<G: Gen>(g: &mut G) -> Self { + fn arbitrary(g: &mut Gen) -> Self { loop { let buf = <Vec<u8>>::arbitrary(g); @@ -580,9 +578,11 @@ impl Hash for PublicKey { #[cfg(test)] impl Arbitrary for PublicKey { - fn arbitrary<G: Gen>(g: &mut G) -> Self { + fn arbitrary(g: &mut Gen) -> Self { use self::PublicKey::*; - match g.gen_range(0, 6) { + use crate::arbitrary_helper::gen_arbitrary_from_range; + + match gen_arbitrary_from_range(0..6, g) { 0 => RSA { e: MPI::arbitrary(g), n: MPI::arbitrary(g), @@ -842,8 +842,10 @@ impl Hash for SecretKeyMaterial { #[cfg(test)] impl Arbitrary for SecretKeyMaterial { - fn arbitrary<G: Gen>(g: &mut G) -> Self { - match g.gen_range(0, 6) { + fn arbitrary(g: &mut Gen) -> Self { + use crate::arbitrary_helper::gen_arbitrary_from_range; + + match gen_arbitrary_from_range(0..6, g) { 0 => SecretKeyMaterial::RSA { d: MPI::arbitrary(g).into(), p: MPI::arbitrary(g).into(), @@ -969,8 +971,10 @@ impl Hash for Ciphertext { #[cfg(test)] impl Arbitrary for Ciphertext { - fn arbitrary<G: Gen>(g: &mut G) -> Self { - match g.gen_range(0, 3) { + fn arbitrary(g: &mut Gen) -> Self { + use crate::arbitrary_helper::gen_arbitrary_from_range; + + match gen_arbitrary_from_range(0..3, g) { 0 => Ciphertext::RSA { c: MPI::arbitrary(g), }, @@ -1062,8 +1066,10 @@ impl Hash for Signature { #[cfg(test)] impl Arbitrary for Signature { - fn arbitrary<G: Gen>(g: &mut G) -> Self { - match g.gen_range(0, 4) { + fn arbitrary(g: &mut Gen) -> Self { + use crate::arbitrary_helper::gen_arbitrary_from_range; + + match gen_arbitrary_from_range(0..4, g) { 0 => Signature::RSA { s: MPI::arbitrary(g), }, diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 6e618e0c..0644816c 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -17,8 +17,6 @@ use std::fmt; #[cfg(test)] use quickcheck::{Arbitrary, Gen}; -#[cfg(test)] -use rand::Rng; /// String-to-Key (S2K) specifiers. /// @@ -366,21 +364,23 @@ impl fmt::Display for S2K { #[cfg(test)] impl Arbitrary for S2K { - fn arbitrary<G: Gen>(g: &mut G) -> Self { + fn arbitrary(g: &mut Gen) -> Self { + use crate::arbitrary_helper::gen_arbitrary_from_range; + #[allow(deprecated)] - match g.gen_range(0, 7) { + match gen_arbitrary_from_range(0..7, g) { 0 => S2K::Simple{ hash: HashAlgorithm::arbitrary(g) }, 1 => S2K::Salted{ hash: HashAlgorithm::arbitrary(g), - salt: g.gen(), + salt: [<u8>::arbitrary(g); 8], }, 2 => S2K::Iterated{ hash: HashAlgorithm::arbitrary(g), - salt: g.gen(), - hash_bytes: S2K::nearest_hash_count(g.gen()), + salt: [<u8>::arbitrary(g); 8], + hash_bytes: S2K::nearest_hash_count(Arbitrary::arbitrary(g)), }, 3 => S2K::Private { - tag: g.gen_range(100, 111), + tag: gen_arbitrary_from_range(100..111, g), parameters: Option::<Vec<u8>>::arbitrary(g).map(|v| v.into()), }, 4 => S2K::Unknown { @@ -388,11 +388,11 @@ impl Arbitrary for S2K { parameters: Option::<Vec<u8>>::arbitrary(g).map(|v| v.into()), }, 5 => S2K::Unknown { - tag: g.gen_range(4, 100), + tag: gen_arbitrary_from_range(4..100, g), parameters: Option::<Vec<u8>>::arbitrary(g).map(|v| v.into()), }, 6 => S2K::Unknown { - tag: g.gen_range(111, 256) as u8, + tag: gen_arbitrary_from_range(111..256, g) as u8, parameters: Option::<Vec<u8>>::arbitrary(g).map(|v| v.into()), }, _ => unreachable!(), |