Decrypt an envelope produced by encrypt_page. page_id MUST
match the value passed at encrypt time — a mismatch surfaces as
KeyMismatch (GCM tag check failure) which is the correct
signal: an attacker swapping pages is functionally indistinguishable
from a wrong key.
Cheap sniff: does this byte slice look like an encrypted page?
Used by the pager (post-wiring) to decide whether to call
decrypt_page or treat the bytes as plaintext on a mixed
pre/post-encryption database.
Read the runtime encryption key from RED_ENCRYPTION_KEY /
RED_ENCRYPTION_KEY_FILE. Returns None when the operator
hasn’t enabled at-rest encryption. Errors are surfaced as Err
so a misconfigured key (typo, wrong length) fails boot loudly
instead of silently leaving plaintext on disk.
Parse a 32-byte AES key from a string — accepts hex (64 chars)
or unpadded base64 (43 or 44 chars). Tolerates leading/trailing
whitespace including newlines from kubectl create secret.