Beyond the mandatory traits, handlers can implement several optional traits to provide advanced capabilities:
AssetPatch
Used for in-place binary patching. This optimizes manifest updates by patching bytes in-place without rewriting the whole file. This only works when the new store is the same size as the existing one.
pub trait AssetPatch {
fn patch_cai_store(&self, asset_path: &Path, store_bytes: &[u8]) -> Result<()>;
}
RemoteRefEmbed
Used for embedding remote manifest reference URLs into the asset's XMP metadata.
pub trait RemoteRefEmbed {
fn embed_reference(&self, asset_path: &Path, embed_ref: RemoteRefEmbedType) -> Result<()>;
fn embed_reference_to_stream(
&self,
source_stream: &mut dyn CAIRead,
output_stream: &mut dyn CAIReadWrite,
embed_ref: RemoteRefEmbedType,
) -> Result<()>;
}
AssetBoxHash
Used for box hash support. It generates a BoxMap describing all hashable regions in the file for c2pa.hash.boxes assertions.
pub trait AssetBoxHash {
fn get_box_map(&self, input_stream: &mut dyn CAIRead) -> Result<Vec<BoxMap>>;
}
ComposedManifestRef
Used for pre-composed manifest wrapping. It wraps raw manifest store bytes into the format-specific container structure (e.g., JPEG XT headers for JPEG, or a caBX chunk for PNG).
pub trait ComposedManifestRef {
fn compose_manifest(&self, manifest_data: &[u8], format: &str) -> Result<Vec<u8>>;
}
When ComposedManifestRef is used, the asset handler is not performing the manifest embedding; the API provides a composed manifest ready for direct insertion.