11
11
// specific language governing permissions and limitations under
12
12
// each license.
13
13
14
- use std:: fmt:: { Debug , Formatter } ;
14
+ use std:: {
15
+ collections:: HashMap ,
16
+ fmt:: { Debug , Formatter } ,
17
+ } ;
15
18
16
- use c2pa:: Manifest ;
19
+ use c2pa:: { Manifest , Reader } ;
17
20
use serde:: { Deserialize , Serialize } ;
18
21
use serde_bytes:: ByteBuf ;
19
22
20
23
use crate :: {
21
24
identity_assertion:: {
22
- report:: { IdentityAssertionReport , IdentityAssertionsForManifest , SignerPayloadReport } ,
25
+ report:: {
26
+ IdentityAssertionReport , IdentityAssertionsForManifest ,
27
+ IdentityAssertionsForManifestStore , SignerPayloadReport ,
28
+ } ,
23
29
signer_payload:: SignerPayload ,
24
30
} ,
25
31
internal:: debug_byte_slice:: DebugByteSlice ,
@@ -116,6 +122,15 @@ impl IdentityAssertion {
116
122
manifest : & Manifest ,
117
123
verifier : & SV ,
118
124
) -> impl Serialize {
125
+ Self :: summarize_all_impl ( manifest, verifier) . await
126
+ }
127
+
128
+ pub ( crate ) async fn summarize_all_impl < SV : SignatureVerifier > (
129
+ manifest : & Manifest ,
130
+ verifier : & SV ,
131
+ ) -> IdentityAssertionsForManifest <
132
+ <<SV as SignatureVerifier >:: Output as ToCredentialSummary >:: CredentialSummary ,
133
+ > {
119
134
// NOTE: We can't write this using .map(...).collect() because there are async
120
135
// calls.
121
136
let mut reports: Vec <
@@ -142,6 +157,65 @@ impl IdentityAssertion {
142
157
}
143
158
}
144
159
160
+ /// Summarize all of the identity assertions found for a [`ManifestStore`].
161
+ ///
162
+ /// [`ManifestStore`]: c2pa::ManifestStore
163
+ #[ cfg( feature = "v1_api" ) ]
164
+ pub async fn summarize_manifest_store < SV : SignatureVerifier > (
165
+ store : & c2pa:: ManifestStore ,
166
+ verifier : & SV ,
167
+ ) -> impl Serialize {
168
+ // NOTE: We can't write this using .map(...).collect() because there are async
169
+ // calls.
170
+ let mut reports: HashMap <
171
+ String ,
172
+ IdentityAssertionsForManifest <
173
+ <<SV as SignatureVerifier >:: Output as ToCredentialSummary >:: CredentialSummary ,
174
+ > ,
175
+ > = HashMap :: new ( ) ;
176
+
177
+ for ( id, manifest) in store. manifests ( ) {
178
+ let report = Self :: summarize_all_impl ( manifest, verifier) . await ;
179
+ reports. insert ( id. clone ( ) , report) ;
180
+ }
181
+
182
+ IdentityAssertionsForManifestStore :: <
183
+ <<SV as SignatureVerifier >:: Output as ToCredentialSummary >:: CredentialSummary ,
184
+ > {
185
+ assertions_for_manifest : reports,
186
+ }
187
+ }
188
+
189
+ /// Summarize all of the identity assertions found for a [`Reader`].
190
+ pub async fn summarize_from_reader < SV : SignatureVerifier > (
191
+ reader : & Reader ,
192
+ verifier : & SV ,
193
+ ) -> impl Serialize {
194
+ // NOTE: We can't write this using .map(...).collect() because there are async
195
+ // calls.
196
+ let mut reports: HashMap <
197
+ String ,
198
+ IdentityAssertionsForManifest <
199
+ <<SV as SignatureVerifier >:: Output as ToCredentialSummary >:: CredentialSummary ,
200
+ > ,
201
+ > = HashMap :: new ( ) ;
202
+
203
+ for manifest in reader. iter_manifests ( ) {
204
+ let report = Self :: summarize_all_impl ( manifest, verifier) . await ;
205
+
206
+ // TO DO: What to do if manifest doesn't have a label?
207
+ if let Some ( label) = manifest. label ( ) {
208
+ reports. insert ( label. to_owned ( ) , report) ;
209
+ }
210
+ }
211
+
212
+ IdentityAssertionsForManifestStore :: <
213
+ <<SV as SignatureVerifier >:: Output as ToCredentialSummary >:: CredentialSummary ,
214
+ > {
215
+ assertions_for_manifest : reports,
216
+ }
217
+ }
218
+
145
219
/// Using the provided [`SignatureVerifier`], check the validity of this
146
220
/// identity assertion.
147
221
///
0 commit comments