Skip to content

Commit 441824a

Browse files
authored
digest: simplify test macros using stringify! (#1958)
Names of test functions and names of associated KAT file usually match, so it's worth to simplify the macro to reduce amount of duplication at call sites.
1 parent 7bbc010 commit 441824a

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

digest/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `CtVariableCoreWrapper` renamed to `CtOutWrapper` ([#1799])
1818
- Removed the OID type parameter from `CtOutWrapper` ([#1799])
1919
- Implementations of the `SerializableState` trait ([#1953])
20+
- `new_test!` and `new_mac_test!` macros ([#1958])
2021

2122
### Removed
2223
- `Mac::new`, `Mac::new_from_slice`, and `Mac::generate_key` methods ([#1173])
@@ -31,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3132
[#1809]: https://github.com/RustCrypto/traits/pull/1809
3233
[#1820]: https://github.com/RustCrypto/traits/pull/1820
3334
[#1953]: https://github.com/RustCrypto/traits/pull/1953
35+
[#1958]: https://github.com/RustCrypto/traits/pull/1958
3436

3537
## 0.10.7 (2023-05-19)
3638
### Changed

digest/src/dev.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub struct TestVector {
2727
/// Define hash function test
2828
#[macro_export]
2929
macro_rules! new_test {
30-
($name:ident, $test_name:expr, $hasher:ty, $test_fn:ident $(,)?) => {
30+
($name:ident, $hasher:ty, $test_fn:ident $(,)?) => {
3131
#[test]
3232
fn $name() {
3333
use $crate::dev::TestVector;
3434

3535
$crate::dev::blobby::parse_into_structs!(
36-
include_bytes!(concat!("data/", $test_name, ".blb"));
36+
include_bytes!(concat!("data/", stringify!($name), ".blb"));
3737
static TEST_VECTORS: &[TestVector { input, output }];
3838
);
3939

digest/src/dev/mac.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,22 @@ pub fn reset_mac_test<M: Mac + KeyInit + FixedOutputReset + Clone>(
118118
/// Define MAC test
119119
#[macro_export]
120120
macro_rules! new_mac_test {
121-
($name:ident, $test_name:expr, $mac:ty, $test_fn:ident $(,)?) => {
122-
digest::new_mac_test!($name, $test_name, $mac, $test_fn, $crate::dev::MacTruncSide::None);
121+
($name:ident, $mac:ty, $test_fn:ident $(,)?) => {
122+
digest::new_mac_test!($name, $mac, $test_fn, $crate::dev::MacTruncSide::None);
123123
};
124-
($name:ident, $test_name:expr, $mac:ty, $test_fn:ident, trunc_left $(,)?) => {
125-
digest::new_mac_test!($name, $test_name, $mac, $test_fn, $crate::dev::MacTruncSide::Left);
124+
($name:ident, $mac:ty, $test_fn:ident, trunc_left $(,)?) => {
125+
digest::new_mac_test!($name, $mac, $test_fn, $crate::dev::MacTruncSide::Left);
126126
};
127-
($name:ident, $test_name:expr, $mac:ty, $test_fn:ident, trunc_right $(,)?) => {
128-
digest::new_mac_test!($name, $test_name, $mac, $test_fn, $crate::dev::MacTruncSide::Right);
127+
($name:ident, $mac:ty, $test_fn:ident, trunc_right $(,)?) => {
128+
digest::new_mac_test!($name, $mac, $test_fn, $crate::dev::MacTruncSide::Right);
129129
};
130-
($name:ident, $test_name:expr, $mac:ty, $test_fn:ident, $trunc:expr $(,)?) => {
130+
($name:ident, $mac:ty, $test_fn:ident, $trunc:expr $(,)?) => {
131131
#[test]
132132
fn $name() {
133133
use digest::dev::MacTestVector;
134134

135135
$crate::dev::blobby::parse_into_structs!(
136-
include_bytes!(concat!("data/", $test_name, ".blb"));
136+
include_bytes!(concat!("data/", stringify!($name), ".blb"));
137137
static TEST_VECTORS: &[MacTestVector { key, input, tag }];
138138
);
139139

digest/src/dev/rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) const RNG: XorShiftRng = XorShiftRng {
1010
w: Wrapping(0xB0AD_B4F3),
1111
};
1212

13-
/// Xorshift RNG instance/
13+
/// Xorshift RNG instance
1414
pub(crate) struct XorShiftRng {
1515
x: Wrapping<u32>,
1616
y: Wrapping<u32>,

0 commit comments

Comments
 (0)