1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// Macros used for unit testing.

/// Instantiate the given test functions once for each built-in provider.
///
/// The selected provider module is bound as `provider`; you can rely on this
/// having the union of the items common to the `crypto::ring` and
/// `crypto::aws_lc_rs` modules.
macro_rules! test_for_each_provider {
    ($($tt:tt)+) => {
        #[cfg(all(test, feature = "ring"))]
        mod test_with_ring {
            use crate::crypto::ring as provider;
            $($tt)+
        }

        #[cfg(all(test, feature = "aws_lc_rs"))]
        mod test_with_aws_lc_rs {
            use crate::crypto::aws_lc_rs as provider;
            $($tt)+
        }
    };
}

/// Instantiate the given benchmark functions once for each built-in provider.
///
/// The selected provider module is bound as `provider`; you can rely on this
/// having the union of the items common to the `crypto::ring` and
/// `crypto::aws_lc_rs` modules.
macro_rules! bench_for_each_provider {
    ($($tt:tt)+) => {
        #[cfg(all(bench, feature = "ring"))]
        mod bench_with_ring {
            use crate::crypto::ring as provider;
            $($tt)+
        }

        #[cfg(all(bench, feature = "aws_lc_rs"))]
        mod bench_with_aws_lc_rs {
            use crate::crypto::aws_lc_rs as provider;
            $($tt)+
        }
    };
}

test_for_each_provider! {
    #[test]
    fn test_each_provider() {
        std::println!("provider is {:?}", provider::default_provider());
    }
}

bench_for_each_provider! {
    #[bench]
    fn bench_each_provider(b: &mut test::Bencher) {
        b.iter(|| provider::default_provider());
    }
}