Skip to main content

uid_hex

Function uid_hex 

Source
pub fn uid_hex(bytes: usize) -> String
Expand description

In-process-unique, restart-decorrelated hex id.

Combines a monotonic per-process counter (bijective — guarantees no two calls in the same process ever collide) with a random per-process salt drawn once from the OS RNG (decorrelates ids across restarts, so a long-lived id from a previous process run can’t be mistaken for one minted by the current process). The high bits of the 128-bit XOR are dominated by the salt (a process fingerprint); the low bits change on every call.

Not unguessable. The counter is a public, low-entropy sequence once the salt leaks (e.g. via any single id from this process) — never use this for bearer credentials, signing nonces, or anything else that must resist an adversary who can observe some ids and guess others. Use secure_hex for that.