Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/sdk/base64-0.22.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeacock authored Sep 3, 2024
2 parents 4ff4716 + 2a14e23 commit 0ac6d93
Show file tree
Hide file tree
Showing 75 changed files with 1,268 additions and 387 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ This project adheres to [Semantic Versioning](https://semver.org), except that

Do not manually edit this file. It will be automatically updated when a new release is published.

## 0.34.0
_30 August 2024_

* (MINOR) Fragmented BMFF media ([#572](https://github.com/contentauth/c2pa-rs/pull/572))

## 0.33.4
_29 August 2024_

* Depend on url crate version 2.5.2 or newer ([#573](https://github.com/contentauth/c2pa-rs/pull/573))

## 0.33.3
_17 August 2024_

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
c2pa = "0.33.3"
c2pa = "0.34.0"
```

If you want to read or write a manifest file, add the `file_io` dependency to your `Cargo.toml`.
Expand Down
2 changes: 1 addition & 1 deletion export_schema/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "export_schema"
version = "0.33.3"
version = "0.34.0"
authors = ["Dave Kozma <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand Down
5 changes: 4 additions & 1 deletion export_schema/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fs, path::Path};

use anyhow::Result;
use c2pa::{settings::Settings, ManifestDefinition, ManifestStore};
use c2pa::{settings::Settings, Builder, ManifestDefinition, ManifestStore};
use schemars::{schema::RootSchema, schema_for};

fn write_schema(schema: &RootSchema, name: &str) {
Expand All @@ -15,6 +15,9 @@ fn write_schema(schema: &RootSchema, name: &str) {
}

fn main() -> Result<()> {
let builder = schema_for!(Builder);
write_schema(&builder, "Builder");

let manifest_definition = schema_for!(ManifestDefinition);
write_schema(&manifest_definition, "ManifestDefinition");

Expand Down
2 changes: 1 addition & 1 deletion make_test_images/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "make_test_images"
version = "0.33.3"
version = "0.34.0"
authors = ["Gavin Peacock <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down
31 changes: 16 additions & 15 deletions make_test_images/src/make_test_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use anyhow::{Context, Result};
use c2pa::{
create_signer,
jumbf_io::{get_supported_types, load_jumbf_from_stream, save_jumbf_to_stream},
Builder, Error, Reader, Signer, SigningAlg,
Builder, Error, Ingredient, Reader, Relationship, Signer, SigningAlg,
};
use memchr::memmem;
use nom::AsBytes;
Expand Down Expand Up @@ -208,7 +208,7 @@ impl MakeTestImages {
fn add_ingredient_from_file(
builder: &mut Builder,
path: &Path,
relationship: &str,
relationship: Relationship,
) -> Result<String> {
let mut source = fs::File::open(path).context("opening ingredient")?;
let name = path
Expand All @@ -222,20 +222,18 @@ impl MakeTestImages {
.into_owned();
let format = extension_to_mime(&extension).unwrap_or("image/jpeg");

let json = json!({
"title": name,
"relationship": relationship,
})
.to_string();

let ingredient = builder.add_ingredient(&json, format, &mut source)?;
if ingredient.thumbnail_ref().is_none() {
let mut parent = Ingredient::from_stream(format, &mut source)?;
parent.set_relationship(relationship);
parent.set_title(name);
if parent.thumbnail_ref().is_none() {
source.rewind()?;
let (format, thumbnail) =
make_thumbnail_from_stream(format, &mut source).context("making thumbnail")?;
ingredient.set_thumbnail(format, thumbnail)?;
parent.set_thumbnail(format, thumbnail)?;
}

builder.add_ingredient(parent);

Ok(
builder.definition.ingredients[builder.definition.ingredients.len() - 1]
.instance_id()
Expand Down Expand Up @@ -300,7 +298,7 @@ impl MakeTestImages {
let src_path = &self.make_path(src);

let instance_id =
Self::add_ingredient_from_file(&mut builder, src_path, "parentOf")?;
Self::add_ingredient_from_file(&mut builder, src_path, Relationship::ParentOf)?;

actions.push(json!(
{
Expand Down Expand Up @@ -376,8 +374,11 @@ impl MakeTestImages {
let instance_id = match ingredient_table.get(ing.as_str()) {
Some(id) => id.to_string(),
None => {
let instance_id =
Self::add_ingredient_from_file(&mut builder, ing_path, "componentOf")?;
let instance_id = Self::add_ingredient_from_file(
&mut builder,
ing_path,
Relationship::ComponentOf,
)?;
ingredient_table.insert(ing, instance_id.clone());
instance_id
}
Expand Down Expand Up @@ -490,7 +491,7 @@ impl MakeTestImages {
let mut builder = Builder::from_json(&json)?;

let parent_name = file_name(&dst_path).ok_or(Error::BadParam("no filename".to_string()))?;
builder.add_ingredient(
builder.add_ingredient_from_stream(
json!({
"title": parent_name,
"relationship": "parentOf"
Expand Down
10 changes: 5 additions & 5 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "c2pa"
version = "0.33.3"
version = "0.34.0"
description = "Rust SDK for C2PA (Coalition for Content Provenance and Authenticity) implementors"
authors = [
"Maurice Fisher <[email protected]>",
Expand Down Expand Up @@ -65,7 +65,7 @@ crate-type = ["lib"]

[dependencies]
asn1-rs = "0.5.2"
async-generic = "0.1.2"
async-generic = "1.1"
async-recursion = "1.1.1"
async-trait = { version = "0.1.77" }
atree = "0.5.2"
Expand All @@ -89,6 +89,7 @@ config = { version = "0.14.0", default-features = false, features = [
conv = "0.3.3"
coset = "0.3.1"
extfmt = "0.1.1"
ed25519-dalek = "2.1.1"
fast-xml = "0.23.1"
hex = "0.4.3"
# Version 1.13.0 doesn't compile under Rust < 1.75, pinning to 1.12.0
Expand Down Expand Up @@ -123,7 +124,7 @@ sha2 = "0.10.6"
tempfile = "3.10.1"
thiserror = "1.0.61"
treeline = "0.1.0"
url = "2.2.2, <2.5.1" # Can't use 2.5.1 or newer until new license is reviewed.
url = "2.5.2"
uuid = { version = "1.7.0", features = ["serde", "v4", "js"] }
x509-parser = "0.15.1"
x509-certificate = "0.21.0"
Expand All @@ -141,7 +142,6 @@ openssl = { version = "0.10.61", features = ["vendored"], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = { version = "1.0.0", features = ["color"] }
ed25519-dalek = "2.1.1"
getrandom = { version = "0.2.7", features = ["js"] }
# We need to use the `inaccurate` flag here to ensure usage of the JavaScript Date API
# to handle certificate timestamp checking correctly.
Expand All @@ -167,6 +167,7 @@ mockall = "0.11.2"
c2pa = { path = ".", features = [
"unstable_api",
] } # allow integration tests to use the new API
glob = "0.3.1"
jumbf = "0.4.0"


Expand All @@ -175,5 +176,4 @@ wasm-bindgen-test = "0.3.31"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
actix = "0.13.1"
ed25519-dalek = "2.1.1"
tokio = { version = "1.36.0", features = ["full"] }
60 changes: 38 additions & 22 deletions sdk/examples/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ use std::path::PathBuf;
use anyhow::Result;
use c2pa::{
assertions::{c2pa_action, labels, Action, Actions, CreativeWork, Exif, SchemaDotOrgPerson},
create_signer, Ingredient, Manifest, Reader as ManifestStore, SigningAlg,
create_signer, Builder, ClaimGeneratorInfo, Ingredient, Reader, Relationship, SigningAlg,
};

const GENERATOR: &str = "test_app/0.1";
const INDENT_SPACE: usize = 2;

// Example for reading the contents of a manifest store, recursively showing nested manifests
fn show_manifest(manifest_store: &ManifestStore, manifest_label: &str, level: usize) -> Result<()> {
fn show_manifest(reader: &Reader, manifest_label: &str, level: usize) -> Result<()> {
let indent = " ".repeat(level * INDENT_SPACE);

println!("{indent}manifest_label: {manifest_label}");
if let Some(manifest) = manifest_store.get_manifest(manifest_label) {
if let Some(manifest) = reader.get_manifest(manifest_label) {
println!(
"{}title: {} , format: {}, instance_id: {}",
indent,
Expand Down Expand Up @@ -66,8 +66,17 @@ fn show_manifest(manifest_store: &ManifestStore, manifest_label: &str, level: us

for ingredient in manifest.ingredients().iter() {
println!("{}Ingredient title:{}", indent, ingredient.title());
if let Some(validation_status) = ingredient.validation_status() {
for status in validation_status {
println!(
"Ingredient validation status: {}: {}",
status.code(),
status.explanation().unwrap_or_default()
);
}
}
if let Some(label) = ingredient.active_manifest() {
show_manifest(manifest_store, label, level + 1)?;
show_manifest(reader, label, level + 1)?;
}
}
}
Expand All @@ -88,11 +97,11 @@ pub fn main() -> Result<()> {
let source = PathBuf::from(src);
let dest = PathBuf::from(dst);
// if a filepath was provided on the command line, read it as a parent file
let parent = Ingredient::from_file(source.as_path())?;

let mut parent = Ingredient::from_file(source.as_path())?;
parent.set_relationship(Relationship::ParentOf);
// create an action assertion stating that we imported this file
let actions = Actions::new().add_action(
Action::new(c2pa_action::PLACED)
Action::new(c2pa_action::OPENED)
.set_parameter("identifier", parent.instance_id().to_owned())?,
);

Expand All @@ -115,31 +124,38 @@ pub fn main() -> Result<()> {
)?;

// create a new Manifest
let mut manifest = Manifest::new(GENERATOR.to_owned());
// add parent and assertions
manifest
.set_parent(parent)?
.add_assertion(&actions)?
.add_assertion(&creative_work)?
.add_assertion(&exif)?;
let mut builder = Builder::new();
builder
.set_claim_generator_info(ClaimGeneratorInfo::new(GENERATOR))
.add_ingredient(parent)
.add_assertion(Actions::LABEL, &actions)?
.add_assertion(CreativeWork::LABEL, &creative_work)?
.add_assertion(Exif::LABEL, &exif)?;

// sign and embed into the target file
let signcert_path = "sdk/tests/fixtures/certs/es256.pub";
let pkey_path = "sdk/tests/fixtures/certs/es256.pem";
let signer = create_signer::from_files(signcert_path, pkey_path, SigningAlg::Es256, None)?;

manifest.embed(&source, &dest, &*signer)?;
builder.sign_file(&*signer, &source, &dest)?;

let manifest_store = ManifestStore::from_file(&dest)?;
let reader = Reader::from_file(&dest)?;

// example of how to print out the whole manifest as json
println!("{manifest_store}\n");

// walk through the manifest and access data.
println!("{reader}\n");

if let Some(manifest_label) = manifest_store.active_label() {
show_manifest(&manifest_store, manifest_label, 0)?;
// walk through the manifests and show the contents
if let Some(manifest_label) = reader.active_label() {
show_manifest(&reader, manifest_label, 0)?;
}
if let Some(validation_status) = reader.validation_status() {
for status in validation_status {
println!(
"Validation status: {}: {}",
status.code(),
status.explanation().unwrap_or_default()
);
}
}

Ok(())
}
Loading

0 comments on commit 0ac6d93

Please sign in to comment.