Skip to main content

hash_security_context

Function hash_security_context 

Source
pub fn hash_security_context(ctx: Option<&SecurityContext>) -> u64
Expand description

Hash of the principal a cached result belongs to.

Covers the fields that can change which rows a request is entitled to: user_id, roles, tenant_id, scopes and attributes (custom RLS policies can key on any attribute, e.g. “department” or “region”). Roles and scopes are sorted and attribute keys ordered, so the order a token lists them in does not fork the entry; every collection is length-prefixed, so a value cannot slide from one field into the next.

Not hashed: request_id, ip_address, authenticated_at, expires_at, issuer, audience — they do not change what the principal may see.

Returns 0 when no security context is present (all anonymous requests share one scope).