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 2a0b033abf39ae9ff46c3cfc3a76b28261f88a6e
parent d6f470adfbeec9e4b8f318d15fdb0820e69c5414
Author: Dave Kozma <dkozma@adobe.com>
Date:   Wed, 22 Jun 2022 17:59:21 -0400

Update thumbnail to be `Vec<u8>`, add serialization feature (#59)

* Update thumbnail to be `Vec<u8>`, add serialization feature
* Update README
Diffstat:
MREADME.md | 3++-
Msdk/Cargo.toml | 1+
Msdk/src/ingredient.rs | 13+++++++++----
3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -50,7 +50,8 @@ c2pa = "0.5.0" * `async_signer` enables signing via asynchronous services which require `async` support. * `file_io` enables manifest generation, signing via OpenSSL, and embedding manifests in various file formats. -* `xmp_write` enables updating XMP on embed with the dcterms:provenance field (requires xmp_toolkit) +* `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)). ## Rust version requirements diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml @@ -14,6 +14,7 @@ rust-version = "1.58.0" [features] async_signer = ["async-trait"] file_io = ["openssl"] +serialize_thumbnails = [] xmp_write = ["xmp_toolkit"] # The diagnostics feature is unsupported and might be removed. diff --git a/sdk/src/ingredient.rs b/sdk/src/ingredient.rs @@ -16,7 +16,6 @@ use crate::{ assertion::{get_thumbnail_image_type, Assertion, AssertionBase}, assertions::{self, labels, Metadata, Relationship, Thumbnail}, - cbor_types::BytesT, claim::Claim, error::{Error, Result}, hashed_uri::HashedUri, @@ -31,6 +30,12 @@ use crate::{error::wrap_io_err, validation_status::status_for_store, xmp_inmemor use log::{debug, error}; use serde::{Deserialize, Serialize}; +/// Function that is used by serde to determine whether or not we should serialize +/// thumbnail data based on the "serialize_thumbnails" flag (serialization is disabled by default) +pub fn skip_serializing_thumbnails(_value: &Option<(String, Vec<u8>)>) -> bool { + !cfg!(feature = "serialize_thumbnails") +} + #[cfg(feature = "file_io")] use std::path::Path; #[derive(Debug, Deserialize, Serialize)] @@ -56,8 +61,8 @@ pub struct Ingredient { /// A thumbnail image capturing the visual state at the time of import. /// /// A tuple of thumbnail MIME format (i.e. `image/jpeg`) and binary bits of the image. - #[serde(skip_serializing)] - thumbnail: Option<(String, BytesT)>, + #[serde(skip_serializing_if = "skip_serializing_thumbnails")] + thumbnail: Option<(String, Vec<u8>)>, /// An optional hash of the asset to prevent duplicates. #[serde(skip_serializing_if = "Option::is_none")] @@ -236,7 +241,7 @@ impl Ingredient { /// Sets the thumbnail format and image data. pub fn set_thumbnail<S: Into<String>>(&mut self, format: S, thumbnail: Vec<u8>) -> &mut Self { - self.thumbnail = Some((format.into(), BytesT(thumbnail))); + self.thumbnail = Some((format.into(), thumbnail)); self }