bash_hash/
variants.rs

1use digest::{array::ArraySize, crypto_common::BlockSizes, typenum};
2
3/// Sealed trait to prevent external implementations.
4pub trait Sealed {}
5
6/// Trait implemented for output sizes supported by `bash-hash`.
7///
8/// Supported output sizes form the following list: U4, U8, ..., U60, U64.
9pub trait OutputSize: ArraySize + Sealed {
10    /// Block size in bytes computed as `192 - 2 * OutputSize`.
11    type BlockSize: BlockSizes;
12}
13
14macro_rules! impl_sizes {
15    ($($variant:ident, $block_size:ident;)*) => {
16        $(
17            impl Sealed for typenum::$variant {}
18
19            impl OutputSize for typenum::$variant {
20                type BlockSize = typenum::$block_size;
21            }
22        )*
23    };
24}
25
26impl_sizes!(
27    U4,  U184;
28    U8,  U176;
29    U12, U168;
30    U16, U160;
31    U20, U152;
32    U24, U144;
33    U28, U136;
34    U32, U128;
35    U36, U120;
36    U40, U112;
37    U44, U104;
38    U48, U96;
39    U52, U88;
40    U56, U80;
41    U60, U72;
42    U64, U64;
43);