c2pa 0.91.11

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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
// Copyright 2022 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.

#[cfg(feature = "file_io")]
use std::path::Path;

use async_generic::async_generic;

use crate::{
    assertion::{Assertion, AssertionBase, AssertionData},
    assertions::{
        self, c2pa_action, labels,
        labels::{CLAIM_THUMBNAIL, DATABOX_STORE},
        Actions, BmffHash, BoxHash, CollectionHash, DataHash, DataMap, Ingredient, Metadata,
        Relationship,
    },
    claim::Claim,
    context::{Context, ProgressPhase},
    cose_validator::{
        check_ocsp_status, check_ocsp_status_async, get_signing_cert_serial_num, verify_cose,
        verify_cose_async,
    },
    crypto::cose::{parse_cose_sign1, CertificateInfo, CertificateTrustPolicy},
    error::{Error, Result},
    jumbf,
    jumbf::labels::{
        assertion_label_from_uri, manifest_label_from_uri, manifest_label_to_parts,
        to_absolute_uri, to_assertion_uri, to_manifest_uri, to_signature_uri,
    },
    log_item,
    read_seek::ReadSeek,
    resource_store::UriOrResource,
    settings::Settings,
    status_tracker::StatusTracker,
    store::StoreValidationInfo,
    utils::hash_utils::{vec_compare, HashRange},
    validation_status,
};

/// Failure codes that reject a claim because of its signing credential, before
/// the claim signature itself is validated.
///
/// `signingCredential.untrusted` is deliberately not included: a manifest whose
/// signer is not on a trust list can still be Valid (C2PA Trust Model, "Valid
/// Manifest"), which requires `claimSignature.validated`.
const SIGNING_CREDENTIAL_REJECTIONS: &[&str] = &[
    validation_status::SIGNING_CREDENTIAL_INVALID,
    validation_status::SIGNING_CREDENTIAL_REVOKED,
    validation_status::SIGNING_CREDENTIAL_EXPIRED,
    validation_status::CLAIM_SIGNATURE_OUTSIDE_VALIDITY,
    validation_status::ALGORITHM_UNSUPPORTED,
];

// Enum to encapsulate the data type of the source asset.  This simplifies
// having different implementations for functions as a single entry point can be
// used to handle different data types.
#[allow(dead_code)] // Bytes and third param in StreamFragment not used without v1_api feature
pub enum ClaimAssetData<'a> {
    #[cfg(feature = "file_io")]
    Path(&'a Path),
    Bytes(&'a [u8], &'a str),
    Stream(&'a mut dyn ReadSeek, &'a str),
    StreamFragment(&'a mut dyn ReadSeek, &'a mut dyn ReadSeek, &'a str),
    #[cfg(feature = "file_io")]
    StreamFragments(&'a mut dyn ReadSeek, &'a Vec<std::path::PathBuf>, &'a str),
}

impl ClaimAssetData<'_> {
    /// Returns the asset's format (MIME type or extension), if it can be determined.
    pub(crate) fn format(&self) -> Option<String> {
        match self {
            #[cfg(feature = "file_io")]
            ClaimAssetData::Path(path) => crate::format_from_path(path),
            ClaimAssetData::Bytes(_, asset_type)
            | ClaimAssetData::Stream(_, asset_type)
            | ClaimAssetData::StreamFragment(_, _, asset_type) => Some((*asset_type).to_owned()),
            #[cfg(feature = "file_io")]
            ClaimAssetData::StreamFragments(_, _, asset_type) => Some((*asset_type).to_owned()),
        }
    }
}

pub(crate) const ALLOWED_UPDATE_MANIFEST_ACTIONS: [&str; 4] = [
    "c2pa.edited.metadata",
    "c2pa.opened",
    "c2pa.published",
    "c2pa.redacted",
];

/// Per C2PA 15.12, the exclusion range containing the manifest store must hold only
/// the manifest store and padding. `manifest_store_range` is the manifest's real
/// location, found independently by re-parsing the asset; a legitimate exclusion
/// covers exactly it. A mismatch means the exclusion covers non-manifest bytes -- a
/// detached manifest applied to an unrelated asset, or content injected into the
/// space freed by shrinking the manifest.
fn data_hash_exclusions_match_manifest(
    exclusions: &[HashRange],
    manifest_store_range: Option<&HashRange>,
    is_embedded: bool,
) -> bool {
    // Remote/sidecar manifests carry a placeholder exclusion that excludes no
    // bytes; the whole asset is hashed, so there is nothing to police.
    if !exclusions.iter().any(|e| e.length() > 0) {
        return true;
    }

    match manifest_store_range {
        // Manifest present in this asset: an exclusion must cover exactly it.
        Some(range) => exclusions.contains(range),
        // Manifest not in this asset: allow only if it was read from here
        // (embedded); a detached manifest on an unrelated asset is rejected (#2643).
        None => is_embedded,
    }
}

impl Claim {
    /// Verify that the claim `signature` field points to the signature box of this manifest.
    ///
    /// The claim label comes from the JUMBF label of the manifest, which is outside the signed
    /// claim. Since Spec 2.3 (ยง10.2.2) the `signature` field must be an absolute URI. That URI
    /// names the manifest label, so it binds the label to the signed claim. Without it, the label
    /// could be changed without invalidating the signature. Earlier specs, including the Spec 2.2
    /// claim example, allow a relative URI to this manifest's signature box, so V2 claims that do
    /// not declare Spec 2.3 or later may still use one. V1 claims may always use a relative URI.
    pub(crate) fn verify_signature_box_uri(
        claim: &Claim,
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        let is_signature_box = jumbf::labels::box_name_from_uri(&claim.signature)
            .unwrap_or_default()
            == jumbf::labels::SIGNATURE;

        let sig_box_err = match manifest_label_from_uri(&claim.signature) {
            Some(signature_url) if signature_url != claim.label() => true,
            Some(_) => !is_signature_box,
            // relative signature box
            None => Self::requires_absolute_signature_uri(claim) || !is_signature_box,
        };

        if sig_box_err {
            log_item!(
                to_signature_uri(claim.label()),
                "signature missing",
                "verify_claim"
            )
            .validation_status(validation_status::CLAIM_SIGNATURE_MISSING)
            .failure(validation_log, Error::ClaimMissingSignatureBox)?;
        }
        Ok(())
    }

    /// Whether the claim declares Spec 2.3 or later, which requires an absolute `signature` URI.
    ///
    /// The declared version is read from `claim_generator_info` (Spec 2.4) or the claim map
    /// (Spec 2.3). Both are inside the signed claim, so the declaration cannot be stripped
    /// without invalidating the signature. A declared version that cannot be parsed is treated
    /// as requiring an absolute URI.
    fn requires_absolute_signature_uri(claim: &Claim) -> bool {
        if claim.version() < 2 {
            return false;
        }
        let Some(declared) = claim.spec_version().or(claim.spec_version.as_ref()) else {
            return false;
        };
        let mut parts = declared.split('.').map(|p| p.trim().parse::<u64>());
        match (parts.next(), parts.next()) {
            (Some(Ok(major)), Some(Ok(minor))) => (major, minor) >= (2, 3),
            (Some(Ok(major)), None) => major > 2,
            _ => true,
        }
    }

    /// Verify claim signature, assertion store and asset hashes
    /// claim - claim to be verified
    /// asset_bytes - reference to bytes of the asset
    #[async_generic]
    pub(crate) fn verify_claim(
        claim: &Claim,
        svi: &StoreValidationInfo<'_>,
        cert_check: bool,
        ctp: &CertificateTrustPolicy,
        validation_log: &mut StatusTracker,
        context: &Context,
    ) -> Result<()> {
        // Parse COSE signed data (signature) and validate it.
        let sig = claim.signature_val();
        let additional_bytes: Vec<u8> = Vec::new();

        let mut adjusted_settings = context.settings().clone();
        if claim.version() == 1 {
            adjusted_settings.verify.verify_timestamp_trust = false;
        }

        // use the signature uri as the current uri while validating the signature info
        validation_log.push_current_uri(to_signature_uri(claim.label()));

        Self::verify_signature_box_uri(claim, validation_log)?;

        // for V2 and greater claims the label must conform
        if claim.version() > 1 && manifest_label_to_parts(claim.label()).is_none() {
            log_item!(
                to_manifest_uri(claim.label()),
                "claim box label invalid",
                "verify_claim"
            )
            .validation_status(validation_status::CLAIM_MALFORMED)
            .failure(validation_log, Error::ClaimInvalidContent)?;
        }

        // If we are validating a claim that has been loaded from a file
        // we need the original data but if we are signing, we generate the data
        // This avoids cloning the data when we are only referencing it.
        let mut _generated_data = vec![];
        let data = match claim.original_bytes {
            Some(ref original_bytes) => original_bytes,
            None => {
                _generated_data = claim.data()?;
                &_generated_data
            }
        };

        let sign1 = parse_cose_sign1(sig, data, validation_log)?;

        let certificate_serial_num = get_signing_cert_serial_num(&sign1)?.to_string();
        // check certificate revocation (revocation/trust failures are already recorded in validation_log)
        let ocsp_result = if _sync {
            check_ocsp_status(
                &sign1,
                data,
                ctp,
                svi.certificate_statuses.get(&certificate_serial_num),
                svi.timestamps.get(claim.label()),
                validation_log,
                context,
            )
        } else {
            check_ocsp_status_async(
                &sign1,
                data,
                ctp,
                svi.certificate_statuses.get(&certificate_serial_num),
                svi.timestamps.get(claim.label()),
                validation_log,
                context,
            )
            .await
        };
        let mut ocsp_rejected = false;
        if let Err(err) = ocsp_result {
            if !matches!(err, Error::CertificateTrustError(_)) {
                validation_log.pop_current_uri();
                return Err(err);
            }
            ocsp_rejected = true;
        }

        context.check_progress(ProgressPhase::VerifyingSignature, 1, 1)?;
        let cose_log_start = validation_log.logged_items().len();
        let verified = if _sync {
            verify_cose(
                sig,
                data,
                &additional_bytes,
                cert_check,
                ctp,
                svi.timestamps.get(claim.label()),
                validation_log,
                &adjusted_settings,
            )
        } else {
            verify_cose_async(
                sig,
                data,
                &additional_bytes,
                cert_check,
                ctp,
                svi.timestamps.get(claim.label()),
                validation_log,
                &adjusted_settings,
            )
            .await
        };

        // The OCSP check found the signing credential revoked. That outranks
        // the certificate chain reaching a trust anchor, so do not report the
        // credential as trusted.
        if ocsp_rejected {
            validation_log.remove_status_since(
                cose_log_start,
                validation_status::SIGNING_CREDENTIAL_TRUSTED,
            );
        }

        let result = Claim::verify_internal(claim, svi, verified, validation_log, context);
        validation_log.pop_current_uri();
        result
    }

    // Build a diagnostic message for ingredientMismatch errors, showing the failing
    // action's index, type, each referenced ingredient URL, and the actual relationship
    // found (vs. the expected one).
    fn ingredient_mismatch_msg(
        claim: &Claim,
        action_index: usize,
        action_type: &str,
        params: &assertions::ActionParameters,
        expected_relationship: &str,
    ) -> String {
        let urls: Vec<String> = {
            let mut v = Vec::new();
            if let Some(h) = &params.ingredient {
                v.push(h.url());
            }
            if let Some(hs) = &params.ingredients {
                v.extend(hs.iter().map(|h| h.url()));
            }
            v
        };

        let details: Vec<String> = urls
            .iter()
            .map(|url| {
                let found = assertion_label_from_uri(url).and_then(|target| {
                    claim.ingredient_assertions().iter().find_map(|i| {
                        if i.label() == target {
                            Ingredient::from_assertion(i.assertion()).ok().map(|ing| {
                                let rel = ing.relationship.as_str();
                                let title = ing.title.as_deref().unwrap_or("<no title>");
                                format!("'{}' (title='{}', relationship='{}')", url, title, rel)
                            })
                        } else {
                            None
                        }
                    })
                });
                found.unwrap_or_else(|| format!("'{}' (not found in ingredient assertions)", url))
            })
            .collect();

        format!(
            "action[{}] ('{}') must have valid ingredient with {} relationship; ingredient(s): [{}]",
            action_index,
            action_type,
            expected_relationship,
            if details.is_empty() {
                "none".to_string()
            } else {
                details.join(", ")
            }
        )
    }

    // Perform 2.x action validation check, hashed URI references are only checked
    // to be present and to be valild references an actual manifest store object.
    //The hashed uri's hashes are are validated as part of the Claim assertions check.
    pub(super) fn verify_actions(
        claim: &Claim,
        svi: &StoreValidationInfo<'_>,
        validation_log: &mut StatusTracker,
        settings: &Settings,
    ) -> Result<()> {
        let all_actions = claim.action_assertions();
        let created_actions = claim.created_action_assertions();
        let gathered_actions = claim.gathered_action_assertions();
        let claim_label = claim.label().to_owned();

        // for v1 claims check the single actions assertion
        if claim.version() < 2 && all_actions.len() > 1 {
            log_item!(
                claim_label.clone(),
                "only one action assertion allowed for v1 claims",
                "verify_actions"
            )
            .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
            .failure(
                validation_log,
                Error::ValidationRule("No Action array in Actions".into()),
            )?;
        }

        // Skip further checks for v1 claims if not in strict validation mode
        if claim.version() == 1 && !settings.verify.strict_v1_validation {
            return Ok(()); // no further checks for v1 claims
        }

        // 1. make sure every action has an actions array that is not empty
        if let Some(bad_assertion) = all_actions.iter().find(|a| {
            if let Ok(actions) = Actions::from_assertion(a.assertion()) {
                actions.actions().is_empty()
            } else {
                false
            }
        }) {
            let label = to_assertion_uri(claim.label(), &bad_assertion.label());
            log_item!(label, "Actions missing action array", "verify_actions")
                .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                .failure(
                    validation_log,
                    Error::ValidationRule("No Action array in Actions".into()),
                )?;

            // failure full stop
            return Err(Error::ValidationRule("No Action array in Actions".into()));
        }

        // Skip further checks for v1 claims if not in strict validation mode
        if claim.version() == 1 && !settings.verify.strict_v1_validation {
            return Ok(()); // no further checks for v1 claims
        }

        let mut first_actions_assertion = None;

        // check created actions then gathered actions if not found in created actions
        // starting with 2.4 these assertion can only be in created assertions
        for actions in [&created_actions, &gathered_actions] {
            if let Some(assertion) = actions.first() {
                let first_actions = Actions::from_assertion(assertion.assertion())?;
                let first_actions_first_action = &first_actions.actions().first();

                if let Some(first_actions_first_action) = first_actions_first_action {
                    if first_actions_first_action.action() == c2pa_action::OPENED
                        || first_actions_first_action.action() == c2pa_action::CREATED
                    {
                        first_actions_assertion = Some(assertion);
                    }
                }
            }
        }

        // there can be only 1 of either c2pa.opened or c2pa.created, and they cannot both exist
        let inception_action_count = {
            let mut count = 0usize;
            for assertion in all_actions.iter() {
                let Ok(actions) = Actions::from_assertion(assertion.assertion()) else {
                    continue;
                };
                for action in actions.actions() {
                    if action.action() == c2pa_action::OPENED
                        || action.action() == c2pa_action::CREATED
                    {
                        count += 1;
                    }
                }
            }
            count
        };

        if inception_action_count > 1 {
            log_item!(
                claim_label.clone(),
                "cannot have more than one c2pa.created or c2pa.opened action",
                "verify_actions"
            )
            .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
            .failure(
                validation_log,
                Error::ValidationRule(
                    "cannot have more than one c2pa.created or c2pa.opened action".into(),
                ),
            )?;
        }

        // 2.a first actions assertion must start with an open or created action, do not apply to update manifests
        if first_actions_assertion.is_none() && !claim.update_manifest() {
            log_item!(
                claim_label,
                "first action must be created or opened",
                "verify_actions"
            )
            .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
            .failure(
                validation_log,
                Error::ValidationRule("first action must be created or opened".into()),
            )?;
        }

        // perform all actions checks
        for (index, actions_assertion) in all_actions.iter().enumerate() {
            let actions = Actions::from_assertion(actions_assertion.assertion())?;
            let label = to_assertion_uri(claim.label(), &actions_assertion.label());

            // 1. Actions must have actions array
            if actions.actions().is_empty() {
                log_item!(
                    label.clone(),
                    "actions must have action array",
                    "verify_actions"
                )
                .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                .failure(
                    validation_log,
                    Error::ValidationRule("actions must have action array".into()),
                )?;
            }

            let mut icons = Vec::new();
            // 2.e.i Actions icons
            if let Some(cgi_vec) = actions.software_agents() {
                for cgi in cgi_vec {
                    if let Some(icon) = cgi.icon() {
                        icons.push(icon);
                    }
                }
            }
            // 2.f Template icons
            if let Some(template_vec) = actions.templates() {
                for template in template_vec {
                    if let Some(icon) = &template.icon {
                        icons.push(icon);
                    }
                }
            }
            // check top level icons
            if !icons.is_empty() {
                Claim::verify_icons(claim, &label, &icons, validation_log)?;
            }

            for (action_index, action) in actions.actions().iter().enumerate() {
                //dbg!("action: {:?}", &action);
                // 2.a action must have an action
                if action.action().is_empty() {
                    log_item!(
                        label.clone(),
                        "action must have an action.",
                        "verify_actions"
                    )
                    .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                    .failure(
                        validation_log,
                        Error::ValidationRule("action must have an action".into()),
                    )?;
                }

                // 2.a any other actions assertions cannot contain created or opened actions (v2 claim)
                if let Some(fa) = first_actions_assertion {
                    if fa != actions_assertion
                        && (action.action() == c2pa_action::OPENED
                            || action.action() == c2pa_action::CREATED)
                    {
                        log_item!(
                            label.clone(),
                            "only first action can be created or opened",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                        .failure(
                            validation_log,
                            Error::ValidationRule(
                                "only first action can be created or opened".into(),
                            ),
                        )?;
                    }
                }

                // 2.a created or opened must be first action
                if index != 0
                    && (action.action() == c2pa_action::OPENED
                        || action.action() == c2pa_action::CREATED)
                {
                    log_item!(
                        label.clone(),
                        "created or opened must be first action",
                        "verify_actions"
                    )
                    .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                    .failure(
                        validation_log,
                        Error::ValidationRule("created or opened must be first action".into()),
                    )?;
                }

                // 2.b rules
                if action.action() == c2pa_action::OPENED
                    || action.action() == c2pa_action::PLACED
                    || action.action() == c2pa_action::REMOVED
                {
                    // 2.b.i must have parameters
                    let Some(params) = action.parameters() else {
                        log_item!(
                            label.clone(),
                            "opened, placed and removed items must have ingredient(s) parameters",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH)
                        .failure(
                            validation_log,
                            Error::ValidationRule(
                                "opened, placed and removed items must have ingredient(s) parameters".into(),
                            ),
                        )?;
                        continue; // Skip the parameter-dependent checks below
                    };

                    // 2.b.ii must have ingredient or ingredients param
                    if params.ingredients.is_none() && params.ingredient.is_none() {
                        log_item!(
                            label.clone(),
                            "opened, placed and removed items must have ingredient(s) parameters",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH)
                        .failure(
                            validation_log,
                            Error::ValidationRule("opened, placed and removed items must have ingredient(s) parameters".into()),
                        )?;
                        continue;
                    }

                    // 2.b.iii if ingredients, must be an array with at least one item
                    if let Some(h_vec) = &params.ingredients {
                        if h_vec.is_empty() {
                            log_item!(
                                label.clone(),
                                "opened, placed and removed items must have ingredients parameter must be non empty array",
                                "verify_actions"
                            )
                            .validation_status(validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH)
                            .failure(
                                validation_log,
                                Error::ValidationRule("opened, placed and removed items must have ingredients parameter must be non empty array".into()),
                            )?;
                        }
                    }

                    // 2.b.iv.A opened must have a parentOf
                    if action.action() == c2pa_action::OPENED {
                        let mut found_good = 0usize;

                        if let Some(h) = &params.ingredient {
                            // can we find a reference in the ingredient list
                            // is it referenced from this manifest
                            if claim.ingredient_assertions().iter().any(|i| {
                                if let Ok(ingredient) = Ingredient::from_assertion(i.assertion()) {
                                    if let Some(target_label) = assertion_label_from_uri(&h.url()) {
                                        return target_label == i.label()
                                            && ingredient.relationship == Relationship::ParentOf;
                                    }
                                }
                                false
                            }) {
                                found_good = 1;
                            }
                        } else if let Some(ingredients) = &params.ingredients {
                            for h in ingredients {
                                // can we find a reference in the ingredient list
                                // is it referenced from this manifest and only once
                                found_good = claim
                                    .ingredient_assertions()
                                    .iter()
                                    .filter(|i| {
                                        if let Ok(ingredient) =
                                            Ingredient::from_assertion(i.assertion())
                                        {
                                            if let Some(target_label) =
                                                assertion_label_from_uri(&h.url())
                                            {
                                                return target_label == i.label()
                                                    && ingredient.relationship
                                                        == Relationship::ParentOf;
                                            }
                                        }
                                        false
                                    })
                                    .count();
                            }
                        }

                        if found_good != 1 {
                            let msg = Self::ingredient_mismatch_msg(
                                claim,
                                action_index,
                                action.action(),
                                params,
                                "parentOf",
                            );
                            log_item!(label.clone(), msg.clone(), "verify_actions")
                                .validation_status(
                                    validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH,
                                )
                                .failure_no_throw(validation_log, Error::ValidationRule(msg));
                        }
                    }

                    // 2.b.iv.B, 2.b.iv.C must have a ComponentOf
                    if action.action() == c2pa_action::PLACED
                        || action.action() == c2pa_action::REMOVED
                    {
                        let mut found_good = 0usize;

                        if let Some(h) = &params.ingredient {
                            // can we find a reference in the ingredient list
                            // is it referenced from this manifest
                            if claim.ingredient_assertions().iter().any(|i| {
                                if let Ok(ingredient) = Ingredient::from_assertion(i.assertion()) {
                                    if let Some(target_label) = assertion_label_from_uri(&h.url()) {
                                        return target_label == i.label()
                                            && ingredient.relationship
                                                == Relationship::ComponentOf;
                                    }
                                }
                                false
                            }) {
                                found_good = 1;
                            }
                        } else if let Some(h_vec) = &params.ingredients {
                            for h in h_vec {
                                // can we find a reference in the ingredient list
                                // is it referenced from this manifest
                                if claim.ingredient_assertions().iter().any(|i| {
                                    if let Ok(ingredient) =
                                        Ingredient::from_assertion(i.assertion())
                                    {
                                        if let Some(target_label) =
                                            assertion_label_from_uri(&h.url())
                                        {
                                            return target_label == i.label()
                                                && ingredient.relationship
                                                    == Relationship::ComponentOf;
                                        }
                                    }
                                    false
                                }) {
                                    found_good = 1;
                                }
                            }
                        }

                        if found_good != 1 {
                            let msg = Self::ingredient_mismatch_msg(
                                claim,
                                action_index,
                                action.action(),
                                params,
                                "componentOf",
                            );
                            log_item!(label.clone(), msg.clone(), "verify_actions")
                                .validation_status(
                                    validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH,
                                )
                                .failure_no_throw(validation_log, Error::ValidationRule(msg));
                        }
                    }
                }

                // 2.b.v c2pa.created must have a digitalSourceType
                if action.action() == c2pa_action::CREATED && action.source_type().is_none() {
                    log_item!(
                        label.clone(),
                        "c2pa.created action must have a digitalSourceType",
                        "verify_actions"
                    )
                    .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                    .failure_no_throw(
                        validation_log,
                        Error::ValidationRule(
                            "c2pa.created action must have a digitalSourceType".into(),
                        ),
                    );
                }

                // c2pa.translated must have sourceLanguage and targetLanguage parameters.
                // Per the C2PA spec (18.15.4.7, Parameters): "When using a c2pa.translated
                // action, the sourceLanguage and targetLanguage fields in the parameters
                // object shall contain RFC 5646, BCP 47 language codes."
                if action.action() == c2pa_action::TRANSLATED {
                    let params = action.parameters();
                    let source_language = params
                        .and_then(|p| p.source_language.as_deref())
                        .unwrap_or("");
                    let target_language = params
                        .and_then(|p| p.target_language.as_deref())
                        .unwrap_or("");

                    if source_language.is_empty() || target_language.is_empty() {
                        log_item!(
                            label.clone(),
                            "c2pa.translated action must have sourceLanguage and targetLanguage parameters",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                        .failure_no_throw(
                            validation_log,
                            Error::ValidationRule(
                                "c2pa.translated action must have sourceLanguage and targetLanguage parameters".into(),
                            ),
                        );
                    }
                }

                // 2.c if ingredient is present it must be a valid parentOf reference
                if action.action() == c2pa_action::TRANSCODED
                    || action.action() == c2pa_action::REPACKAGED
                {
                    if let Some(params) = action.parameters() {
                        let mut parent_tested = None; // on exists if action actually pointed to an ingredient
                        if let Some(h) = &params.ingredient {
                            // can we find a reference in the ingredient list
                            // is it referenced from this manifest
                            if claim.ingredient_assertions().iter().any(|i| {
                                if let Ok(ingredient) = Ingredient::from_assertion(i.assertion()) {
                                    if let Some(target_label) = assertion_label_from_uri(&h.url()) {
                                        return target_label == i.label()
                                            && ingredient.relationship == Relationship::ParentOf;
                                    }
                                }
                                false
                            }) {
                                parent_tested = Some(true);
                            }

                            match parent_tested {
                                Some(v) => parent_tested = Some(v),
                                None => parent_tested = Some(false),
                            }
                        } else if let Some(h_vec) = &params.ingredients {
                            for h in h_vec {
                                // can we find a reference in the ingredient list
                                // is it referenced from this manifest
                                if claim.ingredient_assertions().iter().any(|i| {
                                    if let Ok(ingredient) =
                                        Ingredient::from_assertion(i.assertion())
                                    {
                                        if let Some(target_label) =
                                            assertion_label_from_uri(&h.url())
                                        {
                                            return target_label == i.label()
                                                && ingredient.relationship
                                                    == Relationship::ParentOf;
                                        }
                                    }
                                    false
                                }) {
                                    parent_tested = Some(true);
                                }
                            }
                            match parent_tested {
                                Some(v) => parent_tested = Some(v),
                                None => parent_tested = Some(false),
                            }
                        }
                        // will only exist if we actual tested for an ingredient
                        if let Some(false) = parent_tested {
                            let msg = Self::ingredient_mismatch_msg(
                                claim,
                                action_index,
                                action.action(),
                                params,
                                "parentOf",
                            );
                            log_item!(label.clone(), msg.clone(), "verify_actions")
                                .validation_status(
                                    validation_status::ASSERTION_ACTION_INGREDIENT_MISMATCH,
                                )
                                .failure_no_throw(validation_log, Error::ValidationRule(msg));
                        }
                    }
                }

                // 2.d if redacted actions contains a redacted parameter if must be a resolvable reference
                if action.action() == c2pa_action::REDACTED {
                    if let Some(params) = action.parameters() {
                        let mut parent_tested = None; // on exists if action actually pointed to an ingredient
                        if let Some(redacted_uri) = &params.redacted {
                            if let Some(ingredient_label) = manifest_label_from_uri(redacted_uri) {
                                // can we find a reference in the ingredient list
                                if let Some(ingredient_claim) =
                                    svi.manifest_map.get(&ingredient_label)
                                {
                                    // The referenced manifest exists, so far so good.
                                    // now get the assertion label and try to resolve it.
                                    if let Some(redaction_label) =
                                        assertion_label_from_uri(redacted_uri)
                                    {
                                        // The assertion may or may not be in the assertion store.
                                        // It can exist and be zeroed or be removed entirely
                                        // but it must be in the claim's assertions HashUri list.
                                        // For databox items, check the claim's redacted_assertions
                                        // since databox refs are not in the assertions list.
                                        let in_assertions = ingredient_claim
                                            .assertions()
                                            .iter()
                                            .any(|a| a.url().contains(&redaction_label));
                                        let in_redacted = redacted_uri.contains(DATABOX_STORE)
                                            && claim
                                                .redactions()
                                                .is_some_and(|r| r.contains(redacted_uri));
                                        parent_tested = Some(in_assertions || in_redacted);
                                    } else {
                                        parent_tested = Some(false);
                                    }
                                }
                            }
                        }
                        match parent_tested {
                            None => {
                                log_item!(
                                    label.clone(),
                                    "redaction uri must be a valid reference",
                                    "verify_actions"
                                )
                                .validation_status(
                                    validation_status::ASSERTION_ACTION_REDACTION_MISMATCH,
                                )
                                .failure_no_throw(
                                    validation_log,
                                    Error::ValidationRule(
                                        "redaction action must have valid ingredient".into(),
                                    ),
                                );
                            }
                            Some(false) => {
                                log_item!(
                                    label.clone(),
                                    "The assertion was not redacted",
                                    "verify_actions"
                                )
                                .validation_status(validation_status::ASSERTION_NOT_REDACTED)
                                .failure_no_throw(
                                    validation_log,
                                    Error::ValidationRule("the assertion was not redacted".into()),
                                );
                            }
                            Some(true) => {}
                        }
                    }
                }

                // 2.f if the actionโ€™s parameters field exists and contains a relatedAssertions field
                if let Some(related_assertions) = action.related_assertions() {
                    // 2.f.i if the value of relatedAssertions is not an array with at least one element,
                    //       the claim shall be rejected with a failure code of assertion.action.malformed
                    if related_assertions.is_empty() {
                        log_item!(
                            label.clone(),
                            "relatedAssertions must contain at least one entry",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                        .failure_no_throw(
                            validation_log,
                            Error::ValidationRule(
                                "relatedAssertions must contain at least one entry".into(),
                            ),
                        );
                    }

                    for related in related_assertions {
                        let url = related.url();

                        // 2.f.ii.B resolve the hashed URI to locate the referenced assertion
                        let (target_label, instance) = Claim::assertion_label_from_link(&url);

                        // 2.f.ii.C if the referenced assertion cannot be resolved, or does not
                        //          resolve to an assertion within the current manifest, the claim
                        //          shall be rejected with a failure code of assertion.action.malformed
                        let in_current_manifest = if related.is_relative_url() {
                            true
                        } else {
                            manifest_label_from_uri(&url).as_deref() == Some(claim.label())
                        };
                        let assertion = if in_current_manifest {
                            claim.get_claim_assertion(&target_label, instance)
                        } else {
                            None
                        };

                        if assertion.is_none() {
                            log_item!(
                                url.clone(),
                                format!("relatedAssertions reference could not be resolved within the current manifest: {url}"),
                                "verify_actions"
                            )
                            .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                            .failure_no_throw(
                                validation_log,
                                Error::ValidationRule(
                                format!("relatedAssertions reference could not be resolved within the current manifest: {url}"),
                                ),
                            );
                        }

                        // 2.f.ii.D If the referenced assertion is of of type c2pa.ingredients,
                        //          c2pa.ingredients.v2, c2pa.ingredients.v3, c2pa.actions, or
                        //          c2pa.actions.v2, the claim shall be rejected with a failure
                        //          code of assertion.action.malformed.
                        let base = labels::base(&target_label);
                        if base == labels::ACTIONS || base == labels::INGREDIENT {
                            log_item!(
                                url.clone(),
                                format!("relatedAssertions must not reference an actions or ingredient assertion: {url}"),
                                "verify_actions"
                            )
                            .validation_status(validation_status::ASSERTION_ACTION_MALFORMED)
                            .failure_no_throw(
                                validation_log,
                                Error::ValidationRule(
                                format!("relatedAssertions must not reference an actions or ingredient assertion: {url}"),
                                ),
                            );
                        }
                    }
                }

                // 2.h check softwareAgent icons
                let mut icons = Vec::new();
                if let Some(assertions::SoftwareAgent::ClaimGeneratorInfo(cgi)) =
                    action.software_agent()
                {
                    if let Some(icon) = cgi.icon() {
                        icons.push(icon);
                    }
                }
                if !icons.is_empty() {
                    Claim::verify_icons(claim, &label, &icons, validation_log)?;
                }

                // check watermarks for required softbinding
                // `c2pa_action::WATERMARKED` is deprecated for producing new content (spec 2.2+),
                // but validators must still recognize it in older manifests.
                #[allow(deprecated)]
                if action.action() == c2pa_action::WATERMARKED
                    || action.action() == c2pa_action::WATERMARKED_BOUND
                {
                    // there must be at least one soft binding assertions, in the future there may be
                    // a requirement to reference the actual soft binding via parameters relatedAssertions field
                    if claim.soft_binding_assertions().is_empty() {
                        log_item!(
                            label.clone(),
                            "watermark action missing soft binding assertion",
                            "verify_actions"
                        )
                        .validation_status(validation_status::ACTION_ASSERTION_SOFTBINDING_MISSING)
                        .failure_no_throw(
                            validation_log,
                            Error::ValidationRule(
                                "watermark action missing soft binding assertion".into(),
                            ),
                        );
                    }
                }
            }
        }

        Ok(())
    }

    /// Checks that each icon is a hashed URI that resolves within `claim`.
    ///
    /// `source_uri` is the JUMBF URI of the claim or assertion containing the icons, used to
    /// locate failures for icons that have no hashed URI of their own.
    fn verify_icons(
        claim: &Claim,
        source_uri: &str,
        icon_uris: &[&UriOrResource],
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        for icon in icon_uris {
            let icon = match icon {
                UriOrResource::HashedUri(icon) => icon,
                UriOrResource::ResourceRef(resource) => {
                    let msg = format!(
                        "icon must contain a hashed URI, found resource reference: {}",
                        resource.identifier
                    );
                    log_item!(source_uri.to_owned(), msg.clone(), "verify_icons")
                        .validation_status(validation_status::HASHED_URI_MISSING)
                        .failure(validation_log, Error::ValidationRule(msg))?;
                    continue;
                }
            };
            // make sure the icon uri is valid
            let (label, instance) = Claim::assertion_label_from_link(&icon.url());
            if let Some(ca) = claim.get_claim_assertion(&label, instance) {
                // verify the hashes match
                if !vec_compare(ca.hash(), &icon.hash()) {
                    log_item!(
                        icon.url(),
                        format!("hash does not match assertion data: {}", icon.url()),
                        "verify_icons"
                    )
                    .validation_status(validation_status::ASSERTION_HASHEDURI_MISMATCH)
                    .failure(
                        validation_log,
                        Error::HashMismatch(format!("Assertion hash failure: {}", icon.url(),)),
                    )?;
                }
            } else if claim.get_databox(icon).is_some() {
                // We have a databox with this icon
                // todo: check the hash on the databox?
                continue;
            } else {
                log_item!(icon.url(), "could not resolve icon address", "verify_icons")
                    .validation_status(validation_status::ASSERTION_MISSING)
                    .failure(validation_log, Error::AssertionMissing { url: icon.url() })?;
            }
        }
        Ok(())
    }

    /// Classifies a hash-verification failure into its format's `malformed`
    /// or `mismatch` validation-status constant, based on whether `e` carries
    /// that format's own `malformed` code.
    fn classify_hash_verification_error(
        e: &Error,
        malformed: &'static str,
        unknown_box: Option<&'static str>,
        mismatch: &'static str,
    ) -> &'static str {
        match e {
            Error::C2PAValidation(es) if es == malformed => malformed,
            // The box-hash verifier signals a box present in the asset but
            // absent from the list by returning this sentinel string (spec
            // ยง14.12.3's `unknownBox`, distinct from a plain hash mismatch).
            Error::HashMismatch(es) => match unknown_box {
                Some(ub) if es == ub => ub,
                _ => mismatch,
            },
            _ => mismatch,
        }
    }

    pub(crate) fn verify_hash_binding(
        claim: &Claim,
        asset_data: &mut ClaimAssetData<'_>,
        svi: &StoreValidationInfo,
        validation_log: &mut StatusTracker,
        context: &Context,
    ) -> Result<()> {
        const UNNAMED: &str = "unnamed";
        let default_str = |s: &String| s.clone();

        // verify data hashes for provenance claims
        if claim.label() == svi.binding_claim {
            let hash_assertions = claim.hash_assertions();
            // must have at least one hard binding for normal manifests
            if hash_assertions.is_empty() && !claim.update_manifest() {
                log_item!(claim.uri(), "claim missing data binding", "verify_internal")
                    .validation_status(validation_status::HARD_BINDINGS_MISSING)
                    .failure(validation_log, Error::ClaimMissingHardBinding)?;
            }

            // must have exactly one hard binding for normal manifests
            if hash_assertions.len() != 1 && !claim.update_manifest() {
                log_item!(
                    claim.uri(),
                    "claim has multiple data bindings",
                    "verify_internal"
                )
                .validation_status(validation_status::HARD_BINDINGS_MULTIPLE)
                .failure(validation_log, Error::ClaimMultipleHardBinding)?;
            }

            // update manifests cannot have data hashes
            if !hash_assertions.is_empty() && claim.update_manifest() {
                log_item!(
                    claim.uri(),
                    "update manifests cannot contain data hash assertions",
                    "verify_internal"
                )
                .validation_status(validation_status::MANIFEST_UPDATE_INVALID)
                .failure(validation_log, Error::UpdateManifestInvalid)?;
            }

            // while this is a vec the spec only expects one at the moment and is checked above
            for hash_binding_assertion in hash_assertions {
                if hash_binding_assertion
                    .label_raw()
                    .starts_with(DataHash::LABEL)
                {
                    let mut dh = DataHash::from_assertion(hash_binding_assertion.assertion())?;
                    let name = dh.name.as_ref().map_or(UNNAMED.to_string(), default_str);

                    // update with any needed update hash adjustments
                    if svi.update_manifest_label.is_some() {
                        let mut start_adjust = 0;
                        let mut start_offset = 0;
                        if let Some(exclusions) = &mut dh.exclusions {
                            if let Some(range) = &svi.manifest_store_range {
                                // find the range that starts at the same position as the manifest store range
                                if let Some(pos) =
                                    exclusions.iter().position(|r| r.start() == range.start())
                                {
                                    // find the adjustment length
                                    start_offset = range.start();
                                    start_adjust =
                                        range.length().saturating_sub(exclusions[pos].length());

                                    // replace range using the size that covers entire manifest (including update manifests)
                                    exclusions[pos] = range.clone();
                                }
                            }
                            // fix up offsets affected by update manifest
                            if start_offset > 0 {
                                for exclusion in exclusions {
                                    if exclusion.start() > start_offset {
                                        exclusion.set_start(exclusion.start() + start_adjust);
                                    }
                                }
                            }
                        }
                    }

                    if !dh.is_remote_hash() {
                        if let Some(exclusions) = &dh.exclusions {
                            if !data_hash_exclusions_match_manifest(
                                exclusions,
                                svi.manifest_store_range.as_ref(),
                                svi.is_embedded,
                            ) {
                                log_item!(
                                    claim.assertion_uri(&hash_binding_assertion.label()),
                                    "data hash exclusion does not match the manifest location in the asset",
                                    "verify_internal"
                                )
                                .validation_status(validation_status::ASSERTION_DATAHASH_MISMATCH)
                                .failure(
                                    validation_log,
                                    Error::HashMismatch(
                                        "data hash exclusion does not match manifest location"
                                            .to_string(),
                                    ),
                                )?;
                            }

                            // there are extra exclusion then log the information code about extra exclusion
                            if exclusions.len() > 1 {
                                log_item!(
                                    claim.assertion_uri(&hash_binding_assertion.label()),
                                    "extra data hash exclusions found",
                                    "verify_internal"
                                )
                                .validation_status(
                                    validation_status::ASSERTION_DATAHASH_ADDITIONAL_EXCLUSIONS,
                                )
                                .informational(validation_log);
                            }
                        }

                        // only verify local hashes here
                        let mut cb = |step, total| {
                            context.check_progress(ProgressPhase::VerifyingAssetHash, step, total)
                        };
                        let hash_result = match asset_data {
                            #[cfg(feature = "file_io")]
                            ClaimAssetData::Path(asset_path) => {
                                let mut file = std::fs::File::open(asset_path)?;
                                dh.verify_stream_hash_with_progress(
                                    &mut file,
                                    Some(claim.alg()),
                                    &mut cb,
                                )
                            }
                            ClaimAssetData::Bytes(asset_bytes, _) => {
                                let mut cursor = std::io::Cursor::new(*asset_bytes);
                                dh.verify_stream_hash_with_progress(
                                    &mut cursor,
                                    Some(claim.alg()),
                                    &mut cb,
                                )
                            }
                            ClaimAssetData::Stream(stream_data, _) => dh
                                .verify_stream_hash_with_progress(
                                    *stream_data,
                                    Some(claim.alg()),
                                    &mut cb,
                                ),
                            _ => return Err(Error::UnsupportedType), /* this should never happen (coding error) */
                        };

                        match hash_result {
                            Ok(_a) => {
                                log_item!(
                                    claim.assertion_uri(&hash_binding_assertion.label()),
                                    "data hash valid",
                                    "verify_internal"
                                )
                                .validation_status(validation_status::ASSERTION_DATAHASH_MATCH)
                                .success(validation_log);

                                continue;
                            }
                            Err(e) => {
                                log_item!(
                                    claim.assertion_uri(&hash_binding_assertion.label()),
                                    format!("asset hash error, name: {name}, error: {e}"),
                                    "verify_internal"
                                )
                                .validation_status(validation_status::ASSERTION_DATAHASH_MISMATCH)
                                .failure(
                                    validation_log,
                                    Error::HashMismatch(format!("Asset hash failure: {e}")),
                                )?;
                            }
                        }
                    } else {
                        log_item!(
                            hash_binding_assertion.label(),
                            "remote data hash URIs are not supported",
                            "verify_internal"
                        )
                        .validation_status(validation_status::ASSERTION_DATAHASH_MISMATCH)
                        .failure(
                            validation_log,
                            Error::HashMismatch(
                                "remote data hash URIs are not supported".to_string(),
                            ),
                        )?;
                    }
                } else if hash_binding_assertion
                    .label_raw()
                    .starts_with(BmffHash::LABEL)
                {
                    let cp2a_id: [u8; 16] = [
                        216, 254, 195, 214, 27, 14, 72, 60, 146, 151, 88, 40, 135, 126, 196, 129,
                    ];
                    let c2pa_dm = DataMap {
                        offset: 8,
                        value: cp2a_id.to_vec(), // C2PA identifier
                    };

                    // handle BMFF data hashes
                    let dh = BmffHash::from_assertion(hash_binding_assertion.assertion())?;

                    let name = dh.name().map_or("unnamed".to_string(), default_str);

                    // are there addtional exclusions that are not manifests or ftyp
                    if dh.exclusions().iter().any(|e| {
                        if e.xpath == "/uuid" {
                            match &e.data {
                                Some(dm_vec) if dm_vec.len() == 1 => !(dm_vec[0] == c2pa_dm),
                                _ => true,
                            }
                        } else if e.xpath == "/ftyp" || e.xpath == "/mfra" {
                            false
                        } else {
                            true // not ftyp, mfra or uuid
                        }
                    }) {
                        log_item!(
                            claim.assertion_uri(&hash_binding_assertion.label()),
                            "extra BMFF hash exclusion(s) found",
                            "verify_internal"
                        )
                        .validation_status(
                            validation_status::ASSERTION_BMFFHASH_ADDITIONAL_EXCLUSIONS,
                        )
                        .informational(validation_log);
                    }

                    let mut step = 0u32;
                    let mut cb = |_s: u32, t: u32| {
                        step += 1;
                        context.check_progress(ProgressPhase::VerifyingAssetHash, step, t)
                    };
                    let hash_result = match asset_data {
                        #[cfg(feature = "file_io")]
                        ClaimAssetData::Path(asset_path) => {
                            dh.verify_hash_with_progress(asset_path, Some(claim.alg()), &mut cb)
                        }
                        ClaimAssetData::Bytes(asset_bytes, _) => dh
                            .verify_in_memory_hash_with_progress(
                                asset_bytes,
                                Some(claim.alg()),
                                &mut cb,
                            ),
                        ClaimAssetData::Stream(stream_data, _) => dh
                            .verify_stream_hash_with_progress(
                                *stream_data,
                                Some(claim.alg()),
                                &mut cb,
                            ),
                        ClaimAssetData::StreamFragment(initseg_data, fragment_data, _) => dh
                            .verify_stream_segment_with_progress(
                                *initseg_data,
                                *fragment_data,
                                Some(claim.alg()),
                                &mut cb,
                            ),
                        #[cfg(feature = "file_io")]
                        ClaimAssetData::StreamFragments(initseg_data, fragment_paths, _) => dh
                            .verify_stream_segments_with_progress(
                                *initseg_data,
                                fragment_paths,
                                Some(claim.alg()),
                                &mut cb,
                            ),
                    };

                    match hash_result {
                        Ok(_a) => {
                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                "BMFF hash valid",
                                "verify_internal"
                            )
                            .validation_status(validation_status::ASSERTION_BMFFHASH_MATCH)
                            .success(validation_log);

                            continue;
                        }
                        Err(e) => {
                            let err_str = Self::classify_hash_verification_error(
                                &e,
                                validation_status::ASSERTION_BMFFHASH_MALFORMED,
                                None,
                                validation_status::ASSERTION_BMFFHASH_MISMATCH,
                            );

                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                format!("asset hash error, name: {name}, error: {e}"),
                                "verify_internal"
                            )
                            .validation_status(err_str)
                            .failure(
                                validation_log,
                                Error::HashMismatch(format!("Asset hash failure: {e}")),
                            )?;
                        }
                    }
                } else if hash_binding_assertion
                    .label_raw()
                    .starts_with(BoxHash::LABEL)
                {
                    // box hash case
                    // handle BMFF data hashes
                    let bh = BoxHash::from_assertion(hash_binding_assertion.assertion())?;

                    let mut cb = |step, total| {
                        context.check_progress(ProgressPhase::VerifyingAssetHash, step, total)
                    };
                    let hash_result = match asset_data {
                        #[cfg(feature = "file_io")]
                        ClaimAssetData::Path(asset_path) => {
                            let box_hash_processor = context
                                .io()
                                .handler_from_path(asset_path)
                                .ok_or(Error::UnsupportedType)?
                                .asset_box_hash_ref()
                                .ok_or(Error::HashMismatch("Box hash not supported".to_string()))?;

                            let mut file = std::fs::File::open(asset_path)?;
                            bh.verify_stream_hash_with_progress(
                                &mut file,
                                Some(claim.alg()),
                                box_hash_processor,
                                &mut cb,
                            )
                        }
                        ClaimAssetData::Bytes(asset_bytes, asset_type) => {
                            let box_hash_processor = context
                                .io()
                                .handler(asset_type)
                                .ok_or(Error::UnsupportedType)?
                                .asset_box_hash_ref()
                                .ok_or(Error::HashMismatch(format!(
                                    "Box hash not supported for: {asset_type}"
                                )))?;

                            let mut cursor = std::io::Cursor::new(*asset_bytes);
                            bh.verify_stream_hash_with_progress(
                                &mut cursor,
                                Some(claim.alg()),
                                box_hash_processor,
                                &mut cb,
                            )
                        }
                        ClaimAssetData::Stream(stream_data, asset_type) => {
                            let box_hash_processor = context
                                .io()
                                .handler(asset_type)
                                .ok_or(Error::UnsupportedType)?
                                .asset_box_hash_ref()
                                .ok_or(Error::HashMismatch(format!(
                                    "Box hash not supported for: {asset_type}"
                                )))?;

                            bh.verify_stream_hash_with_progress(
                                *stream_data,
                                Some(claim.alg()),
                                box_hash_processor,
                                &mut cb,
                            )
                        }
                        _ => return Err(Error::UnsupportedType),
                    };

                    match hash_result {
                        Ok(metadata_exclusion_used) => {
                            if metadata_exclusion_used {
                                log_item!(
                                    claim.assertion_uri(&hash_binding_assertion.label()),
                                    "additional box hash exclusions found",
                                    "verify_internal"
                                )
                                .validation_status(
                                    validation_status::ASSERTION_BOXHASH_ADDITIONAL_EXCLUSIONS,
                                )
                                .informational(validation_log);
                            }

                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                "boxes hash valid",
                                "verify_internal"
                            )
                            .validation_status(validation_status::ASSERTION_BOXHASH_MATCH)
                            .success(validation_log);

                            continue;
                        }
                        Err(e) => {
                            let err_str = Self::classify_hash_verification_error(
                                &e,
                                validation_status::ASSERTION_BOXESHASH_MALFORMED,
                                Some(validation_status::ASSERTION_BOXHASH_UNKNOWN_BOX),
                                validation_status::ASSERTION_BOXHASH_MISMATCH,
                            );

                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                format!("asset hash error: {e}"),
                                "verify_internal"
                            )
                            .validation_status(err_str)
                            .failure(
                                validation_log,
                                Error::HashMismatch(format!("Asset hash failure: {e}")),
                            )?;
                        }
                    }
                } else if hash_binding_assertion
                    .label_raw()
                    .starts_with(CollectionHash::LABEL)
                {
                    let collection_hash =
                        CollectionHash::from_assertion(hash_binding_assertion.assertion())?;

                    let verify_result = if asset_data
                        .format()
                        .as_deref()
                        .is_some_and(|f| context.io().is_zip_format(f))
                    {
                        match asset_data {
                            #[cfg(feature = "file_io")]
                            ClaimAssetData::Path(asset_path) => {
                                let mut file = std::fs::File::open(asset_path)?;
                                collection_hash.verify_zip_stream_hash(&mut file, Some(claim.alg()))
                            }
                            ClaimAssetData::Bytes(asset_bytes, _) => {
                                let mut cursor = std::io::Cursor::new(*asset_bytes);
                                collection_hash
                                    .verify_zip_stream_hash(&mut cursor, Some(claim.alg()))
                            }
                            ClaimAssetData::Stream(stream_data, _) => collection_hash
                                .verify_zip_stream_hash(*stream_data, Some(claim.alg())),
                            _ => return Err(Error::UnsupportedType),
                        }
                    } else {
                        // we don't support multiple streams as input so the only option is paths for non-ZIP-based assets.
                        match asset_data {
                            #[cfg(feature = "file_io")]
                            ClaimAssetData::Path(asset_path) => collection_hash
                                .verify_hash(asset_path.parent().unwrap_or(asset_path)),
                            _ => return Err(Error::UnsupportedType),
                        }
                    };

                    match verify_result {
                        Ok(_) => {
                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                "collection hash valid",
                                "verify_internal"
                            )
                            .validation_status(validation_status::ASSERTION_COLLECTIONHASH_MATCH)
                            .success(validation_log);

                            continue;
                        }
                        Err(err) => {
                            let err_str = match &err {
                                Error::C2PAValidation(code)
                                    if code
                                        == validation_status::ASSERTION_COLLECTIONHASH_MALFORMED =>
                                {
                                    validation_status::ASSERTION_COLLECTIONHASH_MALFORMED
                                }
                                Error::C2PAValidation(code)
                                    if code
                                        == validation_status::ASSERTION_COLLECTIONHASH_INVALID_URI =>
                                {
                                    validation_status::ASSERTION_COLLECTIONHASH_INVALID_URI
                                }
                                Error::C2PAValidation(code)
                                    if code
                                        == validation_status::ASSERTION_COLLECTIONHASH_INCORRECT_FILE_COUNT =>
                                {
                                    validation_status::ASSERTION_COLLECTIONHASH_INCORRECT_FILE_COUNT
                                }
                                _ => validation_status::ASSERTION_COLLECTIONHASH_MISMATCH,
                            };

                            log_item!(
                                claim.assertion_uri(&hash_binding_assertion.label()),
                                format!("collection hash error: {err_str}"),
                                "verify_internal"
                            )
                            .validation_status(err_str)
                            .failure(
                                validation_log,
                                Error::HashMismatch(format!("asset hash failure: {err}")),
                            )?;
                        }
                    }
                } else {
                    log_item!(
                        claim.assertion_uri(&hash_binding_assertion.label()),
                        "hash binding unknown or not found",
                        "verify_internal"
                    )
                    .validation_status(validation_status::HARD_BINDINGS_MISSING)
                    .failure(
                        validation_log,
                        Error::HashMismatch("hash binding unknown format".into()),
                    )?;
                }
            }
        }

        Ok(())
    }

    pub(super) fn verify_internal(
        claim: &Claim,
        svi: &StoreValidationInfo,
        verified: Result<CertificateInfo>,
        validation_log: &mut StatusTracker,
        context: &Context,
    ) -> Result<()> {
        // Statuses for this claim's signature are logged under its signature URI.
        let signature_uri = to_signature_uri(claim.label());
        let signature_has_status = |codes: &[&str]| {
            validation_log.logged_items().iter().any(|item| {
                item.label == signature_uri
                    && item
                        .validation_status
                        .as_deref()
                        .is_some_and(|code| codes.contains(&code))
            })
        };

        // C2PA only validates the claim signature, and issues
        // claimSignature.validated, "if the claim has not yet been rejected" by
        // the checks on its signing credential. An untrusted credential does not
        // count here; see SIGNING_CREDENTIAL_REJECTIONS.
        let credential_rejected = signature_has_status(SIGNING_CREDENTIAL_REJECTIONS);

        // claimSignature.insideValidity means the signer's certificate and all CA
        // certificates up to the trust anchor were valid at the validation time,
        // so it cannot be reported alongside claimSignature.outsideValidity, or
        // alongside signingCredential.expired, which the certificate profile check
        // has also used for an expired signer.
        let outside_validity = signature_has_status(&[
            validation_status::CLAIM_SIGNATURE_OUTSIDE_VALIDITY,
            validation_status::SIGNING_CREDENTIAL_EXPIRED,
        ]);

        // signature check
        match verified {
            Ok(vi) => {
                if !vi.validated {
                    log_item!(
                        to_signature_uri(claim.label()),
                        "claim signature is not valid",
                        "verify_internal"
                    )
                    .validation_status(validation_status::CLAIM_SIGNATURE_MISMATCH)
                    .failure(validation_log, Error::CoseSignature)?;
                } else {
                    if !outside_validity {
                        log_item!(
                            to_signature_uri(claim.label()),
                            "claim signature valid",
                            "verify_internal"
                        )
                        .validation_status(validation_status::CLAIM_SIGNATURE_INSIDE_VALIDITY)
                        .success(validation_log);
                    }

                    // add signature validated status
                    if !credential_rejected {
                        log_item!(
                            to_signature_uri(claim.label()),
                            "claim signature valid",
                            "verify_internal"
                        )
                        .validation_status(validation_status::CLAIM_SIGNATURE_VALIDATED)
                        .success(validation_log);
                    }
                }
            }
            Err(parse_err) => {
                // handle case where lower level failed to log
                log_item!(
                    to_signature_uri(claim.label()),
                    "claim signature is not valid",
                    "verify_internal"
                )
                .validation_status(validation_status::CLAIM_SIGNATURE_MISMATCH)
                .failure_no_throw(validation_log, parse_err);
            }
        };

        // if claim make sure we have a valid claim_generator_info
        // note that for 2.x claims this is a mandatory fields its presence
        // is checked during Claim cbor deserialization
        if let Some(cgi_vec) = claim.claim_generator_info() {
            let mut icons = Vec::new();
            for cgi in cgi_vec {
                if let Some(icon) = cgi.icon() {
                    icons.push(icon);
                }
            }
            if !icons.is_empty() {
                Claim::verify_icons(claim, &claim.to_claim_uri(), &icons, validation_log)?;
            }
        }

        // check for self redacted assertions and illegal redactions
        if let Some(redactions) = claim.redactions() {
            for r in redactions {
                if r.contains(claim.label()) {
                    log_item!(
                        r.to_owned(),
                        "claim contains self redaction",
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_SELF_REDACTED)
                    .failure(validation_log, Error::ClaimSelfRedact)?;
                }

                if r.contains(labels::ACTIONS) {
                    log_item!(
                        r.to_owned(),
                        "redaction of action assertions disallowed",
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_ACTION_REDACTED)
                    .failure(validation_log, Error::ClaimDisallowedRedaction)?;
                }

                // check for disallowed hash redactions
                if labels::HASH_LABELS.iter().any(|label| r.contains(label)) {
                    log_item!(
                        r.to_owned(),
                        "redaction of disallowed hash assertion",
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_HARDBINDING_REDACTED)
                    .failure(validation_log, Error::ClaimDisallowedRedaction)?;
                }
            }
        }

        // get the parent count
        let parent_count = claim
            .ingredient_assertions()
            .iter()
            .filter(|a| {
                if let Ok(ingredient) = Ingredient::from_assertion(a.assertion()) {
                    let version = ingredient.version().unwrap_or(1);
                    let has_valid_parent = version <= 2 && ingredient.c2pa_manifest().is_some()
                        || ingredient.c2pa_manifest().is_some() && ingredient.signature().is_some();

                    return has_valid_parent && ingredient.relationship == Relationship::ParentOf;
                }
                false
            })
            .count();

        // check update manifest rules
        if claim.update_manifest() {
            // must be one of the allowed actions
            for aa in claim.action_assertions() {
                let actions = Actions::from_assertion(aa.assertion())?;
                for action in actions.actions() {
                    if !ALLOWED_UPDATE_MANIFEST_ACTIONS
                        .iter()
                        .any(|a| *a == action.action())
                    {
                        log_item!(
                            claim.uri(),
                            "update manifests contains disallowed actions assertion",
                            "verify_internal"
                        )
                        .validation_status(validation_status::MANIFEST_UPDATE_INVALID)
                        .failure(validation_log, Error::UpdateManifestInvalid)?;
                    }
                }
            }

            // make sure there are no thumbnail assertions
            if claim
                .claim_assertion_store()
                .iter()
                .any(|ca| ca.label_raw().contains(CLAIM_THUMBNAIL))
            {
                log_item!(
                    claim.uri(),
                    "update manifests cannot contain thumbnail assertions",
                    "verify_internal"
                )
                .validation_status(validation_status::MANIFEST_UPDATE_INVALID)
                .failure(validation_log, Error::UpdateManifestInvalid)?;
            }

            // make sure one ingredient parent
            match parent_count {
                0 => {
                    log_item!(
                        claim.uri(),
                        "update manifest must have ingredient with parentOf relationship",
                        "verify_internal"
                    )
                    .validation_status(validation_status::MANIFEST_UPDATE_WRONG_PARENTS)
                    .failure(validation_log, Error::UpdateManifestInvalid)?;
                }
                1 => (),
                _ => {
                    log_item!(
                        claim.uri(),
                        "update manifests can have one 1 ingredient ",
                        "verify_internal"
                    )
                    .validation_status(validation_status::MANIFEST_UPDATE_INVALID)
                    .failure(validation_log, Error::UpdateManifestInvalid)?;
                }
            }
        } else {
            // can only have zero or one parentOf
            if parent_count > 1 {
                log_item!(
                    claim.uri(),
                    "too many ingredient parents",
                    "ingredient_checks"
                )
                .validation_status(validation_status::MANIFEST_MULTIPLE_PARENTS)
                .failure(
                    validation_log,
                    Error::ClaimVerification("ingredient has more than one parent".to_string()),
                )?;
            }
        }

        // track list to make sure there are no extra assertions found in assertion store
        let mut ca_tracking_list = claim.claim_assertion_store().clone();

        // verify assertion structure comparing hashes from assertion list to contents of assertion store
        for assertion in claim.assertions() {
            let (label, instance) = Claim::assertion_label_from_link(&assertion.url());
            let assertion_absolute_uri = if assertion.is_relative_url() {
                to_absolute_uri(claim.label(), &assertion.url())
            } else {
                // make sure the assertion points to this assertion store
                let Some(assertion_manifest) = manifest_label_from_uri(&assertion.url()) else {
                    log_item!(
                        assertion.url(),
                        format!("assertion URI malformed: {}", assertion.url()),
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_HASHEDURI_MISMATCH)
                    .failure_no_throw(
                        validation_log,
                        Error::AssertionMissing {
                            url: assertion.url(),
                        },
                    );
                    continue;
                };

                if assertion_manifest != claim.label() {
                    log_item!(
                        assertion.url(),
                        format!(
                            "assertion reference to external assertion store: {}",
                            assertion.url()
                        ),
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_OUTSIDE_MANIFEST)
                    .failure(
                        validation_log,
                        Error::AssertionMissing {
                            url: assertion.url(),
                        },
                    )?;
                };

                assertion.url()
            };

            // remove from tracking list
            if let Some(index) = ca_tracking_list
                .iter()
                .position(|v| v.label_raw().as_str() == label && v.instance() == instance)
            {
                ca_tracking_list.swap_remove(index);
            }

            // we can skip if this is a redacted assertion
            if svi.redactions.iter().any(|r| {
                let r_manifest = manifest_label_from_uri(r).unwrap_or_default();
                if r_manifest == claim.label() {
                    let (r_label, r_instance) = Claim::assertion_label_from_link(r);
                    r_label == label && r_instance == instance
                } else {
                    false
                }
            }) {
                continue;
            }

            // make sure assertion data has not changed
            match claim.get_claim_assertion(&label, instance) {
                // get the assertion if label and hash match
                Some(ca) => {
                    // if not a redaction then we must check the hash
                    if !vec_compare(ca.hash(), &assertion.hash()) {
                        log_item!(
                            assertion_absolute_uri.clone(),
                            format!("hash does not match assertion data: {}", assertion.url()),
                            "verify_internal"
                        )
                        .validation_status(validation_status::ASSERTION_HASHEDURI_MISMATCH)
                        .failure(
                            validation_log,
                            Error::HashMismatch(format!(
                                "Assertion hash failure: {}",
                                assertion_absolute_uri.clone(),
                            )),
                        )?;
                    } else {
                        log_item!(
                            assertion_absolute_uri,
                            format!("hashed uri matched: {}", assertion.url()),
                            "verify_internal"
                        )
                        .validation_status(validation_status::ASSERTION_HASHEDURI_MATCH)
                        .success(validation_log);
                    }
                }
                None => {
                    log_item!(
                        assertion_absolute_uri.clone(),
                        format!("cannot find matching assertion: {}", assertion.url()),
                        "verify_internal"
                    )
                    .validation_status(validation_status::ASSERTION_MISSING)
                    .failure_no_throw(
                        validation_log,
                        Error::AssertionMissing {
                            url: assertion_absolute_uri.clone(),
                        },
                    );
                }
            }
        }

        // we should have accounted for all assertions in the store
        if !ca_tracking_list.is_empty() {
            // log all unaccessed assertions and return err
            for undeclared in &ca_tracking_list {
                log_item!(
                    undeclared.label().clone(),
                    "assertion is not referenced by the claim",
                    "verify_internal"
                )
                .validation_status(validation_status::ASSERTION_UNDECLARED)
                .failure_no_throw(
                    validation_log,
                    Error::AssertionMissing {
                        url: undeclared.label(),
                    },
                );
            }
            return Err(Error::AssertionMissing {
                url: ca_tracking_list[0].label(),
            });
        }

        // check action rules
        Claim::verify_actions(claim, svi, validation_log, context.settings())?;

        // check metadata rules
        if claim.version() >= 2 {
            // only for claim version 2 or greater
            Claim::verify_metadata(claim, validation_log)?;
            Claim::verify_claim_generator_info(claim, validation_log)?;
        }

        // soft binding algorithm validation applies to all claim versions
        Claim::verify_soft_binding_alg(
            claim,
            context
                .settings()
                .soft_binding
                .soft_binding_algorithms
                .as_deref()
                .unwrap_or(&[]),
            validation_log,
        )?;

        // cloud-data assertion validation applies to all claim versions
        Claim::verify_cloud_data(claim, validation_log)?;

        // external-reference assertion validation applies to all claim versions
        Claim::verify_external_reference(claim, validation_log)?;

        Ok(())
    }

    // Validate claim_generator_info for v2+ claims per ยง10.2.2.
    // Must be present, non-empty, and have a non-empty name field.
    pub(super) fn verify_claim_generator_info(
        claim: &Claim,
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        match claim.claim_generator_info() {
            None | Some([]) => {
                log_item!(
                    claim.uri(),
                    "claim_generator_info is required for v2+ claims",
                    "verify_claim_generator_info"
                )
                .validation_status(validation_status::CLAIM_MALFORMED)
                .failure(
                    validation_log,
                    Error::ClaimDecoding("claim_generator_info is missing".to_string()),
                )?;
            }
            Some(cgi) => {
                if cgi[0].name.is_empty() {
                    log_item!(
                        claim.uri(),
                        "claim_generator_info name must not be empty",
                        "verify_claim_generator_info"
                    )
                    .validation_status(validation_status::CLAIM_MALFORMED)
                    .failure(
                        validation_log,
                        Error::ClaimDecoding("claim_generator_info name is empty".to_string()),
                    )?;
                }
            }
        }
        Ok(())
    }

    /// Validate that each soft binding assertion's effective algorithm is in the
    /// C2PA soft binding algorithm registry (ยง9.3.2).
    ///
    /// The effective algorithm is the assertion-level `alg` field when present,
    /// falling back to the claim-level `alg_soft` field. If neither is present
    /// the assertion is malformed.
    /// Starting with C2PA 2.4 we no longer require soft binding alg to be on the
    /// official list.  This allows for future algorithm support without code changes.
    /// The function now will only check the structure of the assertion.
    pub(super) fn verify_soft_binding_alg(
        claim: &Claim,
        _soft_binding_algs: &[String],
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        use assertions::SoftBinding;

        for ca in claim.soft_binding_assertions() {
            let label = to_assertion_uri(claim.label(), &ca.label());

            let _soft_binding = match SoftBinding::from_assertion(ca.assertion()) {
                Ok(soft_binding) => soft_binding,
                Err(_) => {
                    log_item!(
                        label.clone(),
                        "soft binding assertion could not be decoded",
                        "verify_soft_binding_alg"
                    )
                    .validation_status(validation_status::CLAIM_MALFORMED)
                    .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));

                    // Malformed, but don't abort the whole verification over one
                    // bad soft binding assertion -- move on to the next one.
                    continue;
                }
            };

            /*
            // Effective alg: assertion field takes precedence over claim-level alg_soft.
            let effective_alg = soft_binding
                .alg
                .as_deref()
                .or_else(|| claim.alg_soft().map(String::as_str));

            match effective_alg {
                None => {
                    log_item!(
                        label.clone(),
                        "soft binding assertion has no algorithm (alg or alg_soft required)",
                        "verify_soft_binding_alg"
                    )
                    .validation_status(validation_status::CLAIM_MALFORMED)
                    .failure(
                        validation_log,
                        Error::ValidationRule("soft binding missing algorithm".into()),
                    )?;
                }
                Some(alg) if !soft_binding_algs.iter().any(|a| a == alg) => {
                    log_item!(
                        label.clone(),
                        format!("soft binding algorithm '{alg}' is not in the C2PA soft binding algorithm registry"),
                        "verify_soft_binding_alg"
                    )
                    .validation_status(validation_status::ALGORITHM_UNSUPPORTED)
                    .failure(
                        validation_log,
                        Error::ValidationRule(format!(
                            "unsupported soft binding algorithm: {alg}"
                        )),
                    )?;
                }
                Some(_) => {}
            }
            */
        }
        Ok(())
    }

    /// Validate each `c2pa.cloud-data` assertion per ยง15.10.3.2.1.
    ///
    /// Checks:
    /// 1. Required fields (`assertion`/label, `size`, `url`/location, `format`/content_type)
    ///    are present โ€” failure code `assertion.cloud-data.malformed`.
    /// 2. The referenced assertion must not be a hard binding type โ€” failure code
    ///    `assertion.cloud-data.hardBinding`.
    /// 3. In an update manifest the referenced assertion must not be an actions
    ///    assertion โ€” failure code `assertion.cloud-data.actions`.
    ///
    /// No fetching of the cloud data is performed, only the structure of the assertion is checked.
    pub(super) fn verify_cloud_data(
        claim: &Claim,
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        use assertions::CloudData;

        for ca in claim.cloud_data_assertions() {
            let label = to_assertion_uri(claim.label(), &ca.label());

            let cloud_data = match CloudData::from_assertion(ca.assertion()) {
                Ok(cloud_data) => cloud_data,
                Err(_) => {
                    log_item!(
                        label.clone(),
                        "cloud-data assertion could not be decoded",
                        "verify_cloud_data"
                    )
                    .validation_status(validation_status::ASSERTION_CLOUD_DATA_MALFORMED)
                    .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));

                    // Malformed, but don't abort the whole verification over one
                    // bad cloud-data assertion -- move on to the next one.
                    continue;
                }
            };

            // Step 1: size must be at least 1 byte.
            if cloud_data.size < 1 {
                log_item!(
                    label.clone(),
                    "cloud-data assertion has invalid size (must be >= 1)",
                    "verify_cloud_data"
                )
                .validation_status(validation_status::ASSERTION_CLOUD_DATA_MALFORMED)
                .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));
            }

            // Step 2: hard binding assertions must not be stored as cloud data.
            if cloud_data.is_hard_binding() {
                log_item!(
                    label.clone(),
                    "cloud-data assertion references a hard binding assertion",
                    "verify_cloud_data"
                )
                .validation_status(validation_status::ASSERTION_CLOUD_DATA_HARD_BINDING)
                .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));
            }

            // Step 3: actions assertions must not be stored as cloud data in update manifests.
            if claim.update_manifest() && cloud_data.is_actions() {
                log_item!(
                    label.clone(),
                    "cloud-data assertion references an actions assertion in an update manifest",
                    "verify_cloud_data"
                )
                .validation_status(validation_status::ASSERTION_CLOUD_DATA_ACTIONS)
                .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));
            }

            // Check for forbbidden label types, including hard bindings and the cloud-data assertion itself.
            if cloud_data.is_forbidden().is_err() {
                log_item!(
                    label.clone(),
                    "cloud-data assertion references a forbidden label",
                    "verify_cloud_data"
                )
                .validation_status(validation_status::ASSERTION_CLOUD_DATA_MALFORMED)
                .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));
            }
        }

        Ok(())
    }

    /// Validate each `c2pa.external-reference` assertion per C2PA 2.4.
    /// No fetching of the external reference is performed, only the structure of the assertion is checked.
    pub(super) fn verify_external_reference(
        claim: &Claim,
        validation_log: &mut StatusTracker,
    ) -> Result<()> {
        use assertions::ExternalReference;

        for ca in claim.assertions_by_type(
            &Assertion::new(
                assertions::labels::EXTERNAL_REFERENCE,
                None,
                AssertionData::Cbor(Vec::new()),
            ),
            None,
        ) {
            let label = to_assertion_uri(claim.label(), &ca.label());

            let external_reference = match ExternalReference::from_assertion(ca.assertion()) {
                Ok(external_reference) => external_reference,
                Err(_) => {
                    log_item!(
                        label.clone(),
                        "external-reference assertion could not be decoded",
                        "verify_external_reference"
                    )
                    .validation_status(validation_status::ASSERTION_EXTERNAL_REFERENCE_MALFORMED)
                    .failure_no_throw(validation_log, Error::ClaimDecoding(label.clone()));
                    continue;
                }
            };

            if let Err(err) = external_reference.validate() {
                log_item!(label.clone(), err.to_string(), "verify_external_reference")
                    .validation_status(validation_status::ASSERTION_EXTERNAL_REFERENCE_MALFORMED)
                    .failure_no_throw(validation_log, err);
            }
        }

        Ok(())
    }

    // Perform metadata validation check.
    // Check the structure only.  C2PA 2.4 no longer requires checking against allowed fields.
    fn verify_metadata(claim: &Claim, _validation_log: &mut StatusTracker) -> Result<()> {
        for metadata_assertion in claim.metadata_assertions() {
            Metadata::from_assertion(metadata_assertion.assertion())?;
        }
        Ok(())
    }
}