25 lines
586 B
Rust
25 lines
586 B
Rust
|
use sha2::{Digest, Sha256, Sha384, Sha512};
|
||
|
use std::fs::File;
|
||
|
use std::io;
|
||
|
|
||
|
pub fn hash_sha256(mut file: File) -> String {
|
||
|
let mut hasher = Sha256::new();
|
||
|
_ = io::copy(&mut file, &mut hasher);
|
||
|
|
||
|
return format!("{:x}", hasher.finalize());
|
||
|
}
|
||
|
|
||
|
pub fn hash_sha384(mut file: File) -> String {
|
||
|
let mut hasher = Sha384::new();
|
||
|
_ = io::copy(&mut file, &mut hasher);
|
||
|
|
||
|
return format!("{:x}", hasher.finalize());
|
||
|
}
|
||
|
|
||
|
pub fn hash_sha512(mut file: File) -> String {
|
||
|
let mut hasher = Sha512::new();
|
||
|
_ = io::copy(&mut file, &mut hasher);
|
||
|
|
||
|
return format!("{:x}", hasher.finalize());
|
||
|
}
|