Skip to content

Commit a6ba93c

Browse files
committed
tweak tests
1 parent 2ae9b4b commit a6ba93c

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

bash-prg-hash/tests/mod.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@ use hex_literal::hex;
77
use std::fmt::Debug;
88

99
#[derive(Debug, Clone, Copy)]
10-
pub struct TestVector {
11-
pub customization: &'static [u8],
12-
pub input: &'static [u8],
13-
pub output: &'static [u8],
10+
struct TestVector {
11+
customization: &'static [u8],
12+
input: &'static [u8],
13+
output: &'static [u8],
1414
}
1515

16-
pub(crate) fn bash_prg_hash_test<D>(
16+
fn bash_prg_hash_test<D: TryCustomizedInit + ExtendableOutput + Clone>(
1717
&TestVector {
1818
customization,
1919
input,
2020
output,
2121
}: &TestVector,
22-
) -> Result<(), &'static str>
23-
where
24-
D: TryCustomizedInit + ExtendableOutput + Clone,
25-
<D as TryCustomizedInit>::Error: Debug,
26-
{
27-
let mut hasher = D::try_new_customized(customization).unwrap();
22+
) -> Result<(), &'static str> {
23+
let Ok(mut hasher) = D::try_new_customized(customization) else {
24+
return Err("initialization error");
25+
};
2826
let mut buf = [0u8; 1024];
2927
let buf = &mut buf[..output.len()];
3028
// Test that it works when accepting the message all at once
@@ -37,7 +35,9 @@ where
3735

3836
// Test that it works when accepting the message in chunks
3937
for n in 1..core::cmp::min(17, input.len()) {
40-
let mut hasher = D::try_new_customized(customization).unwrap();
38+
let Ok(mut hasher) = D::try_new_customized(customization) else {
39+
return Err("initialization error");
40+
};
4141
for chunk in input.chunks(n) {
4242
hasher.update(chunk);
4343
}
@@ -100,23 +100,6 @@ macro_rules! test_bash_prg_rand {
100100
};
101101
}
102102

103-
// Test from the https://apmi.bsu.by/assets/files/std/met-v10.zip
104-
macro_rules! test_bash_prg_million {
105-
($name:ident, $hasher:ty, $expected:expr) => {
106-
#[test]
107-
fn $name() {
108-
let mut h = <$hasher>::default();
109-
let block = [0x61u8; 1000];
110-
for _ in 0..1000 {
111-
h.update(&block);
112-
}
113-
let mut output = [0u8; 64];
114-
h.finalize_xof_into(&mut output);
115-
assert_eq!(&output[..$expected.len()], $expected);
116-
}
117-
};
118-
}
119-
120103
test_bash_prg_rand!(
121104
bashprg1282_rand,
122105
BashPrgHash1282,
@@ -144,6 +127,23 @@ test_bash_prg_rand!(
144127
)
145128
);
146129

130+
// Test from the https://apmi.bsu.by/assets/files/std/met-v10.zip
131+
macro_rules! test_bash_prg_million {
132+
($name:ident, $hasher:ty, $expected:expr) => {
133+
#[test]
134+
fn $name() {
135+
let mut h = <$hasher>::default();
136+
let block = [0x61u8; 1000];
137+
for _ in 0..1000 {
138+
h.update(&block);
139+
}
140+
let mut output = [0u8; 64];
141+
h.finalize_xof_into(&mut output);
142+
assert_eq!(&output[..$expected.len()], $expected);
143+
}
144+
};
145+
}
146+
147147
// BASH.PRG.HASH128.5
148148
test_bash_prg_million!(
149149
bashprg1282_million,

0 commit comments

Comments
 (0)