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