Expand description
Minimal HMAC-SHA256 used across the CMS for short signed tokens (view-restriction grants, signed rendition URLs).
The framework’s CSRF module has an hmac_sha256 but it’s
pub(crate); rather than pull the hmac + sha2 crates twice, we
implement HMAC over the sha2 crate the workspace already depends
on. One shared impl so the two call sites can’t drift.
Constants§
- GENERATED_
KEY_ PATH - Where the CMS keeps the key it generates when
RCMS_SECRET_KEYis not set, relative to the working directory. Several replicas need either the env var or this file on shared storage, so they sign alike.
Functions§
- constant_
time_ eq - Constant-time comparison of two byte slices — use when checking a supplied MAC against the expected one so timing doesn’t leak how many leading bytes matched.
- derived_
key - A key for one purpose, derived from
secret, so a value signed for one feature never verifies in another. - hmac_
sha256_ hex - HMAC-SHA256(
key,msg) as lowercase hex (64 chars). Callers that want a shorter token truncate the result (a prefix of a hex HMAC is itself a valid MAC at reduced bit-strength). - secret
- The CMS signing secret:
set_secret’s key, elseRCMS_SECRET_KEY, else a 32-byte key generated once and kept atGENERATED_KEY_PATH, so every signed feature works without configuration. - set_
secret - Set the CMS signing secret. Call once at startup, before anything is
served; the key must be stable across restarts. Sourced from the
RCMS_SECRET_KEYenv var, thenGENERATED_KEY_PATH, when this isn’t called.