Skip to main content

user_hash

Function user_hash 

Source
pub fn user_hash(key: &str) -> String
Expand description

Compute the per-user directory name for ~/.trustee/users/{hash}/.

Single definition of the user→hash mapping: SHA-256 of key, first 8 bytes interpreted big-endian, formatted as 16 lowercase hex chars.

Two input domains feed this one function:

  • Web/API path: the authenticated user_key (JWT sub claim, or dev:email in dev mode) — see trustee-api’s ServerState.
  • CLI path: the OS username ($USER / $USERNAME, falling back to "unknown") — see the trustee binary’s compute_user_hash.

The two domains intentionally produce different hashes for the same directory tree; consolidating the algorithm here guarantees they cannot drift apart.