Skip to content

Commit ac8acc1

Browse files
committed
Sketch in proposed changes for CAWG validation in Reader interface
1 parent 10202e5 commit ac8acc1

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

c2pa_c_ffi/src/c_api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ pub unsafe extern "C" fn c2pa_free_string_array(ptr: *const *const c_char, count
463463

464464
// Run CAWG post-validation - this is async and requires a runtime.
465465
fn post_validate(result: Result<C2paReader, c2pa::Error>) -> Result<C2paReader, c2pa::Error> {
466+
if true {
467+
todo!("Remove me?");
468+
}
469+
466470
match result {
467471
Ok(mut reader) => {
468472
let runtime = match Runtime::new() {

c2pa_c_ffi/src/json_api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use crate::{Error, Result, SignerInfo};
2424
pub fn read_file(path: &str, data_dir: Option<String>) -> Result<String> {
2525
let mut reader = Reader::from_file(path).map_err(Error::from_c2pa_error)?;
2626
let runtime = Runtime::new().map_err(|e| Error::Other(e.to_string()))?;
27+
if true {
28+
todo!("Remove post_validate_async here?");
29+
}
2730
runtime
2831
.block_on(reader.post_validate_async(&CawgValidator {}))
2932
.map_err(Error::from_c2pa_error)?;

cli/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ fn verify_fragmented(init_pattern: &Path, frag_pattern: &Path) -> Result<Vec<Rea
574574

575575
// run cawg validation if supported
576576
fn validate_cawg(reader: &mut Reader) -> Result<()> {
577+
if true {
578+
todo!("Remove me?");
579+
}
577580
#[cfg(not(target_os = "wasi"))]
578581
{
579582
Runtime::new()?

sdk/examples/cawg_identity.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ mod cawg {
125125

126126
builder.sign_file_async(&signer, source, &dest).await?;
127127

128-
let mut reader = Reader::from_file(dest)?;
129-
130-
reader.post_validate_async(&CawgValidator {}).await?;
128+
let reader = Reader::from_file_async(dest).await?;
131129

132130
println!("{reader}");
133131
Ok(())

sdk/src/identity/validator.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ mod tests {
7878
crate::settings::set_settings_value("verify.verify_trust", false).unwrap();
7979

8080
let mut stream = Cursor::new(CONNECTED_IDENTITIES_VALID);
81-
let mut reader = Reader::from_stream("image/jpeg", &mut stream).unwrap();
82-
reader.post_validate_async(&CawgValidator {}).await.unwrap();
81+
let reader = Reader::from_stream_async("image/jpeg", &mut stream).await.unwrap();
8382
//println!("validation results: {}", reader);
8483
assert_eq!(
8584
reader
@@ -100,8 +99,7 @@ mod tests {
10099
crate::settings::set_settings_value("verify.verify_trust", false).unwrap();
101100

102101
let mut stream = Cursor::new(MULTIPLE_IDENTITIES_VALID);
103-
let mut reader = Reader::from_stream("image/jpeg", &mut stream).unwrap();
104-
reader.post_validate_async(&CawgValidator {}).await.unwrap();
102+
let reader = Reader::from_stream_async("image/jpeg", &mut stream).await.unwrap();
105103
println!("validation results: {reader}");
106104
assert_eq!(
107105
reader
@@ -116,10 +114,9 @@ mod tests {
116114
}
117115

118116
#[c2pa_test_async]
119-
async fn test_post_validate_with_hard_binding_missing() {
117+
async fn test_cawg_validate_with_hard_binding_missing() {
120118
let mut stream = Cursor::new(NO_HARD_BINDING);
121-
let mut reader = Reader::from_stream("image/jpeg", &mut stream).unwrap();
122-
reader.post_validate_async(&CawgValidator {}).await.unwrap();
119+
let reader = Reader::from_stream_async("image/jpeg", &mut stream).await.unwrap();
123120
assert_eq!(
124121
reader
125122
.validation_results()

sdk/src/reader.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@ impl Reader {
136136
Store::from_stream_async(format, &mut stream, verify, &mut validation_log).await
137137
}?;
138138

139-
Self::from_store(store, &validation_log)
139+
let /* mut */ result = Self::from_store(store, &validation_log)?;
140+
if false {
141+
// QUESTION: What to do if we're in the _sync version and there
142+
// are identity assertions? Just report an error (needs async)?
143+
todo!("Add identity assertion validation here");
144+
}
145+
Ok(result)
140146
}
141147

142148
#[async_generic()]
@@ -151,7 +157,11 @@ impl Reader {
151157
Store::from_stream_async(format, &mut stream, verify, &mut validation_log).await
152158
}?;
153159

154-
Self::from_store(store, &validation_log)
160+
let mut result = Self::from_store(store, &validation_log)?;
161+
if false {
162+
todo!("Add identity assertion validation here");
163+
}
164+
Ok(result)
155165
}
156166

157167
#[cfg(feature = "file_io")]
@@ -735,6 +745,9 @@ impl Reader {
735745
validator: &impl AsyncPostValidator
736746
))]
737747
pub fn post_validate(&mut self, validator: &impl PostValidator) -> Result<()> {
748+
if true {
749+
todo!("Remove me");
750+
}
738751
let mut validation_log = StatusTracker::default();
739752
let mut validation_results = self.validation_results.take().unwrap_or_default();
740753
let mut assertion_values = HashMap::new();
@@ -997,6 +1010,9 @@ pub mod tests {
9971010

9981011
#[test]
9991012
fn test_reader_post_validate() -> Result<()> {
1013+
if true {
1014+
todo!("Remove me");
1015+
}
10001016
use crate::{log_item, status_tracker::StatusTracker};
10011017

10021018
let mut reader =

0 commit comments

Comments
 (0)