Skip to main content

ferogram_crypto/
sha.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2//
3// ferogram: async Telegram MTProto client in Rust
4// https://github.com/ankit-chaubey/ferogram
5//
6// Licensed under either the MIT License or the Apache License 2.0.
7// See the LICENSE-MIT or LICENSE-APACHE file in this repository:
8// https://github.com/ankit-chaubey/ferogram
9//
10// Feel free to use, modify, and share this code.
11// Please keep this notice when redistributing.
12
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}