futu_core/log_redact.rs
1/// Return a stable, non-reversible label for endpoint strings that may contain
2/// backend IPs, broker IPs, or private domains.
3///
4/// This is for log correlation only. It deliberately avoids adding crypto
5/// dependencies to `futu-core`; callers must not use the output for security
6/// decisions.
7pub fn endpoint_log_fingerprint(endpoint: &str) -> String {
8 const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
9 const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
10
11 let mut hash = FNV_OFFSET;
12 for byte in endpoint.as_bytes() {
13 hash ^= u64::from(*byte);
14 hash = hash.wrapping_mul(FNV_PRIME);
15 }
16
17 format!("endpoint-{hash:012x}", hash = hash & 0x0000_ffff_ffff_ffff)
18}
19
20#[cfg(test)]
21mod tests;