ophelia_quickcheck/
lib.rs

1use ophelia_hasher::HashValue;
2
3use quickcheck::{Arbitrary, Gen};
4
5#[macro_export]
6macro_rules! impl_quickcheck_for_privatekey {
7    ($priv_key:ident) => {
8        impl quickcheck::Arbitrary for $priv_key {
9            fn arbitrary(g: &mut quickcheck::Gen) -> $priv_key {
10                let octet32 = ophelia_quickcheck::Octet32::arbitrary(g);
11
12                $priv_key::try_from(octet32.as_ref()).unwrap()
13            }
14        }
15    };
16}
17
18// TODO: SeedableRng?
19#[derive(Clone, Debug)]
20pub struct Octet32([u8; 32]);
21
22impl AsRef<[u8]> for Octet32 {
23    fn as_ref(&self) -> &[u8] {
24        &self.0
25    }
26}
27
28impl Arbitrary for Octet32 {
29    fn arbitrary(g: &mut Gen) -> Octet32 {
30        let mut octet32 = [0u8; 32];
31
32        for octet in &mut octet32 {
33            *octet = u8::arbitrary(g);
34        }
35
36        Octet32(octet32)
37    }
38}
39
40#[derive(Clone, Debug)]
41pub struct AHashValue(HashValue);
42
43impl AHashValue {
44    pub fn into_inner(self) -> HashValue {
45        self.0
46    }
47}
48
49impl quickcheck::Arbitrary for AHashValue {
50    fn arbitrary(g: &mut quickcheck::Gen) -> AHashValue {
51        let mut hash = [0u8; 32];
52
53        for byte in &mut hash {
54            *byte = u8::arbitrary(g);
55        }
56
57        AHashValue(HashValue::from_bytes_unchecked(hash))
58    }
59}