From 1fbb6ef21f1525ed5faf4c95207b9c11bea27e94 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 15 Oct 2024 21:19:03 +0100 Subject: [PATCH] Avoid the macOS requirement. (#204) --- Sources/X509/SecKeyWrapper.swift | 2 +- Tests/X509Tests/SecKeyWrapperTests.swift | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/X509/SecKeyWrapper.swift b/Sources/X509/SecKeyWrapper.swift index 8205944..979cbf1 100644 --- a/Sources/X509/SecKeyWrapper.swift +++ b/Sources/X509/SecKeyWrapper.swift @@ -119,7 +119,7 @@ extension Certificate.PrivateKey { ) } - if privateKeyType == (kSecAttrKeyTypeECDSA as String) { + if privateKeyType == (kSecAttrKeyTypeECSECPrimeRandom as String) { let keySize = attributes[kSecAttrKeySizeInBits as String] as? Int ?? -1 if keySize == 256 { diff --git a/Tests/X509Tests/SecKeyWrapperTests.swift b/Tests/X509Tests/SecKeyWrapperTests.swift index 6435376..dce5664 100644 --- a/Tests/X509Tests/SecKeyWrapperTests.swift +++ b/Tests/X509Tests/SecKeyWrapperTests.swift @@ -38,7 +38,12 @@ final class SecKeyWrapperTests: XCTestCase { ) // eliptic curves - for keyType in [kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyTypeEC, kSecAttrKeyTypeECDSA] { + var keyTypes = [kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyTypeEC] + #if os(macOS) + keyTypes.append(kSecAttrKeyTypeECDSA) + #endif + + for keyType in keyTypes { for keySize in [256, 384] { for useSEP in [true, false] { keys.append( @@ -52,9 +57,11 @@ final class SecKeyWrapperTests: XCTestCase { } } } + return keys } + @available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *) func testPEMExport() throws { for candidate in try generateCandidateKeys() { try XCTContext.runActivity(named: "Testing \(candidate.type) key (size: \(candidate.keySize))") { _ in