Skip to main content

stamp_provenance_bytes

Function stamp_provenance_bytes 

Source
pub fn stamp_provenance_bytes(
    input: &[u8],
    patch: &ProvenancePatch,
) -> Result<Vec<u8>, V2FormatError>
Expand description

Patch provenance metadata on an existing APR v2 buffer and return the re-serialized bytes.

§Errors

Returns V2FormatError::InvalidHeader if:

  • input is not a valid APR v2 buffer (propagated from AprV2Reader::from_bytes)
  • patch.has_any() is false — a no-op stamp is rejected up-front so callers cannot accidentally rewrite without changing the artifact

§Guarantees

  • Header flags from input are preserved in the output (LAYOUT_ROW_MAJOR is always added regardless of input, per LAYOUT-002 jidoka)
  • Tensor bytes are copied verbatim — no quantize/dequantize round-trip
  • Sort-by-name ordering matches AprV2Writer::write() (tensor index is sorted, so the re-serialized index is canonical)

§Non-guarantees

  • Footer checksum WILL change (metadata bytes moved)
  • sha256 of the output file WILL differ from the input (by design — that is the whole point of a stamp operation)