Skip to content

Commit

Permalink
Update thumbnail to be Vec<u8>, add serialization feature (#59)
Browse files Browse the repository at this point in the history
* Update thumbnail to be `Vec<u8>`, add serialization feature
* Update README
  • Loading branch information
Dave Kozma authored Jun 22, 2022
1 parent d6f470a commit 2a0b033
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions sdk/src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)]
Expand All @@ -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")]
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2a0b033

Please sign in to comment.