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// If you use or modify this code, keep this notice at the top of your file
8// and include the LICENSE-MIT or LICENSE-APACHE file from this repository:
9// https://github.com/ankit-chaubey/ferogram
10
11#[macro_export]
12macro_rules! sha1 {
13 ( $( $x:expr ),+ ) => {{
14 use sha1::{Digest, Sha1};
15 let mut h = Sha1::new();
16 $( h.update($x); )+
17 let out: [u8; 20] = h.finalize().into();
18 out
19 }};
20}
21
22/// Calculate the SHA-256 hash of one or more byte slices concatenated.
23#[macro_export]
24macro_rules! sha256 {
25 ( $( $x:expr ),+ ) => {{
26 use sha2::{Digest, Sha256};
27 let mut h = Sha256::new();
28 $( h.update($x); )+
29 let out: [u8; 32] = h.finalize().into();
30 out
31 }};
32}