use std::path::{Path, PathBuf};
pub fn sif_path(sif_dir: &Path, reference: &str) -> PathBuf {
let safe: String = reference
.chars()
.map(|c| {
if c.is_alphanumeric() || c == '.' || c == '-' {
c
} else {
'_'
}
})
.collect();
sif_dir.join(format!("{safe}.sif"))
}
pub fn sif_path_for_digest(sif_dir: &Path, digest: &str) -> PathBuf {
let safe: String = digest
.chars()
.map(|c| if c.is_alphanumeric() { c } else { '_' })
.collect();
sif_dir.join(format!("{safe}.sif"))
}
pub fn file_sha256(path: &Path) -> std::io::Result<String> {
use sha2::{Digest, Sha256};
let bytes = std::fs::read(path)?;
let hash = Sha256::digest(&bytes);
let hex: String = hash.iter().map(|b| format!("{b:02x}")).collect();
Ok(format!("sha256:{hex}"))
}