Skip to main content

ferogram_crypto/
sha.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4// ferogram: async Telegram MTProto client in Rust
5// https://github.com/ankit-chaubey/ferogram
6//
7//
8// If you use or modify this code, keep this notice at the top of your file
9// and include the LICENSE-MIT or LICENSE-APACHE file from this repository:
10// https://github.com/ankit-chaubey/ferogram
11
12/// Calculate the SHA-1 hash of one or more byte slices concatenated.
13#[macro_export]
14macro_rules! sha1 {
15    ( $( $x:expr ),+ ) => {{
16        use sha1::{Digest, Sha1};
17        let mut h = Sha1::new();
18        $( h.update($x); )+
19        let out: [u8; 20] = h.finalize().into();
20        out
21    }};
22}
23
24/// Calculate the SHA-256 hash of one or more byte slices concatenated.
25#[macro_export]
26macro_rules! sha256 {
27    ( $( $x:expr ),+ ) => {{
28        use sha2::{Digest, Sha256};
29        let mut h = Sha256::new();
30        $( h.update($x); )+
31        let out: [u8; 32] = h.finalize().into();
32        out
33    }};
34}