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 d946902ef88208dea482bab49236d0e77508fb04
parent ce1f06078ae72a8485f18b9ce0ae710f751fa177
Author: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com>
Date:   Fri, 15 Dec 2023 14:49:44 -0500

Add support for ARW and NEF (#355)

Support for ARW and NEF
Diffstat:
Msdk/src/asset_handlers/tiff_io.rs | 12+++++++++++-
Msdk/src/store.rs | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 159 insertions(+), 1 deletion(-)

diff --git a/sdk/src/asset_handlers/tiff_io.rs b/sdk/src/asset_handlers/tiff_io.rs @@ -49,7 +49,17 @@ const TILEOFFSETS: u16 = 324; const SUBFILES: [u16; 3] = [SUBFILE_TAG, EXIFIFD_TAG, GPSIFD_TAG]; -static SUPPORTED_TYPES: [&str; 5] = ["tif", "tiff", "image/tiff", "dng", "image/x-adobe-dng"]; +static SUPPORTED_TYPES: [&str; 9] = [ + "tif", + "tiff", + "image/tiff", + "dng", + "image/x-adobe-dng", + "arw", + "image/x-sony-arw", + "nef", + "image/x-nikon-nef", +]; // The type of an IFD entry enum IFDEntryType { diff --git a/sdk/src/store.rs b/sdk/src/store.rs @@ -3503,6 +3503,154 @@ pub mod tests { } } + /* reenable this test once we place for large test files + #[test] + #[cfg(feature = "file_io")] + fn test_arw_jumbf_generation() { + let ap = fixture_path("sample1.arw"); + let temp_dir = tempdir().expect("temp dir"); + let op = temp_dir_path(&temp_dir, "ssample1.arw"); + + // Create claims store. + let mut store = Store::new(); + + // Create a new claim. + let claim1 = create_test_claim().unwrap(); + + // Create a new claim. + let mut claim2 = Claim::new("Photoshop", Some("Adobe")); + create_editing_claim(&mut claim2).unwrap(); + + // Create a 3rd party claim + let mut claim_capture = Claim::new("capture", Some("claim_capture")); + create_capture_claim(&mut claim_capture).unwrap(); + + // Do we generate JUMBF? + let signer = temp_signer(); + + // Move the claim to claims list. Note this is not real, the claims would have to be signed in between commmits + store.commit_claim(claim1).unwrap(); + store.save_to_asset(&ap, signer.as_ref(), &op).unwrap(); + store.commit_claim(claim_capture).unwrap(); + store.save_to_asset(&op, signer.as_ref(), &op).unwrap(); + store.commit_claim(claim2).unwrap(); + store.save_to_asset(&op, signer.as_ref(), &op).unwrap(); + + // write to new file + println!("Provenance: {}\n", store.provenance_path().unwrap()); + + let mut report = DetailedStatusTracker::new(); + + // read from new file + let new_store = Store::load_from_asset(&op, true, &mut report).unwrap(); + + // can we get by the ingredient data back + let _some_binary_data: Vec<u8> = vec![ + 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0x0e, 0x0f, 0x0a, 0x0d, 0x0b, 0x0e, 0x0a, 0x0d, + 0x0b, 0x0e, + ]; + + // dump store and compare to original + for claim in new_store.claims() { + let _restored_json = claim + .to_json(AssertionStoreJsonFormat::OrderedList, false) + .unwrap(); + let _orig_json = store + .get_claim(claim.label()) + .unwrap() + .to_json(AssertionStoreJsonFormat::OrderedList, false) + .unwrap(); + + println!( + "Claim: {} \n{}", + claim.label(), + claim + .to_json(AssertionStoreJsonFormat::OrderedListNoBinary, true) + .expect("could not restore from json") + ); + + for hashed_uri in claim.assertions() { + let (label, instance) = Claim::assertion_label_from_link(&hashed_uri.url()); + claim + .get_claim_assertion(&label, instance) + .expect("Should find assertion"); + } + } + } + #[test] + #[cfg(feature = "file_io")] + fn test_nef_jumbf_generation() { + let ap = fixture_path("sample1.nef"); + let temp_dir = tempdir().expect("temp dir"); + let op = temp_dir_path(&temp_dir, "ssample1.nef"); + + // Create claims store. + let mut store = Store::new(); + + // Create a new claim. + let claim1 = create_test_claim().unwrap(); + + // Create a new claim. + let mut claim2 = Claim::new("Photoshop", Some("Adobe")); + create_editing_claim(&mut claim2).unwrap(); + + // Create a 3rd party claim + let mut claim_capture = Claim::new("capture", Some("claim_capture")); + create_capture_claim(&mut claim_capture).unwrap(); + + // Do we generate JUMBF? + let signer = temp_signer(); + + // Move the claim to claims list. Note this is not real, the claims would have to be signed in between commmits + store.commit_claim(claim1).unwrap(); + store.save_to_asset(&ap, signer.as_ref(), &op).unwrap(); + store.commit_claim(claim_capture).unwrap(); + store.save_to_asset(&op, signer.as_ref(), &op).unwrap(); + store.commit_claim(claim2).unwrap(); + store.save_to_asset(&op, signer.as_ref(), &op).unwrap(); + + // write to new file + println!("Provenance: {}\n", store.provenance_path().unwrap()); + + let mut report = DetailedStatusTracker::new(); + + // read from new file + let new_store = Store::load_from_asset(&op, true, &mut report).unwrap(); + + // can we get by the ingredient data back + let _some_binary_data: Vec<u8> = vec![ + 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0x0e, 0x0f, 0x0a, 0x0d, 0x0b, 0x0e, 0x0a, 0x0d, + 0x0b, 0x0e, + ]; + + // dump store and compare to original + for claim in new_store.claims() { + let _restored_json = claim + .to_json(AssertionStoreJsonFormat::OrderedList, false) + .unwrap(); + let _orig_json = store + .get_claim(claim.label()) + .unwrap() + .to_json(AssertionStoreJsonFormat::OrderedList, false) + .unwrap(); + + println!( + "Claim: {} \n{}", + claim.label(), + claim + .to_json(AssertionStoreJsonFormat::OrderedListNoBinary, true) + .expect("could not restore from json") + ); + + for hashed_uri in claim.assertions() { + let (label, instance) = Claim::assertion_label_from_link(&hashed_uri.url()); + claim + .get_claim_assertion(&label, instance) + .expect("Should find assertion"); + } + } + } + */ #[test] #[cfg(feature = "file_io")] fn test_wav_jumbf_generation() {