//! Finding fingerprint helper (a SHA-256 over the salient parts), shared by the //! probe modules for stable dedup keys. Mirrors the agent's `dedup` helper. use sha2::{Digest, Sha256}; /// A stable fingerprint over the given parts (order-sensitive, separated so /// `["ab","c"]` and `["a","bc"]` differ). pub fn compute_fingerprint(parts: &[&str]) -> String { let mut hasher = Sha256::new(); for part in parts { hasher.update(part.as_bytes()); hasher.update(b"|"); } hex::encode(hasher.finalize()) } #[cfg(test)] mod tests { use super::*; #[test] fn deterministic_and_hex() { let a = compute_fingerprint(&["repo", "rule", "1"]); assert_eq!(a, compute_fingerprint(&["repo", "rule", "1"])); assert_eq!(a.len(), 64); assert!(a.chars().all(|c| c.is_ascii_hexdigit())); assert_ne!( compute_fingerprint(&["ab", "c"]), compute_fingerprint(&["a", "bc"]) ); } }