late-java-core 2.2.9

A Rust library for launching Minecraft Java Edition
use crate::error::Result;

/// Utilidades generales
pub mod utils {
    use super::*;
    
    /// Obtener hash de archivo
    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)
    }
}