commit dcf30a700203b319895720fd368488329a5c340c
parent 64f6ee5f2c520fce03f00314f1b4a8dd684b8333
Author: Eric Scouten <scouten@adobe.com>
Date: Tue, 12 Jul 2022 16:06:53 -0700
Update XMP Toolkit to 0.5.0 (#71)
Diffstat:
4 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
@@ -52,7 +52,7 @@ c2pa = "0.7.0"
* `bmff` enables handling of BMFF file formats. Currently only MP4, M4A, and MOV are enabled for writing.
* `file_io` enables manifest generation, signing via OpenSSL, and embedding manifests in various file formats.
* `serialize_thumbnails` includes binary thumbnail data in the [Serde](https://serde.rs/) serialization output.
-* `xmp_write` enables updating XMP on embed with the `dcterms:provenance` field (requires [xmp_toolkit](https://crates.io/crates/xmp_toolkit)).
+* `xmp_write` enables updating XMP on embed with the `dcterms:provenance` field. (Requires [xmp_toolkit](https://crates.io/crates/xmp_toolkit).)
## Rust version requirements
diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml
@@ -70,7 +70,7 @@ url = "2.2.2"
ureq = "2.4.0"
instant = "0.1.0"
openssl = { version = "0.10.31", features = ["vendored"], optional = true }
-xmp_toolkit = { version = "0.3.4", optional = true }
+xmp_toolkit = { version = "0.5.0", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = { version = "0.2", features = ["color"] }
diff --git a/sdk/src/embedded_xmp.rs b/sdk/src/embedded_xmp.rs
@@ -13,7 +13,10 @@
use std::path::Path;
-use xmp_toolkit::{OpenFileOptions, XmpFile, XmpFileError, XmpMeta};
+use log::error;
+use xmp_toolkit::{OpenFileOptions, XmpError, XmpFile, XmpMeta};
+
+use crate::{Error, Result};
/// Add the URI for the active manifest to the XMP packet for a file.
///
@@ -22,20 +25,29 @@ use xmp_toolkit::{OpenFileOptions, XmpFile, XmpFileError, XmpMeta};
///
/// This does not check the claim at all; it is presumed
/// that the string that is passed is a valid signed claim.
-pub(crate) fn add_manifest_uri_to_file<P: AsRef<Path>>(
- path: P,
- manifest_uri: &str,
-) -> Result<(), XmpFileError> {
- XmpMeta::register_namespace("http://purl.org/dc/terms/", "dcterms");
+pub(crate) fn add_manifest_uri_to_file<P: AsRef<Path>>(path: P, manifest_uri: &str) -> Result<()> {
+ XmpMeta::register_namespace("http://purl.org/dc/terms/", "dcterms").map_err(xmp_write_err)?;
+
+ let mut f = XmpFile::new().map_err(xmp_write_err)?;
+
+ f.open_file(path, OpenFileOptions::default().for_update())
+ .map_err(xmp_write_err)?;
- let mut f = XmpFile::new();
+ let mut m = match f.xmp() {
+ Some(m) => m,
+ None => XmpMeta::new().map_err(xmp_write_err)?,
+ };
- f.open_file(path, OpenFileOptions::OPEN_FOR_UPDATE)?;
+ m.set_property("http://purl.org/dc/terms/", "provenance", manifest_uri)
+ .map_err(xmp_write_err)?;
- let mut m = f.xmp().unwrap_or_else(XmpMeta::new);
- m.set_property("http://purl.org/dc/terms/", "provenance", manifest_uri);
- f.put_xmp(&m);
+ f.put_xmp(&m).map_err(xmp_write_err)?;
f.close();
Ok(())
}
+
+fn xmp_write_err(err: XmpError) -> crate::Error {
+ error!("Unable to add manifest URI to file: {:?}", err);
+ Error::XmpWriteError
+}
diff --git a/sdk/src/store.rs b/sdk/src/store.rs
@@ -1429,8 +1429,7 @@ impl Store {
// update XMP info & add xmp hash to provenance claim
#[cfg(feature = "xmp_write")]
if let Some(provenance) = self.provenance_path() {
- embedded_xmp::add_manifest_uri_to_file(output_path, &provenance)
- .map_err(|_err| Error::XmpWriteError)?;
+ embedded_xmp::add_manifest_uri_to_file(output_path, &provenance)?;
} else {
return Err(Error::XmpWriteError);
}