Skip to content

Commit 871f95d

Browse files
0xTimLukasa
andauthored
Typealias CryptoKitError (apple#285)
Provides a typealias for `CryptoKitError` to hide the implementation detail of CryptoKit. Resolves apple#274 ### Motivation: CryptoKit is an implementation detail on Apple platforms - this makes it clearer for users coming from other platforms ### Modifications: Added a type alias and updated documentation Co-authored-by: Cory Benfield <lukasa@apple.com>
1 parent af6be72 commit 871f95d

File tree

7 files changed

+44
-25
lines changed

7 files changed

+44
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ What this means for you is that you should depend on Swift Crypto with a version
129129
In SwiftPM that can be easily done specifying for example `from: "1.0.0"` meaning that you support Swift Crypto in every version starting from 1.0.0 up to (excluding) 2.0.0.
130130
SemVer and Swift Crypto's Public API guarantees should result in a working program without having to worry about testing every single version for compatibility.
131131

132-
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.
132+
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 `CryptoError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
133133

134134
To do so, please use the following dependency in your `Package.swift`:
135135

Sources/Crypto/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_library(Crypto
3636
"ASN1/PKCS8PrivateKey.swift"
3737
"ASN1/SEC1PrivateKey.swift"
3838
"ASN1/SubjectPublicKeyInfo.swift"
39+
"CryptoError_boring.swift"
3940
"CryptoKitErrors.swift"
4041
"Digests/BoringSSL/Digest_boring.swift"
4142
"Digests/Digest.swift"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftCrypto open source project
4+
//
5+
// Copyright (c) 2019-2025 Apple Inc. and the SwiftCrypto project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *)
16+
public typealias CryptoError = CryptoKitError
17+
@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
18+
public typealias CryptoASN1Error = CryptoKitASN1Error

Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension MLDSA${parameter_set} {
4343
///
4444
/// - Parameter seedRepresentation: The seed to use to generate the private key.
4545
///
46-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 32 bytes long.
46+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 32 bytes long.
4747
public init(seedRepresentation: some DataProtocol) throws {
4848
self.backing = try Backing(seedRepresentation: seedRepresentation)
4949
}
@@ -119,7 +119,7 @@ extension MLDSA${parameter_set} {
119119
///
120120
/// - Parameter seedRepresentation: The seed to use to generate the private key.
121121
///
122-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 32 bytes long.
122+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 32 bytes long.
123123
init(seedRepresentation: some DataProtocol) throws {
124124
guard seedRepresentation.count == MLDSA.seedByteCount else {
125125
throw CryptoKitError.incorrectKeySize
@@ -199,7 +199,7 @@ extension MLDSA${parameter_set} {
199199
///
200200
/// - Parameter rawRepresentation: The public key bytes.
201201
///
202-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
202+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
203203
public init(rawRepresentation: some DataProtocol) throws {
204204
self.backing = try Backing(rawRepresentation: rawRepresentation)
205205
}
@@ -252,7 +252,7 @@ extension MLDSA${parameter_set} {
252252
///
253253
/// - Parameter rawRepresentation: The public key bytes.
254254
///
255-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
255+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
256256
init(rawRepresentation: some DataProtocol) throws {
257257
guard rawRepresentation.count == MLDSA${parameter_set}.PublicKey.Backing.byteCount else {
258258
throw CryptoKitError.incorrectKeySize

Sources/_CryptoExtras/MLKEM/MLKEM_boring.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension MLKEM768 {
4646
///
4747
/// - Parameter seedRepresentation: The seed to use to generate the private key.
4848
///
49-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
49+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
5050
public init(seedRepresentation: some DataProtocol) throws {
5151
self.backing = try Backing(seedRepresentation: seedRepresentation)
5252
}
@@ -65,7 +65,7 @@ extension MLKEM768 {
6565
///
6666
/// - Parameter encapsulated: The encapsulated shared secret.
6767
///
68-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
68+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
6969
///
7070
/// - Returns: The symmetric key.
7171
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -104,7 +104,7 @@ extension MLKEM768 {
104104
///
105105
/// - Parameter seedRepresentation: The seed to use to generate the private key.
106106
///
107-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
107+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
108108
init(seedRepresentation: some DataProtocol) throws {
109109
guard seedRepresentation.count == MLKEM.seedByteCount else {
110110
throw CryptoKitError.incorrectKeySize
@@ -135,7 +135,7 @@ extension MLKEM768 {
135135
///
136136
/// - Parameter encapsulated: The encapsulated shared secret.
137137
///
138-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
138+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
139139
///
140140
/// - Returns: The symmetric key.
141141
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -184,7 +184,7 @@ extension MLKEM768 {
184184
///
185185
/// - Parameter rawRepresentation: The public key bytes.
186186
///
187-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
187+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
188188
public init(rawRepresentation: some DataProtocol) throws {
189189
self.backing = try Backing(rawRepresentation: rawRepresentation)
190190
}
@@ -216,7 +216,7 @@ extension MLKEM768 {
216216
///
217217
/// - Parameter rawRepresentation: The public key bytes.
218218
///
219-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
219+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
220220
init(rawRepresentation: some DataProtocol) throws {
221221
guard rawRepresentation.count == MLKEM768.PublicKey.byteCount else {
222222
throw CryptoKitError.incorrectKeySize
@@ -317,7 +317,7 @@ extension MLKEM1024 {
317317
///
318318
/// - Parameter seedRepresentation: The seed to use to generate the private key.
319319
///
320-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
320+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
321321
public init(seedRepresentation: some DataProtocol) throws {
322322
self.backing = try Backing(seedRepresentation: seedRepresentation)
323323
}
@@ -336,7 +336,7 @@ extension MLKEM1024 {
336336
///
337337
/// - Parameter encapsulated: The encapsulated shared secret.
338338
///
339-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
339+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
340340
///
341341
/// - Returns: The symmetric key.
342342
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -375,7 +375,7 @@ extension MLKEM1024 {
375375
///
376376
/// - Parameter seedRepresentation: The seed to use to generate the private key.
377377
///
378-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
378+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
379379
init(seedRepresentation: some DataProtocol) throws {
380380
guard seedRepresentation.count == MLKEM.seedByteCount else {
381381
throw CryptoKitError.incorrectKeySize
@@ -406,7 +406,7 @@ extension MLKEM1024 {
406406
///
407407
/// - Parameter encapsulated: The encapsulated shared secret.
408408
///
409-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
409+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
410410
///
411411
/// - Returns: The symmetric key.
412412
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -455,7 +455,7 @@ extension MLKEM1024 {
455455
///
456456
/// - Parameter rawRepresentation: The public key bytes.
457457
///
458-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
458+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
459459
public init(rawRepresentation: some DataProtocol) throws {
460460
self.backing = try Backing(rawRepresentation: rawRepresentation)
461461
}
@@ -487,7 +487,7 @@ extension MLKEM1024 {
487487
///
488488
/// - Parameter rawRepresentation: The public key bytes.
489489
///
490-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
490+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
491491
init(rawRepresentation: some DataProtocol) throws {
492492
guard rawRepresentation.count == MLKEM1024.PublicKey.byteCount else {
493493
throw CryptoKitError.incorrectKeySize

Sources/_CryptoExtras/MLKEM/MLKEM_boring.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension MLKEM${parameter_set} {
5050
///
5151
/// - Parameter seedRepresentation: The seed to use to generate the private key.
5252
///
53-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
53+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
5454
public init(seedRepresentation: some DataProtocol) throws {
5555
self.backing = try Backing(seedRepresentation: seedRepresentation)
5656
}
@@ -69,7 +69,7 @@ extension MLKEM${parameter_set} {
6969
///
7070
/// - Parameter encapsulated: The encapsulated shared secret.
7171
///
72-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
72+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
7373
///
7474
/// - Returns: The symmetric key.
7575
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -108,7 +108,7 @@ extension MLKEM${parameter_set} {
108108
///
109109
/// - Parameter seedRepresentation: The seed to use to generate the private key.
110110
///
111-
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
111+
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
112112
init(seedRepresentation: some DataProtocol) throws {
113113
guard seedRepresentation.count == MLKEM.seedByteCount else {
114114
throw CryptoKitError.incorrectKeySize
@@ -139,7 +139,7 @@ extension MLKEM${parameter_set} {
139139
///
140140
/// - Parameter encapsulated: The encapsulated shared secret.
141141
///
142-
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
142+
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
143143
///
144144
/// - Returns: The symmetric key.
145145
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
@@ -188,7 +188,7 @@ extension MLKEM${parameter_set} {
188188
///
189189
/// - Parameter rawRepresentation: The public key bytes.
190190
///
191-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
191+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
192192
public init(rawRepresentation: some DataProtocol) throws {
193193
self.backing = try Backing(rawRepresentation: rawRepresentation)
194194
}
@@ -220,7 +220,7 @@ extension MLKEM${parameter_set} {
220220
///
221221
/// - Parameter rawRepresentation: The public key bytes.
222222
///
223-
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
223+
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
224224
init(rawRepresentation: some DataProtocol) throws {
225225
guard rawRepresentation.count == MLKEM${parameter_set}.PublicKey.byteCount else {
226226
throw CryptoKitError.incorrectKeySize

Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ extension _RSA.BlindSigning.PublicKey {
495495
extension _RSA.BlindSigning {
496496
/// Errors defined in the RSA Blind Signatures protocol.
497497
///
498-
/// - NOTE: This type does not conform to `Swift.Error`, it is used to construct a `CryptoKitError`.
498+
/// - NOTE: This type does not conform to `Swift.Error`, it is used to construct a `CryptoError`.
499499
///
500500
/// - Seealso: [RFC 9474: Errors](https://www.rfc-editor.org/rfc/rfc9474.html#name-errors).
501501
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
@@ -512,7 +512,7 @@ extension _RSA.BlindSigning {
512512

513513
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
514514
extension CryptoKitError {
515-
/// Map an error from the RSA Blind Signatures protocol to a CryptoKitError.
515+
/// Map an error from the RSA Blind Signatures protocol to a CryptoError.
516516
init(_ error: _RSA.BlindSigning.ProtocolError) {
517517
switch error {
518518
case .messageTooLong:

0 commit comments

Comments
 (0)