From 6a032cf17dc5e5fc015f5d8fbcd9813d2566dce2 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 23 Oct 2026 11:58:54 +0100 Subject: [PATCH] Remove pre-6.2 compiler checks (#492) ### Motivation: Tending the garden. This repo only supports Swift 6.2+ these days, but we have some code that conditionally compiles based on compiler versions that are either always false or always true. ### Modifications: - Remove any pre-6.2 compiler check. ### Result: Removing dead code. --- .../EC/EllipticCurvePoint.swift | 113 ------------------ Sources/CryptoExtras/AES/CMAC.swift | 14 --- .../CryptoExtras/Util/Data+Extensions.swift | 5 - Tests/CryptoExtrasTests/ARC/ARCAPITests.swift | 25 ---- Tests/CryptoTests/Utils/RFCVector.swift | 5 - Tests/CryptoTests/Utils/Wycheproof.swift | 5 - 6 files changed, 167 deletions(-) diff --git a/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift b/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift index 98fbea01..60ce85e3 100644 --- a/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift +++ b/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift @@ -77,10 +77,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.multiply(by: rhs, on: group, context: context) } - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package consuming func multiplying( by rhs: ArbitraryPrecisionInteger, @@ -90,18 +86,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.multiply(by: rhs, on: group, context: context) return self } - #else - @usableFromInline - package func multiplying( - by rhs: ArbitraryPrecisionInteger, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var `self` = self - try self.multiply(by: rhs, on: group, context: context) - return self - } - #endif @usableFromInline package static func multiplying( @@ -134,10 +118,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.add(rhs, on: group, context: context) } - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package consuming func adding( _ rhs: consuming EllipticCurvePoint, @@ -147,23 +127,7 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.add(rhs, on: group, context: context) return self } - #else - @usableFromInline - package func adding( - _ rhs: consuming EllipticCurvePoint, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var `self` = self - try self.add(rhs, on: group, context: context) - return self - } - #endif - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package static func adding( _ lhs: consuming EllipticCurvePoint, @@ -174,19 +138,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try lhs.add(rhs, on: group, context: context) return lhs } - #else - @usableFromInline - package static func adding( - _ lhs: EllipticCurvePoint, - _ rhs: EllipticCurvePoint, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var lhs = lhs - try lhs.add(rhs, on: group, context: context) - return lhs - } - #endif @usableFromInline package mutating func invert( @@ -207,10 +158,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.invert(on: group, context: context) } - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package consuming func inverting( on group: BoringSSLEllipticCurveGroup, @@ -219,22 +166,7 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.invert(on: group, context: context) return self } - #else - @usableFromInline - package func inverting( - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var `self` = self - try self.invert(on: group, context: context) - return self - } - #endif - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package static func inverting( _ point: consuming EllipticCurvePoint, @@ -244,18 +176,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try point.invert(on: group, context: context) return point } - #else - @usableFromInline - package static func inverting( - _ point: EllipticCurvePoint, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var point = point - try point.invert(on: group, context: context) - return point - } - #endif @usableFromInline package mutating func subtract( @@ -278,10 +198,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.subtract(rhs, on: group, context: context) } - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package consuming func subtracting( _ rhs: consuming EllipticCurvePoint, @@ -291,23 +207,7 @@ package struct EllipticCurvePoint: @unchecked Sendable { try self.subtract(rhs, on: group, context: context) return self } - #else - @usableFromInline - package func subtracting( - _ rhs: EllipticCurvePoint, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var `self` = self - try self.subtract(rhs, on: group, context: context) - return self - } - #endif - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) @usableFromInline package static func subtracting( _ rhs: consuming EllipticCurvePoint, @@ -318,19 +218,6 @@ package struct EllipticCurvePoint: @unchecked Sendable { try lhs.subtract(rhs, on: group, context: context) return lhs } - #else - @usableFromInline - package static func subtracting( - _ rhs: EllipticCurvePoint, - from lhs: EllipticCurvePoint, - on group: BoringSSLEllipticCurveGroup, - context: FiniteFieldArithmeticContext? = nil - ) throws -> EllipticCurvePoint { - var lhs = lhs - try lhs.subtract(rhs, on: group, context: context) - return lhs - } - #endif @usableFromInline package init( diff --git a/Sources/CryptoExtras/AES/CMAC.swift b/Sources/CryptoExtras/AES/CMAC.swift index a5a4b201..7b10ebf7 100644 --- a/Sources/CryptoExtras/AES/CMAC.swift +++ b/Sources/CryptoExtras/AES/CMAC.swift @@ -71,10 +71,6 @@ extension AES { self.backing.update(bufferPointer) } - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) /// Finalizes the message authentication computation and returns the /// computed code. /// @@ -87,16 +83,6 @@ extension AES { self.cowIfNeeded() return self.backing.finalize() } - #else - /// Finalizes the message authentication computation and returns the - /// computed code. - /// - /// - Returns: The message authentication code. - public func finalize() -> AES.CMAC.MAC { - var `self` = self - return self.backing.finalize() - } - #endif /// Updates the MAC with data. /// diff --git a/Sources/CryptoExtras/Util/Data+Extensions.swift b/Sources/CryptoExtras/Util/Data+Extensions.swift index 4276aa6b..a0ca7f9d 100644 --- a/Sources/CryptoExtras/Util/Data+Extensions.swift +++ b/Sources/CryptoExtras/Util/Data+Extensions.swift @@ -19,14 +19,9 @@ import Foundation #endif extension Data { - // This enhancement can only be present on 6.1 or later because of the - // absence of https://github.com/swiftlang/swift/pull/76186 in older - // compilers. - #if compiler(>=6.1) // This overload reduces allocations when used in a chain of infix operations. static func + (lhs: consuming Data, rhs: consuming Data) -> Data { lhs.append(contentsOf: rhs) return lhs } - #endif } diff --git a/Tests/CryptoExtrasTests/ARC/ARCAPITests.swift b/Tests/CryptoExtrasTests/ARC/ARCAPITests.swift index 9e71f627..35bc28ac 100644 --- a/Tests/CryptoExtrasTests/ARC/ARCAPITests.swift +++ b/Tests/CryptoExtrasTests/ARC/ARCAPITests.swift @@ -325,28 +325,3 @@ extension P384._ARCV1: ARCV1 {} @available(*, deprecated, message: "ARC(P-384) has been removed from the IETF draft; use ARC(P-256) instead.") @available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, visionOS 2.0, *) extension P384: ARCCurve {} - - -// Swift 5.10 compiler needs a little more help to infer the conformances. -#if swift(<6.0) -@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, visionOS 2.0, *) -fileprivate extension P256._ARCV1.PrivateKey { - typealias H2G = P256._ARCV1.H2G - typealias Credential = P256._ARCV1.Credential - typealias PublicKey = P256._ARCV1.PublicKey - typealias CredentialRequest = P256._ARCV1.CredentialRequest - typealias CredentialResponse = P256._ARCV1.CredentialResponse - typealias Presentation = P256._ARCV1.Presentation -} - -@available(*, deprecated, message: "ARC(P-384) has been removed from the IETF draft; use ARC(P-256) instead.") -@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, visionOS 2.0, *) -fileprivate extension P384._ARCV1.PrivateKey { - typealias H2G = P384._ARCV1.H2G - typealias Credential = P384._ARCV1.Credential - typealias PublicKey = P384._ARCV1.PublicKey - typealias CredentialRequest = P384._ARCV1.CredentialRequest - typealias CredentialResponse = P384._ARCV1.CredentialResponse - typealias Presentation = P384._ARCV1.Presentation -} -#endif diff --git a/Tests/CryptoTests/Utils/RFCVector.swift b/Tests/CryptoTests/Utils/RFCVector.swift index 6bbe4aaf..d46e75a0 100644 --- a/Tests/CryptoTests/Utils/RFCVector.swift +++ b/Tests/CryptoTests/Utils/RFCVector.swift @@ -34,7 +34,6 @@ struct RFCVectorDecoder { for _ in 0..<3 { fileURL!.deleteLastPathComponent() } - #if compiler(>=6.0) if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { fileURL!.append(path: "Test Vectors", directoryHint: .isDirectory) fileURL!.append(path: "\(fileName).txt", directoryHint: .notDirectory) @@ -42,10 +41,6 @@ struct RFCVectorDecoder { fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true) fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) } - #else - fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true) - fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) - #endif let rfcVectorData = try Data(contentsOf: fileURL!) self.rfcVectorData = String(decoding: rfcVectorData, as: Unicode.UTF8.self) diff --git a/Tests/CryptoTests/Utils/Wycheproof.swift b/Tests/CryptoTests/Utils/Wycheproof.swift index a4bb46cd..ce3713cf 100644 --- a/Tests/CryptoTests/Utils/Wycheproof.swift +++ b/Tests/CryptoTests/Utils/Wycheproof.swift @@ -26,7 +26,6 @@ extension XCTestCase { for _ in 0..<3 { fileURL.deleteLastPathComponent() } - #if compiler(>=6.0) if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { fileURL.append(path: "Test Vectors", directoryHint: .isDirectory) fileURL.append(path: "\(jsonName).json", directoryHint: .notDirectory) @@ -34,10 +33,6 @@ extension XCTestCase { fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true) fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) } - #else - fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true) - fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) - #endif let data = try orFail(file: file, line: line) { try Data(contentsOf: unwrap(fileURL, file: file, line: line)) }