Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds Action changes field as option vec of serde_json value #431

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
56 changes: 45 additions & 11 deletions sdk/src/assertions/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ pub struct Action {

/// A semicolon-delimited list of the parts of the resource that were changed since the previous event history.
///
/// This is deprecated in favor of the `changes` field.
#[serde(skip_serializing_if = "Option::is_none")]
changed: Option<String>,

/// A list of the regions of interest of the resource that were changed.
///
/// If not present, presumed to be undefined.
/// When tracking changes and the scope of the changed components is unknown,
/// it should be assumed that anything might have changed.
#[serde(skip_serializing_if = "Option::is_none")]
changed: Option<String>,
changes: Option<Vec<serde_json::Value>>,

/// The value of the `xmpMM:InstanceID` property for the modified (output) resource.
#[serde(rename = "instanceId", skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -152,7 +158,7 @@ impl Action {
matches!(
self.software_agent,
Some(SoftwareAgent::ClaimGeneratorInfo(_))
)
) || self.changes.is_some() // only defined for v2
}

/// Returns the label for this action.
Expand Down Expand Up @@ -703,30 +709,52 @@ pub mod tests {
fn test_json_v2_round_trip() {
let json = serde_json::json!({
"actions": [
{
{
"action": "c2pa.edited",
"parameters": {
"description": "gradient",
"name": "any value"
"description": "gradient",
"name": "any value"
},
"softwareAgent": "TestApp"
},
{
},
{
"action": "c2pa.opened",
"instanceId": "xmp.iid:7b57930e-2f23-47fc-affe-0400d70b738d",
"parameters": {
"description": "import"
"description": "import"
},
"digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/algorithmicMedia",
"softwareAgent": {
"name": "TestApp",
"version": "1.0",
"something": "else"
},
},
{
},
{
"action": "com.joesphoto.filter",
}
},
{
"action": "c2pa.dubbed",
"changes": [
{
"description": "translated to klingon",
"region": [
{
"type": "temporal",
"time": {}
},
{
"type": "identified",
"item": {
"identifier": "https://bioportal.bioontology.org/ontologies/FMA",
"value": "lips"
}
}
]
}
]
}

],
"templates": [
{
Expand Down Expand Up @@ -755,5 +783,11 @@ pub mod tests {
result.actions[0].software_agent().unwrap(),
&SoftwareAgent::String("TestApp".to_string())
);
assert_eq!(
result.actions[3].changes.as_deref().unwrap()[0]
.get("description")
.unwrap(),
"translated to klingon"
);
}
}
90 changes: 88 additions & 2 deletions sdk/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,13 @@ impl Manifest {
_ => {
// inject assertions for all other assertions
match assertion.decode_data() {
AssertionData::Json(_) | AssertionData::Cbor(_) => {
AssertionData::Cbor(_) => {
let value = assertion.as_json_object()?;
let ma = ManifestAssertion::new(base_label, value)
.set_instance(claim_assertion.instance());
manifest.assertions.push(ma);
}
AssertionData::Json(_) => {
let value = assertion.as_json_object()?;
let ma = ManifestAssertion::new(base_label, value)
.set_instance(claim_assertion.instance())
Expand Down Expand Up @@ -1423,6 +1429,68 @@ pub(crate) mod tests {
assert!(result.is_err())
}

#[test]
#[cfg(feature = "file_io")]
/// test assertion validation on actions, should generate an error
fn ws_valid_labeled_assertion() {
// copy an image to use as our target for embedding
let ap = fixture_path(TEST_SMALL_JPEG);
let temp_dir = tempdir().expect("temp dir");
let test_output = temp_dir_path(&temp_dir, "ws_bad_assertion.jpg");
std::fs::copy(ap, test_output).expect("copy");

let mut manifest = test_manifest();

manifest
.add_labeled_assertion(
"c2pa.actions",
&serde_json::json!({
"actions": [
{
"action": "c2pa.edited",
"parameters": {
"description": "gradient",
"name": "any value"
},
"softwareAgent": "TestApp"
},
{
"action": "c2pa.dubbed",
"changes": [
{
"description": "translated to klingon",
"region": [
{
"type": "temporal",
"time": {}
},
{
"type": "identified",
"item": {
"identifier": "https://bioportal.bioontology.org/ontologies/FMA",
"value": "lips"
}
}
]
}
]
}
]
}),
)
.expect("add_assertion");

// convert to store
let store = manifest.to_store().expect("valid action to_store");
let m2 = Manifest::from_store(&store, &store.provenance_label().unwrap(), None)
.expect("from_store");
let actions: Actions = m2
.find_assertion("c2pa.actions.v2")
.expect("find_assertion");
assert_eq!(actions.actions()[0].action(), "c2pa.edited");
assert_eq!(actions.actions()[1].action(), "c2pa.dubbed");
}

#[test]
fn test_verifiable_credential() {
let mut manifest = test_manifest();
Expand Down Expand Up @@ -1974,7 +2042,25 @@ pub(crate) mod tests {
"identifier": "sample1.svg"
},
"something": "else"
}
},
"changes": [
{
"region" : [
{
"type" : "temporal",
"time" : {}
},
{
"type" : "identified",
"item" : {
"identifier" : "https://bioportal.bioontology.org/ontologies/FMA",
"value" : "lips"
}
}
],
"description": "lip synced area"
}
]
}
],
"templates": [
Expand Down
Loading