Skip to content

Commit 6cd19a1

Browse files
authored
Finally remove @retroactive @unchecked Sendable from crypto types (#232)
* Remove retroactive Sendable conf * Remove comments * Update crypto version * Format * Fix test warnings * Use from syntax
1 parent 2033b3e commit 6cd19a1

File tree

11 files changed

+25
-43
lines changed

11 files changed

+25
-43
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ let package = Package(
1313
.library(name: "JWTKit", targets: ["JWTKit"])
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/apple/swift-crypto.git", "3.8.0"..<"5.0.0"),
17-
.package(url: "https://github.com/apple/swift-certificates.git", from: "1.2.0"),
16+
.package(url: "https://github.com/apple/swift-crypto.git", from: "4.0.0"),
17+
.package(url: "https://github.com/apple/swift-certificates.git", from: "1.15.0"),
1818
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
1919
],
2020
targets: [
2121
.target(
2222
name: "JWTKit",
2323
dependencies: [
2424
.product(name: "Crypto", package: "swift-crypto"),
25-
.product(name: "_CryptoExtras", package: "swift-crypto"),
25+
.product(name: "CryptoExtras", package: "swift-crypto"),
2626
.product(name: "X509", package: "swift-certificates"),
2727
.product(name: "Logging", package: "swift-log"),
2828
]

Sources/JWTKit/ECDSA/P256+CurveType.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import FoundationEssentials
66
import Foundation
77
#endif
88

9-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
109
extension P256: ECDSACurveType {
1110
public typealias Signature = P256.Signing.ECDSASignature
1211
public typealias PrivateKey = P256.Signing.PrivateKey
@@ -28,7 +27,6 @@ extension P256: ECDSACurveType {
2827
}
2928
}
3029

31-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
3230
extension P256.Signing.PublicKey: ECDSAPublicKey {
3331
/// Verifies that the P256 key signature is valid for the given digest.
3432
///
@@ -43,11 +41,8 @@ extension P256.Signing.PublicKey: ECDSAPublicKey {
4341
}
4442
}
4543

46-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
47-
extension P256.Signing.PrivateKey: ECDSAPrivateKey, @unchecked @retroactive Sendable {}
48-
extension P256.Signing.ECDSASignature: ECDSASignature, @unchecked @retroactive Sendable {}
49-
extension P256.Signing.PublicKey: @unchecked @retroactive Sendable {}
50-
extension P256: @unchecked @retroactive Sendable {}
44+
extension P256.Signing.PrivateKey: ECDSAPrivateKey {}
45+
extension P256.Signing.ECDSASignature: ECDSASignature {}
5146

5247
public typealias ES256PublicKey = ECDSA.PublicKey<P256>
5348
public typealias ES256PrivateKey = ECDSA.PrivateKey<P256>

Sources/JWTKit/ECDSA/P384+CurveType.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import FoundationEssentials
66
import Foundation
77
#endif
88

9-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
109
extension P384: ECDSACurveType {
1110
public typealias Signature = P384.Signing.ECDSASignature
1211
public typealias PrivateKey = P384.Signing.PrivateKey
@@ -28,7 +27,6 @@ extension P384: ECDSACurveType {
2827
}
2928
}
3029

31-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
3230
extension P384.Signing.PublicKey: ECDSAPublicKey {
3331
/// Verifies that the P384 key signature is valid for the given digest.
3432
///
@@ -43,11 +41,8 @@ extension P384.Signing.PublicKey: ECDSAPublicKey {
4341
}
4442
}
4543

46-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
47-
extension P384.Signing.PrivateKey: ECDSAPrivateKey, @unchecked @retroactive Sendable {}
48-
extension P384.Signing.ECDSASignature: ECDSASignature, @unchecked @retroactive Sendable {}
49-
extension P384.Signing.PublicKey: @unchecked @retroactive Sendable {}
50-
extension P384: @unchecked @retroactive Sendable {}
44+
extension P384.Signing.PrivateKey: ECDSAPrivateKey {}
45+
extension P384.Signing.ECDSASignature: ECDSASignature {}
5146

5247
public typealias ES384PublicKey = ECDSA.PublicKey<P384>
5348
public typealias ES384PrivateKey = ECDSA.PrivateKey<P384>

Sources/JWTKit/ECDSA/P521+CurveType.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import FoundationEssentials
66
import Foundation
77
#endif
88

9-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
109
extension P521: ECDSACurveType {
1110
public typealias Signature = P521.Signing.ECDSASignature
1211
public typealias PrivateKey = P521.Signing.PrivateKey
@@ -29,7 +28,6 @@ extension P521: ECDSACurveType {
2928
}
3029
}
3130

32-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
3331
extension P521.Signing.PublicKey: ECDSAPublicKey {
3432
/// Verifies that the P256 key signature is valid for the given digest.
3533
///
@@ -44,10 +42,8 @@ extension P521.Signing.PublicKey: ECDSAPublicKey {
4442
}
4543
}
4644

47-
extension P521.Signing.PrivateKey: ECDSAPrivateKey, @unchecked @retroactive Sendable {}
48-
extension P521.Signing.ECDSASignature: ECDSASignature, @unchecked @retroactive Sendable {}
49-
extension P521.Signing.PublicKey: @unchecked @retroactive Sendable {}
50-
extension P521: @unchecked @retroactive Sendable {}
45+
extension P521.Signing.PrivateKey: ECDSAPrivateKey {}
46+
extension P521.Signing.ECDSASignature: ECDSASignature {}
5147

5248
public typealias ES512PublicKey = ECDSA.PublicKey<P521>
5349
public typealias ES512PrivateKey = ECDSA.PrivateKey<P521>

Sources/JWTKit/EdDSA/EdDSA.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,3 @@ extension EdDSA {
141141
}
142142
}
143143
}
144-
145-
// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
146-
extension Curve25519.Signing.PublicKey: @unchecked @retroactive Sendable {}
147-
extension Curve25519.Signing.PrivateKey: @unchecked @retroactive Sendable {}

Sources/JWTKit/RSA/JWTKeyCollection+RSA.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _CryptoExtras
1+
import CryptoExtras
22

33
extension JWTKeyCollection {
44
/// Adds an RSA key to the collection.

Sources/JWTKit/RSA/RSA.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Crypto
2+
import CryptoExtras
23
import X509
3-
import _CryptoExtras
44

55
#if !canImport(Darwin)
66
import FoundationEssentials

Sources/JWTKit/RSA/RSASigner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _CryptoExtras
1+
import CryptoExtras
22

33
#if !canImport(Darwin)
44
import FoundationEssentials

Sources/JWTKit/X5C/X5CVerifier.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import X509
1+
@_spi(FixedExpiryValidationTime) import X509
22

33
#if !canImport(Darwin)
44
import FoundationEssentials
@@ -60,8 +60,8 @@ public struct X5CVerifier: Sendable {
6060
/// - Returns: A `X509.VerificationResult` indicating the result of the verification.
6161
public func verifyChain(
6262
certificates: [String],
63-
policy: () throws -> some VerifierPolicy = { RFC5280Policy(validationTime: Date()) }
64-
) async throws -> X509.VerificationResult {
63+
policy: () throws -> some VerifierPolicy = { RFC5280Policy() }
64+
) async throws -> X509.CertificateValidationResult {
6565
let certificates = try certificates.map { try Certificate(pemEncoded: $0) }
6666
return try await verifyChain(certificates: certificates, policy: policy)
6767
}
@@ -74,12 +74,12 @@ public struct X5CVerifier: Sendable {
7474
/// - Returns: A `X509.VerificationResult` indicating the result of the verification.
7575
public func verifyChain(
7676
certificates: [Certificate],
77-
@PolicyBuilder policy: () throws -> some VerifierPolicy = { RFC5280Policy(validationTime: Date()) }
78-
) async throws -> X509.VerificationResult {
77+
@PolicyBuilder policy: () throws -> some VerifierPolicy = { RFC5280Policy() }
78+
) async throws -> X509.CertificateValidationResult {
7979
let untrustedChain = CertificateStore(certificates)
8080
var verifier = try Verifier(rootCertificates: trustedStore, policy: policy)
8181
let result = await verifier.validate(
82-
leafCertificate: certificates[0], intermediates: untrustedChain)
82+
leaf: certificates[0], intermediates: untrustedChain)
8383
return result
8484
}
8585

@@ -141,7 +141,7 @@ public struct X5CVerifier: Sendable {
141141
_ token: some DataProtocol,
142142
as _: Payload.Type = Payload.self,
143143
jsonDecoder: any JWTJSONDecoder,
144-
@PolicyBuilder policy: () throws -> some VerifierPolicy = { RFC5280Policy(validationTime: Date()) }
144+
@PolicyBuilder policy: () throws -> some VerifierPolicy = { RFC5280Policy() }
145145
) async throws -> Payload
146146
where Payload: JWTPayload {
147147
// Parse the JWS header to get the header
@@ -187,12 +187,12 @@ public struct X5CVerifier: Sendable {
187187
rootCertificates: trustedStore,
188188
policy: {
189189
try policy()
190-
RFC5280Policy(validationTime: date)
190+
RFC5280Policy(fixedExpiryValidationTime: date)
191191
})
192192

193193
// Validate the leaf certificate against the trusted store
194194
let result = await verifier.validate(
195-
leafCertificate: certificates[0],
195+
leaf: certificates[0],
196196
intermediates: untrustedChain
197197
)
198198

Tests/JWTKitTests/RSATests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if canImport(Testing)
22
import Testing
33
import JWTKit
4-
import _CryptoExtras
4+
import CryptoExtras
55

66
@Suite("RSA Tests")
77
struct RSATests {

0 commit comments

Comments
 (0)