Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Sources/PackageLoading/ManifestSignatureParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ public enum ManifestSignatureParser {
public enum Error: Swift.Error {
/// Package manifest file is inaccessible (missing, unreadable, etc).
case inaccessibleManifest(path: AbsolutePath, reason: String)
/// Package manifest file's content can not be decoded as a UTF-8 string.
case nonUTF8EncodedManifest(path: AbsolutePath)
/// Malformed manifest signature.
case malformedManifestSignature
}
Expand Down
37 changes: 35 additions & 2 deletions Sources/PackageRegistry/RegistryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2259,14 +2259,29 @@ extension RegistryReleaseMetadata {
private struct RegistryClientSignatureValidationDelegate: SignatureValidation.Delegate {
let underlying: RegistryClient.Delegate?

private let onUnsignedResponseCache = ThreadSafeKeyValueStore<ResponseCacheKey, Bool>()
private let onUntrustedResponseCache = ThreadSafeKeyValueStore<ResponseCacheKey, Bool>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added caching to avoid prompting repeatedly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


func onUnsigned(
registry: Registry,
package: PackageModel.PackageIdentity,
version: TSCUtility.Version,
completion: (Bool) -> Void
) {
let responseCacheKey = ResponseCacheKey(registry: registry, package: package, version: version)
if let cachedResponse = self.onUnsignedResponseCache[responseCacheKey] {
return completion(cachedResponse)
}

if let underlying {
underlying.onUnsigned(registry: registry, package: package, version: version, completion: completion)
underlying.onUnsigned(
registry: registry,
package: package,
version: version
) { response in
self.onUnsignedResponseCache[responseCacheKey] = response
completion(response)
}
} else {
// true == continue resolution
// false == stop dependency resolution
Expand All @@ -2280,14 +2295,32 @@ private struct RegistryClientSignatureValidationDelegate: SignatureValidation.De
version: TSCUtility.Version,
completion: (Bool) -> Void
) {
let responseCacheKey = ResponseCacheKey(registry: registry, package: package, version: version)
if let cachedResponse = self.onUntrustedResponseCache[responseCacheKey] {
return completion(cachedResponse)
}

if let underlying {
underlying.onUntrusted(registry: registry, package: package, version: version, completion: completion)
underlying.onUntrusted(
registry: registry,
package: package,
version: version
) { response in
self.onUntrustedResponseCache[responseCacheKey] = response
completion(response)
}
} else {
// true == continue resolution
// false == stop dependency resolution
completion(false)
}
}

private struct ResponseCacheKey: Hashable {
let registry: Registry
let package: PackageModel.PackageIdentity
let version: TSCUtility.Version
}
}

// MARK: - Utilities
Expand Down
Loading