pub fn decode_envelope_from_bytes(
bytes: &[u8],
hmac_key: &[u8; 32],
) -> Result<Vec<u8>, ArtifactError>Expand description
Decode the unified artifact-store envelope from bytes, returning
the inner payload after verifying the HMAC in constant time and the
BLAKE3 content hash as defence-in-depth.
Counterpart to encode_envelope_to_vec. Used by the snapshot
crate’s default SnapshotReader::restore to detect and consume the
v0.4 envelope before falling through to the legacy v3 / v2 readers.
Returns ArtifactError::BadMagic if the leading 16 bytes do not
match ARTIFACT_MAGIC — callers rely on that variant to know they
should try a different envelope shape, so the magic check is the
first thing this function does (cheap, allocation-free).
Validation order:
- Minimum length, then magic and version (cheap, before any keyed work).
- HMAC verification in constant time over
magic || version || content_hash || zstd_body. Failure returnsArtifactError::BadHmacwithout touching the decoded payload. - zstd decompression with a
MAX_DECOMPRESSED_LENcap, mirroring the disk store’s zip-bomb defence. - Recompute the content hash and compare to the header value — catches a writer bug that hashed the wrong bytes even if the HMAC verified (impossible without key leak, but cheap to check).