Skip to content

Commit 06732ee

Browse files
tmatherngpeacock
andauthored
fix: Use Digitalsourcetype with Builder intents (#1586)
* fix: Take Digital source type into account * fix: Take Digital source type into account * fix: CLarify comment * fix: Remove debug logs * fix: FOrmat * fix: Fix the API * removes default and test file settings for builder.actions.auto_created_actions, auto_opened_actions and auto_palaced actions. These are all now disabled and do not set digitalSourceType. they are still tested with individual unit tests. I set the default intent to edit in test_settings.toml. ca_test.json known goods are updated. If intent is set, it always takes precedent over auto_opened and auto_create. * fix: Typos --------- Co-authored-by: Gavin Peacock <[email protected]>
1 parent 607469e commit 06732ee

File tree

7 files changed

+226
-111
lines changed

7 files changed

+226
-111
lines changed

c2pa_c_ffi/src/c_api.rs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ mod tests {
18471847
}
18481848

18491849
#[test]
1850-
fn builder_create_intent_and_sign() {
1850+
fn builder_create_intent_digital_creation_and_sign() {
18511851
let source_image = include_bytes!(fixture_path!("IMG_0003.jpg"));
18521852
let mut source_stream = TestC2paStream::from_bytes(source_image.to_vec());
18531853
let dest_vec = Vec::new();
@@ -1888,10 +1888,79 @@ mod tests {
18881888

18891889
let json = unsafe { c2pa_reader_json(reader) };
18901890
assert!(!json.is_null());
1891+
1892+
let json_str = unsafe { CString::from_raw(json) };
1893+
let json_content = json_str.to_str().unwrap();
1894+
1895+
assert!(json_content.contains("c2pa.created"));
1896+
// Verify the digital source type was used
1897+
assert!(json_content.contains("digitalSourceType"));
1898+
assert!(json_content.contains("digitalCreation"));
1899+
// Verify there is only one c2pa.created action
1900+
assert_eq!(
1901+
json_content.matches("\"action\": \"c2pa.created\"").count(),
1902+
1
1903+
);
1904+
1905+
TestC2paStream::drop_c_stream(source_stream);
1906+
TestC2paStream::drop_c_stream(read_stream);
1907+
unsafe {
1908+
c2pa_manifest_bytes_free(manifest_bytes_ptr);
1909+
c2pa_builder_free(builder);
1910+
c2pa_signer_free(signer);
1911+
c2pa_reader_free(reader);
1912+
}
1913+
}
1914+
1915+
#[test]
1916+
fn builder_create_intent_empty_and_sign() {
1917+
let source_image = include_bytes!(fixture_path!("IMG_0003.jpg"));
1918+
let mut source_stream = TestC2paStream::from_bytes(source_image.to_vec());
1919+
let dest_vec = Vec::new();
1920+
let mut dest_stream = TestC2paStream::new(dest_vec).into_c_stream();
1921+
1922+
let (signer, builder) = setup_signer_and_builder_for_signing_tests();
1923+
1924+
// The create intent requires needs a digital source type
1925+
let result = unsafe {
1926+
c2pa_builder_set_intent(
1927+
builder,
1928+
C2paBuilderIntent::Create,
1929+
C2paDigitalSourceType::Empty,
1930+
)
1931+
};
1932+
assert_eq!(result, 0);
1933+
1934+
let format = CString::new("image/jpeg").unwrap();
1935+
let mut manifest_bytes_ptr = std::ptr::null();
1936+
let _ = unsafe {
1937+
c2pa_builder_sign(
1938+
builder,
1939+
format.as_ptr(),
1940+
&mut source_stream,
1941+
&mut dest_stream,
1942+
signer,
1943+
&mut manifest_bytes_ptr,
1944+
)
1945+
};
1946+
1947+
// Verify we can read the signed data back
1948+
let dest_test_stream = TestC2paStream::from_c_stream(dest_stream);
1949+
let mut read_stream = dest_test_stream.into_c_stream();
1950+
let format = CString::new("image/jpeg").unwrap();
1951+
1952+
let reader = unsafe { c2pa_reader_from_stream(format.as_ptr(), &mut read_stream) };
1953+
assert!(!reader.is_null());
1954+
1955+
let json = unsafe { c2pa_reader_json(reader) };
1956+
assert!(!json.is_null());
1957+
18911958
let json_str = unsafe { CString::from_raw(json) };
18921959
let json_content = json_str.to_str().unwrap();
18931960

18941961
assert!(json_content.contains("c2pa.created"));
1962+
// Verify the digital source type we picked was used
1963+
assert!(json_content.contains("digitalsourcetype/empty"));
18951964

18961965
TestC2paStream::drop_c_stream(source_stream);
18971966
TestC2paStream::drop_c_stream(read_stream);
@@ -1919,7 +1988,7 @@ mod tests {
19191988
c2pa_builder_set_intent(
19201989
builder,
19211990
C2paBuilderIntent::Edit,
1922-
C2paDigitalSourceType::DigitalCreation,
1991+
C2paDigitalSourceType::Empty,
19231992
)
19241993
};
19251994
assert_eq!(result, 0);
@@ -1951,6 +2020,9 @@ mod tests {
19512020
let json_content = json_str.to_str().unwrap();
19522021

19532022
assert!(json_content.contains("c2pa.opened"));
2023+
// Verify the digital source type parameter was ignored for Edit intent
2024+
// and no "empty" source type appears in the JSON
2025+
assert!(!json_content.contains("digitalsourcetype/empty"));
19542026

19552027
TestC2paStream::drop_c_stream(source_stream);
19562028
TestC2paStream::drop_c_stream(read_stream);
@@ -2114,7 +2186,6 @@ mod tests {
21142186
let json = unsafe { c2pa_reader_json(reader) };
21152187
assert!(!json.is_null());
21162188
let json_str = unsafe { CString::from_raw(json) };
2117-
println!("json: {}", json_str.to_str().unwrap());
21182189
assert!(json_str.to_str().unwrap().contains("Silly Cats 929"));
21192190
assert!(json_str
21202191
.to_str()

cli/tests/fixtures/trust/cawg_sign_settings.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,37 +466,37 @@ operating_system = "auto"
466466
#
467467
# This is a convenience setting and it can be disabled if the information
468468
# is provided manually.
469-
[builder.actions.auto_created_action]
469+
#[builder.actions.auto_created_action]
470470
# Whether to auto create the c2pa.created action.
471-
enabled = true
471+
#enabled = true
472472
# The source type field is required for the c2pa.created action.
473473
#
474474
# For more information, see `c2pa::assertions::actions::source_type`.
475-
source_type = "http://c2pa.org/digitalsourcetype/empty"
475+
#source_type = "http://c2pa.org/digitalsourcetype/empty"
476476

477477
# Settings for configuring how c2pa.opened actions are auto created.
478478
#
479479
# This is a convenience setting and it can be disabled if the information
480480
# is provided manually.
481-
[builder.actions.auto_opened_action]
481+
#[builder.actions.auto_opened_action]
482482
# Whether to auto create the c2pa.opened action.
483-
enabled = true
483+
#enabled = true
484484
# For more information, see `c2pa::assertions::actions::source_type`.
485485
#
486486
# Note this field is optional for the c2pa.opened action.
487-
source_type = "http://c2pa.org/digitalsourcetype/empty"
487+
#source_type = "http://c2pa.org/digitalsourcetype/empty"
488488

489489
# Settings for configuring how c2pa.placed actions are auto created.
490490
#
491491
# This is a convenience setting and it can be disabled if the information
492492
# is provided manually.
493-
[builder.actions.auto_placed_action]
493+
#[builder.actions.auto_placed_action]
494494
# Whether to auto create the c2pa.placed action.
495-
enabled = true
495+
#enabled = true
496496
# For more information, see `c2pa::assertions::actions::source_type`.
497497
#
498498
# Note this field is optional for the c2pa.placed action.
499-
source_type = "http://c2pa.org/digitalsourcetype/empty"
499+
#source_type = "http://c2pa.org/digitalsourcetype/empty"
500500

501501
# Settings for automatic thumbnail generation.
502502
[builder.thumbnail]

docs/settings.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ The `builder` object specifies settings for the Builder API.
125125
| `builder.claim_generator_info` | Object | Default claim generator information. Used if the `Builder` hasn't specified one.<br/>See below. | N/A |
126126
| `builder.certificate_status_fetch` | String | Certificate status fetching scope | null |
127127
| `builder.certificate_status_should_override` | Boolean | Override OCSP with certificate status assertions | null |
128-
| `builder.intent` | object | Default builder intent. The value uses object notation and must be one of: `{"Create": "digitalCapture"}` <br/> `{"Create": "Edit"}` <br/> `{"Create": "Update"}`. | null |
128+
| `builder.intent` | object | Default builder intent. The value uses object notation and must be one of: `{"Create": "digitalCapture"}` <br/> `"Edit"` <br/> `"Update"`. | null |
129129
| `builder.created_assertion_labels` | Array | Array of base assertion labels you want to treated as `created`. When the builder encounters one of these, it will become a created assertion. | null |
130130
| `builder.generate_c2pa_archive` | Boolean | Generate C2PA archive format | null |
131131
| `builder.actions` | Object | Action assertion configuration. | |
132132
| `builder.actions.all_actions_included` | Boolean | Whether all actions are specified | null |
133133
| `builder.actions.templates` | Array | Action templates | null |
134134
| `builder.actions.actions` | Array | Predefined actions to add | null |
135-
| `builder.actions.auto_created_action.enabled` | Boolean | Enable automatic `c2pa.created` actions | true |
135+
| `builder.actions.auto_created_action.enabled` | Boolean | Enable automatic `c2pa.created` actions | false |
136136
| `builder.actions.auto_created_action.source_type` | String | Digital source type for created action | "empty" |
137-
| `builder.actions.auto_opened_action.enabled` | Boolean | Enable automatic `c2pa.opened` actions | true |
137+
| `builder.actions.auto_opened_action.enabled` | Boolean | Enable automatic `c2pa.opened` actions | false |
138138
| `builder.actions.auto_opened_action.source_type` | String | Digital source type for opened action | null |
139-
| `builder.actions.auto_placed_action.enabled` | Boolean | Enable automatic `c2pa.placed` actions | true |
139+
| `builder.actions.auto_placed_action.enabled` | Boolean | Enable automatic `c2pa.placed` actions | false |
140140
| `builder.actions.auto_placed_action.source_type` | String | Digital source type for placed action | null |
141141
| `builder.thumbnail` | Object | Automatic thumbnail generation settings. | |
142142
| `builder.thumbnail.enabled` | Boolean | Enable automatic thumbnails | true |

0 commit comments

Comments
 (0)