script_helpers/
sha256_hash_file_to_string.rs

1use sha2::{Digest, Sha256};
2use std::io::{self};
3use std::path::Path;
4
5use crate::must_open_file::must_open_file;
6
7pub fn sha256_hash_file_to_string(file_path: &Path) -> String {
8    let mut hasher = Sha256::new();
9    if let Err(err) = io::copy(&mut must_open_file(file_path), &mut hasher) {
10        eprintln!("Could not hash file: {}", file_path.to_string_lossy());
11        eprintln!("Error: {}", err);
12    };
13    let hash = hasher.finalize();
14    hex::encode(hash)
15}