use crate::error::Result;
pub mod utils {
use super::*;
pub async fn get_file_hash(file_path: &str, algorithm: &str) -> Result<String> {
let content = std::fs::read(file_path)?;
let hash = match algorithm {
"sha1" => {
use sha1::{Sha1, Digest};
let mut hasher = Sha1::new();
hasher.update(&content);
format!("{:x}", hasher.finalize())
}
"sha256" => {
use sha2::{Sha256, Digest};
let mut hasher = Sha256::new();
hasher.update(&content);
format!("{:x}", hasher.finalize())
}
_ => return Err(crate::error::LateJavaCoreError::Validation("Unsupported algorithm".to_string())),
};
Ok(hash)
}
}