c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

commit 8959e03dca52c4e225b3f662ed1cec7c3ee576db
parent cfe92b949a24bfc33a4a4749c4a2c35767bfc330
Author: Gavin  Peacock <gpeacock@adobe.com>
Date:   Tue, 28 Jun 2022 15:50:48 -0700

Fix bug with multiple ingredients in `Manifest::from_store` (#61)

Fixes bug with multiple ingredients in Manifest::from_store.
Diffstat:
Msdk/src/manifest.rs | 9+++++----
Msdk/src/manifest_store.rs | 23+++++++++++++++++++++--
Msdk/src/utils/test.rs | 9+++++++++
3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs @@ -378,9 +378,10 @@ impl Manifest { for claim_assertion in claim.claim_assertion_store().iter() { let assertion = claim_assertion.assertion(); - let label = assertion.label(); + let label = claim_assertion.label(); + let base_label = assertion.label(); debug!("assertion = {}", label); - match label.as_ref() { + match base_label.as_ref() { labels::INGREDIENT => { let assertion_uri = jumbf::labels::to_assertion_uri(claim.label(), &label); let ingredient = Ingredient::from_ingredient_uri(store, &assertion_uri)?; @@ -395,14 +396,14 @@ impl Manifest { match assertion.decode_data() { AssertionData::Json(_x) => { let value = assertion.as_json_object()?; - let ma = ManifestAssertion::new(label, value) + let ma = ManifestAssertion::new(base_label, value) .set_instance(claim_assertion.instance()) .set_kind(ManifestAssertionKind::Json); manifest.assertions.push(ma); } AssertionData::Cbor(_x) => { let value = assertion.as_json_object()?; //todo: should this be cbor? - let ma = ManifestAssertion::new(label, value) + let ma = ManifestAssertion::new(base_label, value) .set_instance(claim_assertion.instance()); manifest.assertions.push(ma); diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs @@ -236,9 +236,11 @@ mod tests { assert!(!manifest_store.manifests.is_empty()); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); + // make sure we have two different ingredients + assert_eq!(manifest.ingredients()[0].format(), "image/jpeg"); + assert_eq!(manifest.ingredients()[1].format(), "image/png"); - let full_report = - ManifestStore::from_store(&store, &mut OneShotStatusTracker::new()).to_string(); + let full_report = manifest_store.to_string(); assert!(!full_report.is_empty()); println!("{}", full_report); } @@ -260,4 +262,21 @@ mod tests { assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); assert!(manifest.time().is_some()); } + + #[test] + #[cfg(feature = "file_io")] + fn manifest_report_from_file() { + let manifest_store = ManifestStore::from_file("tests/fixtures/CA.jpg").unwrap(); + println!("{}", manifest_store); + + assert!(!manifest_store.manifests.is_empty()); + assert!(manifest_store.active_label().is_some()); + assert!(manifest_store.get_active().is_some()); + assert!(!manifest_store.manifests().is_empty()); + assert!(manifest_store.validation_status().is_none()); + let manifest = manifest_store.get_active().unwrap(); + assert!(!manifest.ingredients().is_empty()); + assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); + assert!(manifest.time().is_some()); + } } diff --git a/sdk/src/utils/test.rs b/sdk/src/utils/test.rs @@ -133,7 +133,16 @@ pub fn create_test_claim() -> Result<Claim> { //.set_manifest_data(&data_path) .add_review(review); + let ingredient2 = Ingredient::new( + "image 2.png", + "image/png", + "xmp.iid:7b57930e-2f23-47fc-affe-0400d70b738c", + Some("xmp.did:87d51599-286e-43b2-9478-88c79f49c346"), + ) + .set_thumbnail(Some(&thumb_uri)); + claim.add_assertion_with_salt(&ingredient, &DefaultSalt::default())?; + claim.add_assertion_with_salt(&ingredient2, &DefaultSalt::default())?; Ok(claim) }