Expand description
Small security helpers: secure random tokens and constant-time comparison
use ullun::security::{constant_time_eq, random_token};
let token = random_token(16).unwrap(); // 128 bits as 32 hex characters
assert_eq!(token.len(), 32);
assert!(constant_time_eq(token.as_bytes(), token.as_bytes()));Enums§
- Resolve
Error - Why
resolve_publicrefused
Functions§
- constant_
time_ eq - Compare two byte strings without returning early on the first difference, so the time taken does not reveal how much of a secret was guessed right. Different lengths compare unequal (the length itself is not hidden).
- is_
public_ ip - Whether
ipis an address on the public internet. Loopback, private (RFC 1918, unique local), link-local, CGNAT, multicast, documentation, benchmarking and reserved ranges are not, and neither are IPv6 addresses that embed such an IPv4 address (IPv4-mapped, NAT64, 6to4). - random_
alphanumeric - Random string of
lencharacters from[A-Za-z0-9], uniformly distributed (rejection sampling). Handy for short public ids; for secrets preferrandom_token. - random_
bytes lenbytes from the operating system’s CSPRNG- random_
token - Unguessable token:
bytesrandom bytes as lowercase hex (2 * bytescharacters). Use at least 16 bytes for session ids and secrets. - resolve_
public - Resolve
hostand vet the answers before connecting (SSRF protection)