From 066a5a051153155a1c0bcba7bf20e1bcab13dcd4 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Sun, 14 Dec 2025 16:35:06 -0500 Subject: [PATCH] Remove `@available` annotations where allowed. iOS / tvOS now have a minimum version of 13. We can simplify our source `@available` annotations where reasonable, as well as make the IsSupported logic simpler. --- .../System/Security/Cryptography/AesGcm.Apple.cs | 8 ++------ .../Cryptography/ChaCha20Poly1305.Apple.cs | 4 ++-- .../pal_swiftbindings.swift | 14 -------------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs index b2621493ae2ec4..df4a759ffccb8c 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs @@ -14,12 +14,8 @@ public sealed partial class AesGcm // CryptoKit only supports 16 byte tags. private static readonly KeySizes s_tagByteSizes = new KeySizes(16, 16, 1); - // CryptoKit added AES.GCM in macOS 10.15, which is lower than our minimum target for macOS/MacCatalyst. On iOS/tvOS, it was added in 13.0. - public static partial bool IsSupported => - OperatingSystem.IsMacOS() || - OperatingSystem.IsMacCatalyst() || - OperatingSystem.IsIOSVersionAtLeast(13) || - OperatingSystem.IsTvOSVersionAtLeast(13); + // CryptoKit added AES.GCM in macOS 10.15, and iOS/tvOS in 13.0. + public static partial bool IsSupported => true; public static partial KeySizes TagByteSizes => s_tagByteSizes; diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs index 55d8dee2c7c1e7..1daa598f7c6a64 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs @@ -8,8 +8,8 @@ namespace System.Security.Cryptography { public sealed partial class ChaCha20Poly1305 { - // CryptoKit added ChaCha20Poly1305 in macOS 10.15, which is lower than our minimum target for macOS/MacCatalyst. On iOS/tvOS, it was added in 13.0. - public static bool IsSupported => OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13); + // CryptoKit added ChaCha20Poly1305 in macOS 10.15, and iOS/tvOS in 13.0. + public static bool IsSupported => true; private FixedMemoryKeyBox _keyBox; [MemberNotNull(nameof(_keyBox))] diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift index 0915b647c33f71..240e22b5228624 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift @@ -21,7 +21,6 @@ protocol SealedBoxProtocol { ) throws where C : DataProtocol, T : DataProtocol } -@available(iOS 13, tvOS 13, *) protocol AEADSymmetricAlgorithm { associatedtype SealedBox : SealedBoxProtocol @@ -31,29 +30,22 @@ protocol AEADSymmetricAlgorithm { static func open(_ sealedBox: SealedBox, using key: SymmetricKey) throws -> Data } -@available(iOS 13, tvOS 13, *) extension AES.GCM.Nonce: NonceProtocol {} -@available(iOS 13, tvOS 13, *) extension AES.GCM.SealedBox: SealedBoxProtocol { typealias Nonce = AES.GCM.Nonce } -@available(iOS 13, tvOS 13, *) extension AES.GCM: AEADSymmetricAlgorithm {} -@available(iOS 13, tvOS 13, *) extension ChaChaPoly.Nonce: NonceProtocol {} -@available(iOS 13, tvOS 13, *) extension ChaChaPoly.SealedBox: SealedBoxProtocol { typealias Nonce = ChaChaPoly.Nonce } -@available(iOS 13, tvOS 13, *) extension ChaChaPoly: AEADSymmetricAlgorithm {} -@available(iOS 13, tvOS 13, *) func encrypt( _ algorithm: Algorithm.Type, key: UnsafeBufferPointer, @@ -79,7 +71,6 @@ func encrypt( _ = resultTag.copyBytes(to: tag) } -@available(iOS 13, tvOS 13, *) func decrypt( _ algorithm: Algorithm.Type, key: UnsafeBufferPointer, @@ -101,7 +92,6 @@ func decrypt( } @_silgen_name("AppleCryptoNative_ChaCha20Poly1305Encrypt") -@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_ChaCha20Poly1305Encrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -121,7 +111,6 @@ public func AppleCryptoNative_ChaCha20Poly1305Encrypt( } @_silgen_name("AppleCryptoNative_ChaCha20Poly1305Decrypt") -@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_ChaCha20Poly1305Decrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -141,7 +130,6 @@ public func AppleCryptoNative_ChaCha20Poly1305Decrypt( } @_silgen_name("AppleCryptoNative_AesGcmEncrypt") -@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_AesGcmEncrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -161,7 +149,6 @@ public func AppleCryptoNative_AesGcmEncrypt( } @_silgen_name("AppleCryptoNative_AesGcmDecrypt") -@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_AesGcmDecrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -181,7 +168,6 @@ public func AppleCryptoNative_AesGcmDecrypt( } @_silgen_name("AppleCryptoNative_IsAuthenticationFailure") -@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_IsAuthenticationFailure(error: Error) -> Bool { if let error = error as? CryptoKitError { switch error {