CI / Check (push) Has been skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Successful in 3m46s
CI / Deploy Dashboard (push) Successful in 2m53s
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Successful in 2m2s
33 lines
978 B
Rust
33 lines
978 B
Rust
//! 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"])
|
|
);
|
|
}
|
|
}
|