Skip to main content

detach_payload

Function detach_payload 

Source
pub fn detach_payload(data: &[u8]) -> Result<DetachedCorim>
Expand description

Split a bundled (payload-embedded) COSE_Sign1 into its CoRIM document payload and a detached COSE_Sign1 signature.

A signed CoRIM is Tag(18) [ protected, unprotected, payload, signature ] where payload is a bstr containing the CBOR-encoded CoRIM document.

This function:

  1. Decodes the COSE_Sign1 with corim::types::signed::decode_signed_corim
  2. Extracts the raw payload bytes -> returned as the document
  3. Re-emits the envelope with the payload field set to nil -> returned as the detached signature

The protected-header bytes and signature bytes are preserved verbatim across the round-trip: decode_signed_corim retains the original protected_header_bytes as-is, and encode_signed_corim emits them unmodified. This is required because the COSE signature is computed over the exact protected-header bytes.

§Errors

Returns an error if:

  • the input is not a valid CoRIM-spec-compliant #6.18(COSE_Sign1), or
  • the input has a nil payload (i.e., is already detached) – in that case pass the bytes straight to verify_corim_signature instead of splitting them.