Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit f75bffd

Browse files
authored
Fix Swift compilation errors in CertificateView.swift
1 parent 3e89f3a commit f75bffd

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

Sources/prosign/views/CertificateView.swift

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Release: Codable, Identifiable, Equatable, Hashable {
2929
Date()
3030
}
3131
}
32-
struct Asset: Codable {
32+
struct Asset: Codable, Hashable, Equatable {
3333
let name: String
3434
let browserDownloadUrl: String
3535

@@ -176,7 +176,7 @@ struct OfficialCertificatesView: View {
176176
var decodeData = data
177177
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200, pat != nil {
178178
// Fallback to unauthenticated
179-
var fallbackRequest = URLRequest(url: url)
179+
let fallbackRequest = URLRequest(url: url)
180180
let (fallbackData, _) = try await URLSession.shared.data(for: fallbackRequest)
181181
decodeData = fallbackData
182182
}
@@ -194,11 +194,28 @@ struct OfficialCertificatesView: View {
194194
}
195195
}
196196

197+
private func findCertificateFiles(in directory: URL) throws -> (p12Urls: [URL], provUrls: [URL]) {
198+
var p12Urls: [URL] = []
199+
var provUrls: [URL] = []
200+
if let enumerator = FileManager.default.enumerator(at: directory, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles, .skipsSubdirectoryDescendants]) {
201+
for case let fileURL as URL in enumerator {
202+
let path = fileURL.path
203+
if !path.contains("__MACOSX") {
204+
if path.hasSuffix(".p12") {
205+
p12Urls.append(fileURL)
206+
} else if path.hasSuffix(".mobileprovision") {
207+
provUrls.append(fileURL)
208+
}
209+
}
210+
}
211+
}
212+
return (p12Urls, provUrls)
213+
}
214+
197215
private func checkCertificate() {
198216
guard let release = selectedRelease,
199217
let asset = release.assets.first(where: { $0.name.hasSuffix(".zip") }),
200-
let downloadStr = asset.browserDownloadUrl,
201-
let downloadUrl = URL(string: downloadStr) else {
218+
let downloadUrl = URL(string: asset.browserDownloadUrl) else {
202219
statusMessage = "Invalid release"
203220
return
204221
}
@@ -216,7 +233,7 @@ struct OfficialCertificatesView: View {
216233
(tempData, response) = try await URLSession.shared.data(for: downloadRequest)
217234
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200, pat != nil {
218235
// Fallback
219-
var fallbackRequest = URLRequest(url: downloadUrl)
236+
let fallbackRequest = URLRequest(url: downloadUrl)
220237
(tempData, _) = try await URLSession.shared.data(for: fallbackRequest)
221238
}
222239
let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
@@ -229,20 +246,7 @@ struct OfficialCertificatesView: View {
229246
let extractDir = tempDir.appendingPathComponent("extracted")
230247
try FileManager.default.unzipItem(at: zipPath, to: extractDir, progress: nil)
231248
// Find files
232-
var p12Urls: [URL] = []
233-
var provUrls: [URL] = []
234-
if let enumerator = FileManager.default.enumerator(at: extractDir, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles, .skipsSubdirectoryDescendants]) {
235-
for case let fileURL as URL in enumerator {
236-
let path = fileURL.path
237-
if !path.contains("__MACOSX") {
238-
if path.hasSuffix(".p12") {
239-
p12Urls.append(fileURL)
240-
} else if path.hasSuffix(".mobileprovision") {
241-
provUrls.append(fileURL)
242-
}
243-
}
244-
}
245-
}
249+
let (p12Urls, provUrls) = try findCertificateFiles(in: extractDir)
246250
guard p12Urls.count == 1, provUrls.count == 1 else {
247251
throw NSError(domain: "Extraction", code: 1, userInfo: [NSLocalizedDescriptionKey: "Unable to extract certificate"])
248252
}

0 commit comments

Comments
 (0)