pub fn patch(
igvm_data: &[u8],
corim_signature: &[u8],
platform: IgvmPlatformType,
expected_document: Option<&[u8]>,
) -> Result<Vec<u8>>Expand description
Verify a CoRIM signature against the document already embedded in an
IGVM file, then patch the corresponding CorimSignature header.
The CoRIM document is expected to already be present in the IGVM file for the target platform (auto-generated at build time). This function:
- Parses the IGVM file and locates the existing
CorimDocumentfor the target platform. - If
expected_documentis provided, asserts that it matches the in-file document byte-for-byte. This catches the common UX trap where a user supplies a--corim-bundlewhose embedded payload was signed against a different document than the one baked into the IGVM file: without this check the failure would surface as an opaque “cryptographic verification failed” error. - Cryptographically verifies
corim_signatureagainst the in-file document viaenvelope::verify_corim_signature. The issuer certificate is taken from the signature envelope’sx5chain/x5bagheader. - Stages the signature replacement via
[
IgvmSerializer::set_corim_signature], which suppresses any in-file document/signature pair for the platform and re-emits the existing document followed by the new signature in the required order, then serializes.
Verification runs before any serializer mutation, so a failed verification leaves no partially-modified output.
§Arguments
igvm_data- The original IGVM file contentscorim_signature- Detached COSE_Sign1 signature payload (nil payload)platform- The target platform typeexpected_document- Optional CoRIM document bytes that the caller asserts should match the document embedded in the IGVM file. Used when the signature was extracted from a bundled envelope; passNonewhen the caller doesn’t have an independent copy.
§Returns
The modified IGVM file contents with the CoRIM signature header inserted or updated.
§Errors
Returns an error if the IGVM file has no CorimDocument header for
the target platform – the signature cannot be attached without a
corresponding document – or if expected_document is provided and
does not match the in-file document, or if cryptographic verification
of corim_signature against the in-file document fails.