Skip to content

Commit 0fea5a4

Browse files
committed
Update code to 2024 SDK release
This patch updates Crypto to the 2024 release version of CryptoKit. As with prior years, there are small tweaks to the API surface that cause this to manifest as a semver major. In this instance, the relevant change is the removal of the long-deprecated setters for the hash function block byte counts. This is another change that meets the technical definition of a semver major, but is practically extraordinarily unlikely to manifest in an actual problem. Nonetheless, we do have to acknowledge the reality that this can break compiling code (e.g. in cases where users have defined protocols that rely on having a setter available, even though they never call through it). To that end, this pushes Crypto up to 4.0.
1 parent b639b5b commit 0fea5a4

File tree

81 files changed

+1047
-908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1047
-908
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ SemVer and Swift Crypto's Public API guarantees should result in a working progr
130130

131131
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
132132

133+
Swift Crypto 3.0.0 was released in September 2023. The only breaking change between Swift Crypto 3.0.0 and 2.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 _or_ 3.0.0 series of releases.
134+
135+
Swift Crypto 4.0.0 was released in October 2024. The only breaking change was the removal of the non-functional setters for `blockByteSize` on the hash functions, which triggered a `fatalError` if they were ever called. For most users, then, it is safe to depend on the entire range from 1.0.0 to 4.0.0 inclusive.
136+
133137
To do so, please use the following dependency in your `Package.swift`:
134138

135139
```swift
136-
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
140+
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "5.0.0"),
137141
```
138142

139143
### Developing Swift Crypto on macOS

Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17-
#if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
17+
#if (!CRYPTO_IN_SWIFTPM_FORCE_BUILD_API) || CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
1818
typealias AESGCMImpl = CoreCryptoGCMImpl
19-
import Security
2019
#else
2120
typealias AESGCMImpl = OpenSSLAESGCMImpl
2221
#endif
2322

23+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
24+
import SwiftSystem
25+
#else
2426
import Foundation
27+
#endif
2528

2629
extension AES {
2730
/// The Advanced Encryption Standard (AES) Galois Counter Mode (GCM) cipher

Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17-
#if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
17+
#if (!CRYPTO_IN_SWIFTPM_FORCE_BUILD_API) || CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
1818
typealias ChaChaPolyImpl = CoreCryptoChaChaPolyImpl
19-
import Security
2019
#else
2120
typealias ChaChaPolyImpl = OpenSSLChaChaPolyImpl
2221
#endif
2322

23+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
24+
import SwiftSystem
25+
#else
2426
import Foundation
27+
#endif
28+
2529

2630
/// An implementation of the ChaCha20-Poly1305 cipher.
2731
public enum ChaChaPoly: Cipher {

Sources/Crypto/AEADs/Cipher.swift

+6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
23+
1824

1925
protocol AEADSealedBox {
2026
associatedtype Nonce: Sequence

Sources/Crypto/AEADs/Nonces.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
18+
import SwiftSystem
19+
#else
1720
import Foundation
21+
#endif
1822
// MARK: - Generated file, do NOT edit
1923
// any edits of this file WILL be overwritten and thus discarded
2024
// see section `gyb` in `README` for details.
2125

26+
27+
28+
2229
// MARK: - AES.GCM + Nonce
2330
extension AES.GCM {
2431
/// A value used once during a cryptographic operation and then discarded.
@@ -47,8 +54,8 @@ extension AES.GCM {
4754
/// ``init()`` method to instead create a random nonce.
4855
///
4956
/// - Parameters:
50-
/// - data: A 12-byte data representation of the nonce. The initializer throws an
51-
/// error if the data has a length other than 12 bytes.
57+
/// - data: A data representation of the nonce.
58+
/// The initializer throws an error if the data has a length smaller than 12 bytes.
5259
public init<D: DataProtocol>(data: D) throws {
5360
if data.count < AES.GCM.defaultNonceByteCount {
5461
throw CryptoKitError.incorrectParameterSize
@@ -109,8 +116,8 @@ extension ChaChaPoly {
109116
/// ``init()`` method to instead create a random nonce.
110117
///
111118
/// - Parameters:
112-
/// - data: A 12-byte data representation of the nonce. The initializer throws an
113-
/// error if the data has a length other than 12 bytes.
119+
/// - data: A 12-byte data representation of the nonce.
120+
/// The initializer throws an error if the data isn't 12 bytes long.
114121
public init<D: DataProtocol>(data: D) throws {
115122
if data.count != ChaChaPoly.nonceByteCount {
116123
throw CryptoKitError.incorrectParameterSize

Sources/Crypto/AEADs/Nonces.swift.gyb

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,31 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
18+
import SwiftSystem
19+
#else
1720
import Foundation
21+
#endif
1822
// MARK: - Generated file, do NOT edit
1923
// any edits of this file WILL be overwritten and thus discarded
2024
// see section `gyb` in `README` for details.
25+
2126
%{
22-
ciphers = [{"name": "AES.GCM", "recommendedNonceSize": "AES.GCM.defaultNonceByteCount", "nonceValidation": "< AES.GCM.defaultNonceByteCount"},{"name": "ChaChaPoly", "recommendedNonceSize": "ChaChaPoly.nonceByteCount", "nonceValidation": "!= ChaChaPoly.nonceByteCount"}]
27+
ciphers = [{"name": "AES.GCM", "recommendedNonceSize": "AES.GCM.defaultNonceByteCount", "nonceValidation": "< AES.GCM.defaultNonceByteCount", "dataDescription": "/// - data: A data representation of the nonce.\n/// The initializer throws an error if the data has a length smaller than 12 bytes."}]
28+
29+
if "NO_CHACHAPOLY" in globals():
30+
pass
31+
else:
32+
ciphers.append({"name": "ChaChaPoly", "recommendedNonceSize": "ChaChaPoly.nonceByteCount", "nonceValidation": "!= ChaChaPoly.nonceByteCount", "dataDescription": "/// - data: A 12-byte data representation of the nonce.\n/// The initializer throws an error if the data isn't 12 bytes long."})
2333
}%
34+
35+
2436
% for cipher in ciphers:
2537
%{
2638
name = cipher["name"]
2739
nonceSize = cipher["recommendedNonceSize"]
2840
nonceValidation = cipher["nonceValidation"]
41+
dataDescription = cipher["dataDescription"]
2942
}%
3043

3144
// MARK: - ${name} + Nonce
@@ -56,8 +69,7 @@ extension ${name} {
5669
/// ``init()`` method to instead create a random nonce.
5770
///
5871
/// - Parameters:
59-
/// - data: A 12-byte data representation of the nonce. The initializer throws an
60-
/// error if the data has a length other than 12 bytes.
72+
${dataDescription}
6173
public init<D: DataProtocol>(data: D) throws {
6274
if data.count ${nonceValidation} {
6375
throw CryptoKitError.incorrectParameterSize

Sources/Crypto/ASN1/ASN1.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
// This module implements "just enough" ASN.1. Specifically, we implement exactly enough ASN.1 DER parsing to handle
2025
// the following use-cases:

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// An ASN1 ANY represents...well, anything.

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// A bitstring is a representation of...well...some bits.

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension Bool: ASN1ImplicitlyTaggable {
2025
static var defaultIdentifier: ASN1.ASN1Identifier {

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// An `ASN1Identifier` is a representation of the abstract notion of an ASN.1 identifier. Identifiers have a number of properties that relate to both the specific

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

19-
/// A protocol that represents any internal object that can present itself as an INTEGER, or be parsed from
20-
/// an INTEGER.
24+
/// A protocol that represents any internal object that can present itself as a INTEGER, or be parsed from
25+
/// a INTEGER.
2126
///
2227
/// This is not a very good solution for a fully-fledged ASN.1 library: we'd rather have a better numerics
2328
/// protocol that could both initialize from and serialize to either bytes or words. However, no such

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// An ASN1 NULL represents nothing.

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// An octet string is a representation of a string of octets.

Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// A UTF8String is roughly what it sounds like. We note that all the string types are encoded as implicitly tagged

Sources/Crypto/ASN1/Basic ASN1 Types/ArraySliceBigint.swift

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
@_exported import CryptoKit
1616
#else
1717

18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
21+
import Foundation
22+
#endif
23+
1824
// For temporary purposes we pretend that ArraySlice is our "bigint" type. We don't really need anything else.
1925
extension ArraySlice: ASN1Serializable where Element == UInt8 { }
2026

Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
struct GeneralizedTime: ASN1ImplicitlyTaggable, Hashable {

Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
18+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
19+
import SwiftSystem
20+
#else
1721
import Foundation
22+
#endif
1823

1924
extension ASN1 {
2025
/// An Object Identifier is a representation of some kind of object: really any kind of object.

Sources/Crypto/ASN1/ECDSASignature.swift

+9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
15+
#if CRYPTOKIT_STATIC_LIBRARY
16+
@_exported import CryptoKit_Static
17+
#else
1518
@_exported import CryptoKit
19+
#endif
20+
#else
21+
22+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
23+
import SwiftSystem
1624
#else
1725
import Foundation
26+
#endif
1827

1928
extension ASN1 {
2029
/// An ECDSA signature is laid out as follows:

Sources/Crypto/ASN1/PEMDocument.swift

+9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
15+
#if CRYPTOKIT_STATIC_LIBRARY
16+
@_exported import CryptoKit_Static
17+
#else
1518
@_exported import CryptoKit
19+
#endif
20+
#else
21+
22+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
23+
import SwiftSystem
1624
#else
1725
import Foundation
26+
#endif
1827

1928
extension ASN1 {
2029
/// A PEM document is some data, and a discriminator type that is used to advertise the content.

Sources/Crypto/ASN1/PKCS8PrivateKey.swift

+4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
1515
@_exported import CryptoKit
1616
#else
17+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
18+
import SwiftSystem
19+
#else
1720
import Foundation
21+
#endif
1822

1923
extension ASN1 {
2024
// A PKCS#8 private key is one of two formats, depending on the version:

Sources/Crypto/ASN1/SEC1PrivateKey.swift

+9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
15+
#if CRYPTOKIT_STATIC_LIBRARY
16+
@_exported import CryptoKit_Static
17+
#else
1518
@_exported import CryptoKit
19+
#endif
20+
#else
21+
22+
#if CRYPTOKIT_NO_ACCESS_TO_FOUNDATION
23+
import SwiftSystem
1624
#else
1725
import Foundation
26+
#endif
1827

1928
extension ASN1 {
2029
// For private keys, SEC 1 uses:

0 commit comments

Comments
 (0)