Skip to main content

layer_crypto/
sha.rs

1/// Calculate the SHA-1 hash of one or more byte slices concatenated.
2#[macro_export]
3macro_rules! sha1 {
4    ( $( $x:expr ),+ ) => {{
5        use sha1::{Digest, Sha1};
6        let mut h = Sha1::new();
7        $( h.update($x); )+
8        let out: [u8; 20] = h.finalize().into();
9        out
10    }};
11}
12
13/// Calculate the SHA-256 hash of one or more byte slices concatenated.
14#[macro_export]
15macro_rules! sha256 {
16    ( $( $x:expr ),+ ) => {{
17        use sha2::{Digest, Sha256};
18        let mut h = Sha256::new();
19        $( h.update($x); )+
20        let out: [u8; 32] = h.finalize().into();
21        out
22    }};
23}