c2pa 0.80.0

Rust SDK for C2PA (Coalition for Content Provenance and Authenticity) implementors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
// Copyright 2025 Adobe. All rights reserved.
// This file is licensed to you under the Apache License,
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT license (http://opensource.org/licenses/MIT),
// at your option.

// Unless required by applicable law or agreed to in writing,
// this software is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
// specific language governing permissions and limitations under
// each license.

//! This version of the validation method tests cover the case where the
//! [`StatusTracker`] is configured to continue when possible.

use std::io::Cursor;

use c2pa_macros::c2pa_test_async;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test;

use crate::{
    crypto::raw_signature::SigningAlg,
    identity::{x509::X509SignatureVerifier, IdentityAssertion},
    status_tracker::{LogKind, StatusTracker},
    Reader,
};

/// An identity assertion MUST contain a valid CBOR data structure that contains
/// the required fields as documented in the identity rule in [Section 5.2,
/// “CBOR schema”]. The `cawg.identity.cbor.invalid` error code SHALL be used to
/// report assertions that do not follow this rule.
///
/// [Section 5.2, “CBOR schema”]: https://cawg.io/identity/1.1-draft/#_cbor_schema
#[c2pa_test_async]
async fn malformed_cbor() {
    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/malformed_cbor.jpg");

    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find malformed CBOR error.
    let mut status_tracker = StatusTracker::default();

    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    let ia_err = ia_results[0].as_ref().unwrap_err();
    assert_eq!(ia_err.to_string(), "could not decode assertion cawg.identity (version (no version), content type application/json): missing field `signer_payload`");

    assert_eq!(status_tracker.logged_items().len(), 1);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);
    assert!(log.label.ends_with("/c2pa.assertions/cawg.identity"));
    assert_eq!(log.description, "invalid CBOR");
    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.cbor.invalid"
    );
}

/// A validator SHALL NOT consider any extra fields not documented in the
/// `identity` rule during the validation process.
#[c2pa_test_async]
async fn extra_fields() {
    // The test asset `extra_field.jpg` was written using a temporarily modified
    // version of this SDK that generated an `other_stuff` string value at the top
    // level of the identity assertion CBOR.

    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/extra_field.jpg");
    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find malformed CBOR error.
    let mut status_tracker = StatusTracker::default();

    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    let ia = ia_results[0].as_ref().unwrap();
    dbg!(ia);

    let sp = &ia.signer_payload;
    assert_eq!(sp.referenced_assertions.len(), 1);

    assert_eq!(
        sp.referenced_assertions[0].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    // TEMPORARY: Should report success code.
    assert_eq!(status_tracker.logged_items().len(), 0);

    // let log = &status_tracker.logged_items()[0];
    // assert_eq!(log.kind, LogKind::Failure);
    // assert_eq!(log.label, "cawg.identity");
    // assert_eq!(log.description, "invalid CBOR");
    // assert_eq!(
    //     log.validation_status.as_ref().unwrap().as_ref(),
    //     "cawg.identity.cbor.invalid"
    // );
}

/// For each entry in `signer_payload.referenced_assertions`, the validator MUST
/// verify that the same entry exists in either the `created_assertions` or
/// `gathered_assertions` entry of the C2PA claim. (For version 1 claims, the
/// entry must appear in the `assertions` entry.) The
/// `cawg.identity.assertion.mismatch` error code SHALL be used to report
/// violations of this rule.
#[c2pa_test_async]
async fn assertion_not_in_claim_v1() {
    // The test asset `extra_assertion_claim_v1.jpg` was written using a temporarily
    // modified version of this SDK that incorrectly added an extra hashed URI to
    // `referenced_assertions` that is not present in the claim.

    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/extra_assertion_claim_v1.jpg");

    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find extra assertion error.
    let mut status_tracker = StatusTracker::default();
    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    // This condition is parseable, but incorrect. There should be a validation
    // status log for this failure.
    let ia = ia_results[0].as_ref().unwrap();

    let sp = &ia.signer_payload;
    assert_eq!(sp.referenced_assertions.len(), 2);

    assert_eq!(
        sp.referenced_assertions[0].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(
        sp.referenced_assertions[1].url(),
        "self#jumbf=c2pa/urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4/c2pa.assertions/testing.bogus.assertion".to_owned()
    );

    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    let x509_verifier = X509SignatureVerifier::default();
    let sig_info = ia
        .validate(
            reader.active_manifest().unwrap(),
            &mut status_tracker,
            &x509_verifier,
        )
        .await
        .unwrap();

    assert_eq!(status_tracker.logged_items().len(), 2);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:4baf4dc3-c464-4c70-902b-d28d832a29e3/c2pa.assertions/cawg.identity"
    );

    assert_eq!(log.description, "referenced assertion not in claim");

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.assertion.mismatch"
    );

    let log = &status_tracker.logged_items()[1];
    assert_eq!(log.kind, LogKind::Success);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:4baf4dc3-c464-4c70-902b-d28d832a29e3/c2pa.assertions/cawg.identity"
    );

    assert_eq!(
        log.description,
        "signing certificate trusted, found in User trust anchors"
    );

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "signingCredential.trusted"
    );

    let cert_info = &sig_info.cert_info;
    assert_eq!(cert_info.alg.unwrap(), SigningAlg::Ed25519);
    assert_eq!(
        cert_info.issuer_org.as_ref().unwrap(),
        "C2PA Test Signing Cert"
    );
}

// For each entry in `signer_payload.referenced_assertions`, the validator MUST
// verify that the same entry exists in either the `created_assertions` or
// `gathered_assertions` entry of the C2PA claim. (For version 1 claims, the
// entry must appear in the `assertions` entry.) The
// `cawg.identity.assertion.mismatch` error code SHALL be used to report
// violations of this rule.
// #[c2pa_test_async]
// #[ignore]
// async fn assertion_not_in_claim_v2() {
//     todo!("Generate a suitable V2 asset with an extra assertion");
// }

/// The validator SHOULD verify that no entry in
/// `signer_payload.referenced_assertions` is duplicated. The
/// `cawg.identity.assertion.duplicate` error code SHALL be used to report
/// violations of this rule.
#[c2pa_test_async]
async fn duplicate_assertion_reference() {
    // The test asset `duplicate_assertion_reference.jpg` was written using a
    // temporarily modified version of this SDK that incorrectly added a
    // duplicate hashed URI to `referenced_assertions`.

    let format = "image/jpeg";
    let test_image =
        include_bytes!("../fixtures/validation_method/duplicate_assertion_reference.jpg");

    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find extra assertion error.
    let mut status_tracker = StatusTracker::default();
    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    // This condition is parseable, but incorrect. There should be a validation
    // status log for this failure.
    let ia = ia_results[0].as_ref().unwrap();

    let sp = &ia.signer_payload;
    assert_eq!(sp.referenced_assertions.len(), 2);

    assert_eq!(
        sp.referenced_assertions[0].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(
        sp.referenced_assertions[1].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    let x509_verifier = X509SignatureVerifier::default();
    let sig_info = ia
        .validate(
            reader.active_manifest().unwrap(),
            &mut status_tracker,
            &x509_verifier,
        )
        .await
        .unwrap();

    assert_eq!(status_tracker.logged_items().len(), 2);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:9b9f27bc-394b-419f-a8d5-81777c9fa76c/c2pa.assertions/cawg.identity"
    );

    assert_eq!(log.description, "multiple references to same assertion");

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.assertion.duplicate"
    );

    let log = &status_tracker.logged_items()[1];
    assert_eq!(log.kind, LogKind::Success);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:9b9f27bc-394b-419f-a8d5-81777c9fa76c/c2pa.assertions/cawg.identity"
    );

    assert_eq!(
        log.description,
        "signing certificate trusted, found in User trust anchors"
    );
    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "signingCredential.trusted"
    );

    let cert_info = &sig_info.cert_info;
    assert_eq!(cert_info.alg.unwrap(), SigningAlg::Ed25519);
    assert_eq!(
        cert_info.issuer_org.as_ref().unwrap(),
        "C2PA Test Signing Cert"
    );
}

/// The validator MUST ensure that `signer_payload.referenced_assertions`
/// contains at least one _hard binding_ assertion as described in [Section 9.2,
/// “Hard bindings”] of the C2PA technical specification. The
/// `cawg.identity.hard_binding_missing` error code SHALL be used to report a
/// missing hard binding assertion.
///
/// [Section 9.2, “Hard bindings”]: https://c2pa.org/specifications/specifications/2.1/specs/C2PA_Specification.html#_hard_bindings
#[c2pa_test_async]
async fn no_hard_binding() {
    // The test asset `duplicate_assertion.jpg` was written using a temporarily
    // modified version of this SDK that incorrectly added a duplicate hashed URI to
    // `referenced_assertions`.

    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/no_hard_binding.jpg");

    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find extra assertion error.
    let mut status_tracker = StatusTracker::default();
    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    // This condition is parseable, but incorrect. There should be a validation
    // status log for this failure.
    let ia = ia_results[0].as_ref().unwrap();

    let sp = &ia.signer_payload;
    assert!(sp.referenced_assertions.is_empty());
    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    let x509_verifier = X509SignatureVerifier::default();
    let sig_info = ia
        .validate(
            reader.active_manifest().unwrap(),
            &mut status_tracker,
            &x509_verifier,
        )
        .await
        .unwrap();

    assert_eq!(status_tracker.logged_items().len(), 2);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:6df39abb-e6b4-49af-a826-ba44b7b248b7/c2pa.assertions/cawg.identity"
    );

    assert_eq!(log.description, "no hard binding assertion");

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.hard_binding_missing"
    );

    let log = &status_tracker.logged_items()[1];
    assert_eq!(log.kind, LogKind::Success);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:6df39abb-e6b4-49af-a826-ba44b7b248b7/c2pa.assertions/cawg.identity"
    );

    assert_eq!(
        log.description,
        "signing certificate trusted, found in User trust anchors"
    );

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "signingCredential.trusted"
    );

    let cert_info = &sig_info.cert_info;
    assert_eq!(cert_info.alg.unwrap(), SigningAlg::Ed25519);
    assert_eq!(
        cert_info.issuer_org.as_ref().unwrap(),
        "C2PA Test Signing Cert"
    );
}

/// The validator MUST maintain a list of valid `signer_payload.sig_type` values
/// and corresponding code paths for the `signature` values that it is prepared
/// to accept. Validators SHOULD be prepared to accept all signature types
/// described in [Section 8, “Credentials, signatures, and validation methods”].
/// The `cawg.identity.sig_type.unknown` error code SHALL be used to report
/// assertions that contain unrecognized `signer_payload.sig_type` values.
///
/// [Section 8, “Credentials, signatures, and validation methods”]: https://cawg.io/identity/1.1-draft/#_credentials_signatures_and_validation_methods
///
/// This test is repeated for each implementation of [`SignatureVerifier`]
/// because the implementation of that type is the one that reports the error.
mod invalid_sig_type {
    use std::io::Cursor;

    #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
    use wasm_bindgen_test::wasm_bindgen_test;

    use super::*;
    use crate::{
        identity::{
            claim_aggregation::IcaSignatureVerifier, x509::X509SignatureVerifier, IdentityAssertion,
        },
        status_tracker::{LogKind, StatusTracker},
        Reader,
    };

    #[c2pa_test_async]
    async fn x509_signature_verifier() {
        // The test asset `invalid_sig_type.jpg` was written using a temporarily
        // modified version of this SDK that added a proof-of-concept signature type
        // that's not intended for general consumption. The validator in this test case
        // is not configured to read that signature type.
        let format = "image/jpeg";
        let test_image = include_bytes!("../fixtures/validation_method/invalid_sig_type.jpg");

        let mut test_image = Cursor::new(test_image);

        // Initial read with default `Reader` should pass without issues.
        let reader = Reader::default()
            .with_stream(format, &mut test_image)
            .unwrap();
        assert_eq!(reader.validation_status(), None);

        // Re-parse with identity assertion code should find extra assertion error.
        let mut status_tracker = StatusTracker::default();

        let active_manifest = reader.active_manifest().unwrap();
        let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
            IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

        assert_eq!(ia_results.len(), 1);

        // This condition is parseable, but incorrect. There should be a validation
        // status log for this failure.
        let ia = ia_results[0].as_ref().unwrap();

        let sp = &ia.signer_payload;
        assert_eq!(sp.referenced_assertions.len(), 1);

        assert_eq!(
            sp.referenced_assertions[0].url(),
            "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
        );

        assert_eq!(sp.sig_type, "INVALID.identity.naive_credential".to_owned());

        // Intentionally not using NaiveSignatureVerifier here.
        let x509_verifier = X509SignatureVerifier::default();
        let err = ia
            .validate(
                reader.active_manifest().unwrap(),
                &mut status_tracker,
                &x509_verifier,
            )
            .await
            .unwrap_err();

        // Comparing via strings since CoseError doesn't impl PartialEq. :-(
        assert_eq!(
            err.to_string(),
            "unable to parse a signature of type \"INVALID.identity.naive_credential\""
        );

        assert_eq!(status_tracker.logged_items().len(), 1);

        let log = &status_tracker.logged_items()[0];
        assert_eq!(log.kind, LogKind::Failure);

        assert_eq!(
            log.label,
            "self#jumbf=/c2pa/test:urn:uuid:0f746efd-5e87-43d9-9032-bfc0e2b0e98f/c2pa.assertions/cawg.identity"
        );

        assert_eq!(log.description, "unsupported signature type");

        assert_eq!(
            log.validation_status.as_ref().unwrap().as_ref() as &str,
            "cawg.identity.sig_type.unknown"
        );
    }

    #[c2pa_test_async]
    async fn ica_verifier() {
        // The test asset `invalid_sig_type.jpg` was written using a temporarily
        // modified version of this SDK that added a proof-of-concept signature type
        // that's not intended for general consumption. The validator in this test case
        // is not configured to read that signature type.

        let format = "image/jpeg";
        let test_image = include_bytes!("../fixtures/validation_method/invalid_sig_type.jpg");

        let mut test_image = Cursor::new(test_image);

        // Initial read with default `Reader` should pass without issues.
        let reader = Reader::default()
            .with_stream(format, &mut test_image)
            .unwrap();
        assert_eq!(reader.validation_status(), None);

        // Re-parse with identity assertion code should find extra assertion error.
        let mut status_tracker = StatusTracker::default();
        let active_manifest = reader.active_manifest().unwrap();
        let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
            IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

        assert_eq!(ia_results.len(), 1);

        // This condition is parseable, but incorrect. There should be a validation
        // status log for this failure.
        let ia = ia_results[0].as_ref().unwrap();

        let sp = &ia.signer_payload;
        assert_eq!(sp.referenced_assertions.len(), 1);

        assert_eq!(
            sp.referenced_assertions[0].url(),
            "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
        );

        assert_eq!(sp.sig_type, "INVALID.identity.naive_credential".to_owned());

        // Intentionally not using NaiveSignatureVerifier here.
        let ica_verifier = IcaSignatureVerifier {};
        let err = ia
            .validate(
                reader.active_manifest().unwrap(),
                &mut status_tracker,
                &ica_verifier,
            )
            .await
            .unwrap_err();

        // Comparing via strings since CoseError doesn't impl PartialEq. :-(
        assert_eq!(
            err.to_string(),
            "unable to parse a signature of type \"INVALID.identity.naive_credential\""
        );

        assert_eq!(status_tracker.logged_items().len(), 1);

        let log = &status_tracker.logged_items()[0];
        assert_eq!(log.kind, LogKind::Failure);

        assert_eq!(
            log.label,
            "self#jumbf=/c2pa/test:urn:uuid:0f746efd-5e87-43d9-9032-bfc0e2b0e98f/c2pa.assertions/cawg.identity"
        );

        assert_eq!(log.description, "unsupported signature type");

        assert_eq!(
            log.validation_status.as_ref().unwrap().as_ref() as &str,
            "cawg.identity.sig_type.unknown"
        );
    }
}

/// The `pad1` and `pad2` fields of an identity assertion MUST contain only
/// zero-value (`0x00`) bytes. The `cawg.identity.pad.invalid` error code SHALL
/// be used to report assertions that contain other values in these fields.
#[c2pa_test_async]
async fn pad1_invalid() {
    // The test asset `pad1_invalid.jpg` was written using a temporarily
    // modified version of this SDK that incorrectly placed a non-zero value in the
    // `pad1` field.

    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/pad1_invalid.jpg");
    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find invalid pad error.
    let mut status_tracker = StatusTracker::default();
    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    // This condition is parseable, but incorrect. There should be a validation
    // status log for this failure.
    let ia = ia_results[0].as_ref().unwrap();

    let sp = &ia.signer_payload;
    assert_eq!(sp.referenced_assertions.len(), 1);

    assert_eq!(
        sp.referenced_assertions[0].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    let x509_verifier = X509SignatureVerifier::default();
    let sig_info = ia
        .validate(
            reader.active_manifest().unwrap(),
            &mut status_tracker,
            &x509_verifier,
        )
        .await
        .unwrap();

    assert_eq!(status_tracker.logged_items().len(), 2);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:8d938dd8-d194-4d24-a0bf-55aae143b692/c2pa.assertions/cawg.identity"
    );

    assert_eq!(log.description, "invalid value in pad fields");

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.pad.invalid"
    );

    let log = &status_tracker.logged_items()[1];
    assert_eq!(log.kind, LogKind::Success);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:8d938dd8-d194-4d24-a0bf-55aae143b692/c2pa.assertions/cawg.identity"
    );

    assert_eq!(
        log.description,
        "signing certificate trusted, found in User trust anchors"
    );

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "signingCredential.trusted"
    );

    let cert_info = &sig_info.cert_info;
    assert_eq!(cert_info.alg.unwrap(), SigningAlg::Ed25519);
    assert_eq!(
        cert_info.issuer_org.as_ref().unwrap(),
        "C2PA Test Signing Cert"
    );
}

#[c2pa_test_async]
async fn pad2_invalid() {
    // The test asset `pad1_invalid.jpg` was written using a temporarily
    // modified version of this SDK that incorrectly placed a non-zero value in the
    // `pad1` field.

    let format = "image/jpeg";
    let test_image = include_bytes!("../fixtures/validation_method/pad2_invalid.jpg");

    let mut test_image = Cursor::new(test_image);

    // Initial read with default `Reader` should pass without issues.
    let reader = Reader::default()
        .with_stream(format, &mut test_image)
        .unwrap();
    assert_eq!(reader.validation_status(), None);

    // Re-parse with identity assertion code should find invalid pad error.
    let mut status_tracker = StatusTracker::default();

    let active_manifest = reader.active_manifest().unwrap();
    let ia_results: Vec<Result<IdentityAssertion, crate::Error>> =
        IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect();

    assert_eq!(ia_results.len(), 1);

    // This condition is parseable, but incorrect. There should be a validation
    // status log for this failure.
    let ia = ia_results[0].as_ref().unwrap();

    let sp = &ia.signer_payload;
    assert_eq!(sp.referenced_assertions.len(), 1);

    assert_eq!(
        sp.referenced_assertions[0].url(),
        "self#jumbf=c2pa.assertions/c2pa.hash.data".to_owned()
    );

    assert_eq!(sp.sig_type, "cawg.x509.cose".to_owned());

    let x509_verifier = X509SignatureVerifier::default();
    let sig_info = ia
        .validate(
            reader.active_manifest().unwrap(),
            &mut status_tracker,
            &x509_verifier,
        )
        .await
        .unwrap();

    assert_eq!(status_tracker.logged_items().len(), 2);

    let log = &status_tracker.logged_items()[0];
    assert_eq!(log.kind, LogKind::Failure);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:d686f86c-63d9-43e9-822c-7789acefe102/c2pa.assertions/cawg.identity"
    );

    assert_eq!(log.description, "invalid value in pad fields");

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "cawg.identity.pad.invalid"
    );

    let log = &status_tracker.logged_items()[1];
    assert_eq!(log.kind, LogKind::Success);

    assert_eq!(
        log.label,
        "self#jumbf=/c2pa/test:urn:uuid:d686f86c-63d9-43e9-822c-7789acefe102/c2pa.assertions/cawg.identity"
    );

    assert_eq!(
        log.description,
        "signing certificate trusted, found in User trust anchors"
    );

    assert_eq!(
        log.validation_status.as_ref().unwrap().as_ref() as &str,
        "signingCredential.trusted"
    );

    let cert_info = &sig_info.cert_info;
    assert_eq!(cert_info.alg.unwrap(), SigningAlg::Ed25519);
    assert_eq!(
        cert_info.issuer_org.as_ref().unwrap(),
        "C2PA Test Signing Cert"
    );
}