scancode_rust/utils/hash.rs
1use md5::{Digest as Md5Digest, Md5};
2use sha1::Sha1;
3use sha2::Sha256;
4
5/// Calculate SHA1 hash of content and return it as a hex string
6pub fn calculate_sha1(content: &[u8]) -> String {
7 let digest = Sha1::digest(content);
8 format!("{:x}", digest)
9}
10
11/// Calculate MD5 hash of content and return it as a hex string
12pub fn calculate_md5(content: &[u8]) -> String {
13 let digest = Md5::digest(content);
14 format!("{:x}", digest)
15}
16
17/// Calculate SHA256 hash of content and return it as a hex string
18pub fn calculate_sha256(content: &[u8]) -> String {
19 let digest = Sha256::digest(content);
20 format!("{:x}", digest)
21}