cert-x-gen 1.9.2

Advanced Multi-Language Security Scanning Engine
Documentation
// Shared by the build-time manifest generator and runtime materializer.
use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
use std::path::{Component, Path};

pub(crate) fn hash(bytes: &[u8]) -> String {
    hex::encode(Sha256::digest(bytes))
}
pub(crate) fn inventory_digest(files: &BTreeMap<String, String>) -> String {
    let mut hasher = Sha256::new();
    for (path, digest) in files {
        hasher.update(path.as_bytes());
        hasher.update([0]);
        hasher.update(digest.as_bytes());
        hasher.update(b"\n");
    }
    hex::encode(hasher.finalize())
}
pub(crate) fn relative(path: &Path) -> bool {
    !path.as_os_str().is_empty() && path.components().all(|c| matches!(c, Component::Normal(_)))
}
pub(crate) fn excluded(path: &Path) -> bool {
    path.components().any(|c| {
        let s = c.as_os_str().to_string_lossy();
        s.starts_with('.')
            || s.starts_with("__pycache__")
            || s.ends_with(".pyc")
            || s.ends_with(".pyo")
            || s == "report.json"
    })
}