@@ -285,16 +285,7 @@ public struct Linux: Platform {
285285 throw SwiftlyError ( message: msg)
286286 }
287287
288- let tmpFile = self . getTempFilePath ( )
289- try await fs. create ( . mode( 0o600 ) , file: tmpFile, contents: nil )
290- try await fs. withTemporary ( files: tmpFile) {
291- try await ctx. httpClient. getGpgKeys ( ) . download ( to: tmpFile)
292- if let mockedHomeDir = ctx. mockedHomeDir {
293- try await sys. gpg ( ) . _import ( key: tmpFile) . run ( environment: . inherit. updating ( [ " GNUPGHOME " : ( mockedHomeDir / " .gnupg " ) . string] ) , quiet: true )
294- } else {
295- try await sys. gpg ( ) . _import ( key: tmpFile) . run ( quiet: true )
296- }
297- }
288+ try await self . importGpgKeys ( ctx)
298289 }
299290
300291 guard let manager = manager else {
@@ -430,6 +421,9 @@ public struct Linux: Platform {
430421 public func verifyToolchainSignature(
431422 _ ctx: SwiftlyCoreContext , toolchainFile: ToolchainFile , archive: FilePath , verbose: Bool
432423 ) async throws {
424+ // Ensure GPG keys are imported before attempting signature verification
425+ try await self . importGpgKeys ( ctx)
426+
433427 if verbose {
434428 await ctx. message ( " Downloading toolchain signature... " )
435429 }
@@ -452,9 +446,26 @@ public struct Linux: Platform {
452446 }
453447 }
454448
449+ /// Import Swift.org GPG keys for signature verification
450+ private func importGpgKeys( _ ctx: SwiftlyCoreContext ) async throws {
451+ let tmpFile = self . getTempFilePath ( )
452+ try await fs. create ( . mode( 0o600 ) , file: tmpFile, contents: nil )
453+ try await fs. withTemporary ( files: tmpFile) {
454+ try await ctx. httpClient. getGpgKeys ( ) . download ( to: tmpFile)
455+ if let mockedHomeDir = ctx. mockedHomeDir {
456+ try await sys. gpg ( ) . _import ( key: tmpFile) . run ( environment: . inherit. updating ( [ " GNUPGHOME " : ( mockedHomeDir / " .gnupg " ) . string] ) , quiet: true )
457+ } else {
458+ try await sys. gpg ( ) . _import ( key: tmpFile) . run ( quiet: true )
459+ }
460+ }
461+ }
462+
455463 public func verifySwiftlySignature(
456464 _ ctx: SwiftlyCoreContext , archiveDownloadURL: URL , archive: FilePath , verbose: Bool
457465 ) async throws {
466+ // Ensure GPG keys are imported before attempting signature verification
467+ try await self . importGpgKeys ( ctx)
468+
458469 if verbose {
459470 await ctx. message ( " Downloading swiftly signature... " )
460471 }
0 commit comments