@@ -206,51 +206,54 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
206
206
callback ( . failure( StringError ( " Unsupported platform " ) ) )
207
207
} else {
208
208
// Check the signature
209
- let signatureResults = ThreadSafeArrayStore < Result < Void , Error > > ( )
210
- certPolicyKeys. forEach { certPolicyKey in
211
- Task {
212
- let count : Int
213
- do {
214
- try await self . signatureValidator. validate (
215
- signedCollection: signedCollection,
216
- certPolicyKey: certPolicyKey
217
- )
218
- count = signatureResults. append ( . success( ( ) ) )
219
- } catch {
220
- count = signatureResults. append ( . failure( error) )
221
- }
222
-
223
- if count == certPolicyKeys. count {
224
- if signatureResults. compactMap ( \. success) . first != nil {
225
- callback ( self . makeCollection (
226
- from: signedCollection. collection,
227
- source: source,
228
- signature: Model . SignatureData ( from: signedCollection. signature, isVerified: true )
229
- ) )
230
- } else {
231
- guard let error = signatureResults. compactMap ( \. failure) . first else {
232
- return callback (
233
- . failure(
234
- InternalError (
235
- " Expected at least one package collection signature validation failure but got none "
236
- )
237
- )
209
+ Task {
210
+ let signatureResults = await withTaskGroup ( of: Result< Void, Error> . self ) { group in
211
+ for certPolicyKey in certPolicyKeys {
212
+ group. addTask {
213
+ do {
214
+ try await self . signatureValidator. validate (
215
+ signedCollection: signedCollection,
216
+ certPolicyKey: certPolicyKey
238
217
)
239
- }
240
-
241
- self . observabilityScope. emit (
242
- warning: " The signature of package collection [ \( source) ] is invalid " ,
243
- underlyingError: error
244
- )
245
- if PackageCollectionSigningError
246
- . noTrustedRootCertsConfigured == error as? PackageCollectionSigningError
247
- {
248
- callback ( . failure( PackageCollectionError . cannotVerifySignature) )
249
- } else {
250
- callback ( . failure( PackageCollectionError . invalidSignature) )
218
+ return . success( ( ) )
219
+ } catch {
220
+ return . failure( error)
251
221
}
252
222
}
253
223
}
224
+ return await group. reduce ( into: [ ] ) { partialResult, validateResult in
225
+ partialResult. append ( validateResult)
226
+ }
227
+ }
228
+
229
+ if signatureResults. compactMap ( \. success) . first != nil {
230
+ callback ( self . makeCollection (
231
+ from: signedCollection. collection,
232
+ source: source,
233
+ signature: Model . SignatureData ( from: signedCollection. signature, isVerified: true )
234
+ ) )
235
+ } else {
236
+ guard let error = signatureResults. compactMap ( \. failure) . first else {
237
+ return callback (
238
+ . failure(
239
+ InternalError (
240
+ " Expected at least one package collection signature validation failure but got none "
241
+ )
242
+ )
243
+ )
244
+ }
245
+
246
+ self . observabilityScope. emit (
247
+ warning: " The signature of package collection [ \( source) ] is invalid " ,
248
+ underlyingError: error
249
+ )
250
+ if PackageCollectionSigningError
251
+ . noTrustedRootCertsConfigured == error as? PackageCollectionSigningError
252
+ {
253
+ callback ( . failure( PackageCollectionError . cannotVerifySignature) )
254
+ } else {
255
+ callback ( . failure( PackageCollectionError . invalidSignature) )
256
+ }
254
257
}
255
258
}
256
259
}
0 commit comments