summaryrefslogtreecommitdiffstats
path: root/vendor/digest/src/dev.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/digest/src/dev.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/digest/src/dev.rs')
-rw-r--r--vendor/digest/src/dev.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/vendor/digest/src/dev.rs b/vendor/digest/src/dev.rs
new file mode 100644
index 000000000..2b68bdd4d
--- /dev/null
+++ b/vendor/digest/src/dev.rs
@@ -0,0 +1,78 @@
+//! Development-related functionality
+
+pub use blobby;
+
+mod fixed;
+mod mac;
+mod rng;
+mod variable;
+mod xof;
+
+pub use fixed::*;
+pub use mac::*;
+pub use variable::*;
+pub use xof::*;
+
+/// Define hash function test
+#[macro_export]
+#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
+macro_rules! new_test {
+ ($name:ident, $test_name:expr, $hasher:ty, $test_func:ident $(,)?) => {
+ #[test]
+ fn $name() {
+ use digest::dev::blobby::Blob2Iterator;
+ let data = include_bytes!(concat!("data/", $test_name, ".blb"));
+
+ for (i, row) in Blob2Iterator::new(data).unwrap().enumerate() {
+ let [input, output] = row.unwrap();
+ if let Some(desc) = $test_func::<$hasher>(input, output) {
+ panic!(
+ "\n\
+ Failed test №{}: {}\n\
+ input:\t{:?}\n\
+ output:\t{:?}\n",
+ i, desc, input, output,
+ );
+ }
+ }
+ }
+ };
+}
+
+/// Define [`Update`][crate::Update] impl benchmark
+#[macro_export]
+#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
+macro_rules! bench_update {
+ (
+ $init:expr;
+ $($name:ident $bs:expr;)*
+ ) => {
+ $(
+ #[bench]
+ fn $name(b: &mut Bencher) {
+ let mut d = $init;
+ let data = [0; $bs];
+
+ b.iter(|| {
+ digest::Update::update(&mut d, &data[..]);
+ });
+
+ b.bytes = $bs;
+ }
+ )*
+ };
+}
+
+/// Feed ~1 MiB of pseudorandom data to an updatable state.
+pub fn feed_rand_16mib<D: crate::Update>(d: &mut D) {
+ let buf = &mut [0u8; 1024];
+ let mut rng = rng::RNG;
+ let n = 16 * (1 << 20) / buf.len();
+ for _ in 0..n {
+ rng.fill(buf);
+ d.update(buf);
+ // additional byte, so size of feeded data
+ // will not be multiple of block size
+ d.update(&[42]);
+ }
+}