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/// Return the stable account correlation label historically used by daemon
21/// logs without exposing the login account itself.
22///
23/// This is a display-only boundary. It must never be used for authentication,
24/// authorization, persistence identity, or cryptographic decisions.
25pub fn account_log_fingerprint(account: &str) -> String {
26 let digest = md5::compute(account.as_bytes());
27 let hex = format!("{digest:x}");
28 format!("acc-{}", &hex[..8])
29}
30
31/// Return the stable UID/customer-ID correlation label historically used by
32/// daemon logs without exposing the numeric login identity itself.
33///
34/// This is a display-only boundary. It must never be used for authentication,
35/// authorization, persistence identity, or cryptographic decisions.
36pub fn uid_log_fingerprint(uid: u64) -> String {
37 uid_text_log_fingerprint(&uid.to_string())
38}
39
40/// String-valued companion for JSON/form identity fields whose wire type is
41/// not guaranteed to be numeric. It shares the historical `uid-` namespace.
42pub fn uid_text_log_fingerprint(uid: &str) -> String {
43 let digest = md5::compute(uid.as_bytes());
44 let hex = format!("{digest:x}");
45 format!("uid-{}", &hex[..8])
46}
47
48#[cfg(test)]
49mod tests;