Skip to main content

fetch_and_verify_data_ref

Function fetch_and_verify_data_ref 

Source
pub async fn fetch_and_verify_data_ref(
    dr: &DataRef,
    fetcher: &impl DataRefFetcher,
) -> Result<Vec<u8>, AcdpError>
Expand description

Convenience: fetch a DataRef and verify its declared content_hash.

Behavior:

  • Embedded ref: returns the decoded bytes via acdp_validation::embedded_decoded_bytes. If the ref also declares a content_hash, acdp_validation::verify_embedded_hash has already verified it at validation time; this function re-verifies as a defense-in-depth check.
  • URI ref: delegates to fetcher and recomputes SHA-256 over the returned bytes, checking against dr.content_hash when present. If content_hash is absent, returns the bytes unverified — the producer chose not to commit to a hash, so the consumer is on its own.
  • Both URI and embedded: rejected at validation; this function relies on that and assumes exactly one is present.