返回 CodeWhale
hashing.rs
根目录 / crates / tui / src / hashing.rs
1 use sha2::{Digest, Sha256};
2
3 pub(crate) fn sha256_hex(bytes: impl AsRef<[u8]>) -> String {
4 hex_bytes(Sha256::digest(bytes.as_ref()))
5 }
6
7 pub(crate) fn hex_bytes(bytes: impl AsRef<[u8]>) -> String {
8 let bytes = bytes.as_ref();
9 let mut out = String::with_capacity(bytes.len() * 2);
10 for byte in bytes {
11 use std::fmt::Write as _;
12 let _ = write!(&mut out, "{byte:02x}");
13 }
14 out
15 }
16
16 lines RUST