Skip to main content

layer_crypto/
sha.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4// NOTE:
5// The "Layer" project is no longer maintained or supported.
6// Its original purpose for personal SDK/APK experimentation and learning
7// has been fulfilled.
8//
9// Please use Ferogram instead:
10// https://github.com/ankit-chaubey/ferogram
11// Ferogram will receive future updates and development, although progress
12// may be slower.
13//
14// Ferogram is an async Telegram MTProto client library written in Rust.
15// Its implementation follows the behaviour of the official Telegram clients,
16// particularly Telegram Desktop and TDLib, and aims to provide a clean and
17// modern async interface for building Telegram clients and tools.
18
19/// Calculate the SHA-1 hash of one or more byte slices concatenated.
20#[macro_export]
21macro_rules! sha1 {
22    ( $( $x:expr ),+ ) => {{
23        use sha1::{Digest, Sha1};
24        let mut h = Sha1::new();
25        $( h.update($x); )+
26        let out: [u8; 20] = h.finalize().into();
27        out
28    }};
29}
30
31/// Calculate the SHA-256 hash of one or more byte slices concatenated.
32#[macro_export]
33macro_rules! sha256 {
34    ( $( $x:expr ),+ ) => {{
35        use sha2::{Digest, Sha256};
36        let mut h = Sha256::new();
37        $( h.update($x); )+
38        let out: [u8; 32] = h.finalize().into();
39        out
40    }};
41}