Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions c2pa_c_ffi/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,31 @@ pub unsafe extern "C" fn c2pa_builder_set_remote_url(
0 as c_int
}

/// ⚠️ **Deprecated Soon**
/// This method is planned to be deprecated in a future release.
/// Usage should be limited and temporary.
///
/// Sets the resource directory on the Builder.
/// When set, resources that are not found in memory will be searched for in the given directory.
/// # Parameters
/// * builder_ptr: pointer to a Builder.
/// * base_path: pointer to a C string with the resource directory.
/// # Errors
/// Returns -1 if there were errors, otherwise returns 0.
/// The error string can be retrieved by calling c2pa_error.
/// # Safety
/// Reads from NULL-terminated C strings.
#[no_mangle]
pub unsafe extern "C" fn c2pa_builder_set_base_path(
builder_ptr: *mut C2paBuilder,
base_path: *const c_char,
) -> c_int {
let mut builder = guard_boxed_int!(builder_ptr);
let base_path = from_cstr_or_return_int!(base_path);
builder.set_base_path(&base_path);
0 as c_int
}

/// Adds a resource to the C2paBuilder.
///
/// The resource uri should match an identifier in the manifest definition.
Expand Down
46 changes: 46 additions & 0 deletions sdk/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ impl Builder {
self
}

/// ⚠️ **Deprecated Soon**
/// This method is planned to be deprecated in a future release.
/// Usage should be limited and temporary.
///
/// Sets the resource directory for this [`Builder`]
///
/// # Arguments
/// * `base_path` - The directory to search in to find the resources.
/// # Returns
/// * A mutable reference to the [`Builder`].
#[cfg(feature = "file_io")]
pub fn set_base_path<P: Into<PathBuf>>(&mut self, base_path: P) -> &mut Self {
self.base_path = Some(base_path.into());
self
}

/// Sets the remote_url for this [`Builder`].
/// The URL must return the manifest data and is injected into the destination asset when signing.
/// For remote-only manifests, set the `no_embed` flag to `true`.
Expand Down Expand Up @@ -1214,6 +1230,8 @@ mod tests {
use wasm_bindgen_test::*;

use super::*;
#[cfg(feature = "file_io")]
use crate::utils::test::fixture_path;
use crate::{
assertions::{c2pa_action, BoxHash},
asset_handlers::jpeg_io::JpegIO,
Expand Down Expand Up @@ -2230,4 +2248,32 @@ mod tests {
assert!(reader_json.contains("Test Ingredient"));
assert!(reader_json.contains("thumbnail.ingredient"));
}

#[cfg(feature = "file_io")]
#[test]
fn test_base_path() {
let mut builder = Builder::new();
let ingredient_folder = fixture_path("ingredient");
builder.set_base_path(&ingredient_folder);
assert_eq!(builder.base_path.as_ref(), Some(&ingredient_folder));
let ingredient_json =
std::fs::read_to_string(ingredient_folder.join("ingredient.json")).unwrap();

let ingredient = Ingredient::from_json(&ingredient_json).unwrap();
builder.add_ingredient(ingredient);

let signer = test_signer(SigningAlg::Ps256);

let mut source = Cursor::new(TEST_IMAGE_CLEAN);
let mut dest = Cursor::new(Vec::new());

builder
.sign(&signer, "image/jpeg", &mut source, &mut dest)
.unwrap();

let reader = Reader::from_stream("jpeg", &mut dest).unwrap();
let active_manifest = reader.active_manifest().unwrap();
let ingredient = active_manifest.ingredients().first().unwrap();
assert_eq!(ingredient.title(), Some("C.jpg"));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions sdk/tests/fixtures/ingredient/ingredient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"title": "C.jpg",
"format": "image/jpeg",
"instance_id": "xmp:iid:547f138e-d98d-45b5-a13c-8fd092b4ebc6",
"thumbnail": {
"format": "image/jpeg",
"identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/c2pa.thumbnail.claim.jpeg",
"hash": "Nrhmnt6qXlHbrpaDmEMb98m3TyN3PJwniriapw7QM4k="
},
"relationship": "componentOf",
"active_manifest": "contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3",
"validation_results": {
"activeManifest": {
"success": [
{
"code": "claimSignature.insideValidity",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.signature",
"explanation": "claim signature valid"
},
{
"code": "claimSignature.validated",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.signature",
"explanation": "claim signature valid"
},
{
"code": "assertion.hashedURI.match",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/c2pa.thumbnail.claim.jpeg",
"explanation": "hashed uri matched: self#jumbf=c2pa.assertions/c2pa.thumbnail.claim.jpeg"
},
{
"code": "assertion.hashedURI.match",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/stds.schema-org.CreativeWork",
"explanation": "hashed uri matched: self#jumbf=c2pa.assertions/stds.schema-org.CreativeWork"
},
{
"code": "assertion.hashedURI.match",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/c2pa.actions",
"explanation": "hashed uri matched: self#jumbf=c2pa.assertions/c2pa.actions"
},
{
"code": "assertion.hashedURI.match",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/c2pa.hash.data",
"explanation": "hashed uri matched: self#jumbf=c2pa.assertions/c2pa.hash.data"
},
{
"code": "assertion.dataHash.match",
"url": "self#jumbf=/c2pa/contentauth:urn:uuid:b2b1f7fa-b119-4de1-9c0d-c97fbea3f2c3/c2pa.assertions/c2pa.hash.data",
"explanation": "data hash valid"
}
],
"informational": [],
"failure": []
}
},
"manifest_data": {
"format": "application/c2pa",
"identifier": "manifest_data.c2pa"
}
}
Binary file added sdk/tests/fixtures/ingredient/manifest_data.c2pa
Binary file not shown.