diff options
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 14 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 7 |
2 files changed, 18 insertions, 3 deletions
diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index c31d6fa2..d60d15e2 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -372,18 +372,26 @@ impl fmt::Display for S2K { #[cfg(test)] impl Arbitrary for S2K { fn arbitrary(g: &mut Gen) -> Self { - use crate::arbitrary_helper::gen_arbitrary_from_range; + use crate::arbitrary_helper::*; #[allow(deprecated)] match gen_arbitrary_from_range(0..7, g) { 0 => S2K::Simple{ hash: HashAlgorithm::arbitrary(g) }, 1 => S2K::Salted{ hash: HashAlgorithm::arbitrary(g), - salt: [<u8>::arbitrary(g); 8], + salt: { + let mut salt = [0u8; 8]; + arbitrary_slice(g, &mut salt); + salt + }, }, 2 => S2K::Iterated{ hash: HashAlgorithm::arbitrary(g), - salt: [<u8>::arbitrary(g); 8], + salt: { + let mut salt = [0u8; 8]; + arbitrary_slice(g, &mut salt); + salt + }, hash_bytes: S2K::nearest_hash_count(Arbitrary::arbitrary(g)), }, 3 => S2K::Private { diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index d6521e4f..38d2b9e4 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -374,4 +374,11 @@ mod arbitrary_helper { panic!() } } + + pub(crate) fn arbitrary_slice<T>(g: &mut Gen, s: &mut [T]) + where + T: Arbitrary, + { + s.iter_mut().for_each(|p| *p = Arbitrary::arbitrary(g)); + } } |