astmap-core 0.0.2

Core domain types and logic for astmap
Documentation
use sha2::{Digest, Sha256};

pub fn sha256(content: &str) -> String {
    let mut hasher = Sha256::new();
    hasher.update(content.as_bytes());
    let result = hasher.finalize();
    result.iter().map(|b| format!("{:02x}", b)).collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_sha256_deterministic() {
        let h1 = sha256("hello world");
        let h2 = sha256("hello world");
        assert_eq!(h1, h2);
        assert_eq!(h1.len(), 64); // SHA-256 = 64 hex chars
    }

    #[test]
    fn test_sha256_different_input() {
        let h1 = sha256("hello");
        let h2 = sha256("world");
        assert_ne!(h1, h2);
    }
}