devimg_core/hash.rs
1use std::fs;
2use std::path::Path;
3
4use crate::{DevimgError, Result};
5
6pub fn hash_bytes(bytes: &[u8]) -> String {
7 format!("blake3:{}", blake3::hash(bytes).to_hex())
8}
9
10pub fn hash_file(path: &Path) -> Result<String> {
11 let bytes = fs::read(path).map_err(|source| DevimgError::io(path, source))?;
12 Ok(hash_bytes(&bytes))
13}