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 9463a33032bcba742c2cc3efde3e972c4d6c8537
parent 451f8828979377428ed3fc86b635e6ad8c61fd30
Author: Gavin  Peacock <gpeacock@adobe.com>
Date:   Wed, 29 Jun 2022 11:23:38 -0700

(MINOR) Return specific errors for FileNotFound and UnsupportedType (#62)

* Return UnsupportedType and FileNotFound errors.
* Do not inject Sec-CH-UA sdk hints
* add xmp_write feature to make_test_images
Diffstat:
Mmake_test_images/Cargo.toml | 2+-
Msdk/src/manifest.rs | 6------
Msdk/src/store.rs | 10+++++++---
3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/make_test_images/Cargo.toml b/make_test_images/Cargo.toml @@ -8,7 +8,7 @@ rust-version = "1.58.0" [dependencies] anyhow = "1.0" -c2pa = { path="../sdk", features = ["file_io"] } +c2pa = { path="../sdk", features = ["file_io", "xmp_write"] } env_logger = "0.9" log = "0.4" image = "0.23.10" diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs @@ -33,8 +33,6 @@ use std::collections::HashMap; #[cfg(feature = "file_io")] use std::path::Path; -const GH_UA: &str = "Sec-CH-UA"; - /// A Manifest represents all the information in a c2pa manifest #[derive(Debug, Deserialize, Serialize)] pub struct Manifest { @@ -495,10 +493,6 @@ impl Manifest { ingredient.add_to_claim(&mut claim, self.redactions.clone())?; } - // add a claim_generator_hint for the version of the library used to create the claim - let lib_hint = format!("\"{}\";v=\"{}\"", crate::NAME, crate::VERSION); - claim.add_claim_generator_hint(GH_UA, Value::from(lib_hint)); - let salt = DefaultSalt::default(); // add any additional assertions diff --git a/sdk/src/store.rs b/sdk/src/store.rs @@ -1649,6 +1649,10 @@ impl Store { let err = match e { Error::PrereleaseError => Error::PrereleaseError, Error::JumbfNotFound => Error::JumbfNotFound, + Error::IoError(_) => { + Error::FileNotFound(asset_path.to_string_lossy().to_string()) + } + Error::UnsupportedType => Error::UnsupportedType, _ => Error::LogStop, }; let log_item = log_item!("asset", "error loading file", "load_from_asset").error(e); @@ -1676,6 +1680,7 @@ impl Store { let err = match e { Error::PrereleaseError => Error::PrereleaseError, Error::JumbfNotFound => Error::JumbfNotFound, + Error::UnsupportedType => Error::UnsupportedType, _ => Error::LogStop, }; let log_item = @@ -2273,11 +2278,10 @@ pub mod tests { #[test] fn test_unsupported_type() { - // test bad xmp let ap = fixture_path("Purple Square.psd"); let mut report = DetailedStatusTracker::new(); - let _r = Store::load_from_asset(&ap, true, &mut report); - + let result = Store::load_from_asset(&ap, true, &mut report); + assert!(matches!(result, Err(Error::UnsupportedType))); println!("Error report for {}: {:?}", ap.as_display(), report); assert!(!report.get_log().is_empty());