Repository: vapor/jwt-kit (swift)

Issue:
Rename JWK/s KeyCollection APIs 
All of the algorithms use the `add` API to add keys to the key collection. The JWK and JWKS are still using the old `use`. We should update those

Pull request:
Fix #186 

Also updates README

Patch:
diff --git a/README.md b/README.md
index c2674de8..1289e637 100644
--- a/README.md
+++ b/README.md
@@ -18,18 +18,12 @@
 
 🔑 JSON Web Token signing and verification (HMAC, RSA, PSS, ECDSA, EdDSA) using SwiftCrypto.
 
-### Major Releases
-
-The table below shows a list of JWTKit major releases alongside their compatible Swift versions. 
-
-|Version|Swift|SPM|
-|---|---|---|
-|5.0|5.10+|`from: "5.0.0"`|
+### Getting Started
 
 Use the SPM string to easily include the dependendency in your `Package.swift` file
 
 ```swift
-.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0-beta.4")
+.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0-beta.rc")
 ```
 
 and add it to your target's dependencies:
@@ -200,7 +194,7 @@ let json = """
 """
 
 // Create key collection and add JWKS
-let keys = try await JWTKeyCollection().use(jwksJSON: json)
+let keys = try await JWTKeyCollection().add(jwksJSON: json)
 ```
 
 You can now pass JWTs from Apple to the `verify` method. The key identifier (`kid`) in the JWT header will be used to automatically select the correct key for verification. A JWKS may contain any of the key types supported by JWTKit.  
diff --git a/Snippets/JWKExamples.swift b/Snippets/JWKExamples.swift
index 152ddf2d..d2c40e5e 100644
--- a/Snippets/JWKExamples.swift
+++ b/Snippets/JWKExamples.swift
@@ -13,4 +13,4 @@ let json = """
 """
 
 // Create key collection and add JWKS
-let keys = try await JWTKeyCollection().use(jwksJSON: json)
+let keys = try await JWTKeyCollection().add(jwksJSON: json)
diff --git a/Sources/JWTKit/JWTKeyCollection.swift b/Sources/JWTKit/JWTKeyCollection.swift
index 4f3a4265..8d3658ab 100644
--- a/Sources/JWTKit/JWTKeyCollection.swift
+++ b/Sources/JWTKit/JWTKeyCollection.swift
@@ -70,7 +70,7 @@ public actor JWTKeyCollection: Sendable {
     /// - Throws: An error if the JSON string cannot be decoded into a `JWKS` instance.
     /// - Returns: Self for chaining.
     @discardableResult
-    public func use(jwksJSON json: String) throws -> Self {
+    public func add(jwksJSON json: String) throws -> Self {
         let jwks = try self.defaultJWTParser.jsonDecoder.decode(JWKS.self, from: Data(json.utf8))
         return try self.add(jwks: jwks)
     }


Test patch:
diff --git a/Tests/JWTKitTests/ECDSATests.swift b/Tests/JWTKitTests/ECDSATests.swift
index c8d9a430..03e471b8 100644
--- a/Tests/JWTKitTests/ECDSATests.swift
+++ b/Tests/JWTKitTests/ECDSATests.swift
@@ -111,7 +111,7 @@ final class ECDSATests: XCTestCase {
         }
         """
 
-        try await keys.use(jwksJSON: jwksString)
+        try await keys.add(jwksJSON: jwksString)
         let foo = try await keys.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
@@ -150,7 +150,7 @@ final class ECDSATests: XCTestCase {
         }
         """
 
-        try await keys.use(jwksJSON: jwksString)
+        try await keys.add(jwksJSON: jwksString)
         let foo = try await keys.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
@@ -189,7 +189,7 @@ final class ECDSATests: XCTestCase {
         }
         """
 
-        try await keys.use(jwksJSON: jwksString)
+        try await keys.add(jwksJSON: jwksString)
         let foo = try await keys.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
@@ -201,8 +201,8 @@ final class ECDSATests: XCTestCase {
         struct Payload: JWTPayload {
             let foo: String
             func verify(using _: some JWTAlgorithm) throws {
-                guard foo == "bar" else {
-                    throw NotBar(foo: foo)
+                guard self.foo == "bar" else {
+                    throw NotBar(foo: self.foo)
                 }
             }
         }
diff --git a/Tests/JWTKitTests/EdDSATests.swift b/Tests/JWTKitTests/EdDSATests.swift
index 1629a086..83c040bb 100644
--- a/Tests/JWTKitTests/EdDSATests.swift
+++ b/Tests/JWTKitTests/EdDSATests.swift
@@ -67,7 +67,7 @@ final class EdDSATests: XCTestCase {
         }
         """
 
-        try await keyCollection.use(jwksJSON: jwksString)
+        try await keyCollection.add(jwksJSON: jwksString)
         let foo = try await keyCollection.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
@@ -104,7 +104,7 @@ final class EdDSATests: XCTestCase {
         }
         """
 
-        try await keyCollection.use(jwksJSON: jwksString)
+        try await keyCollection.add(jwksJSON: jwksString)
         let foo = try await keyCollection.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
@@ -141,7 +141,7 @@ final class EdDSATests: XCTestCase {
         }
         """
 
-        try await keyCollection.use(jwksJSON: jwksString)
+        try await keyCollection.add(jwksJSON: jwksString)
         let foo = try await keyCollection.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
diff --git a/Tests/JWTKitTests/JWTKitTests.swift b/Tests/JWTKitTests/JWTKitTests.swift
index b5a8fd93..dd848090 100644
--- a/Tests/JWTKitTests/JWTKitTests.swift
+++ b/Tests/JWTKitTests/JWTKitTests.swift
@@ -31,7 +31,7 @@ class JWTKitTests: XCTestCase {
             // Since we have an ExpirationClaim, we will
             // call its verify method.
             func verify(using _: some JWTAlgorithm) throws {
-                try expiration.verifyNotExpired()
+                try self.expiration.verifyNotExpired()
             }
         }
 
@@ -210,7 +210,7 @@ class JWTKitTests: XCTestCase {
         }
         """
 
-        let keyCollection = try await JWTKeyCollection().use(jwksJSON: json)
+        let keyCollection = try await JWTKeyCollection().add(jwksJSON: json)
 
         await XCTAssertNoThrowAsync(try await keyCollection.getKey())
         let a: JWTAlgorithm, b: JWTAlgorithm
@@ -238,8 +238,8 @@ class JWTKitTests: XCTestCase {
         struct Payload: JWTPayload {
             let foo: String
             func verify(using _: some JWTAlgorithm) throws {
-                guard foo == "bar" else {
-                    throw NotBar(foo: foo)
+                guard self.foo == "bar" else {
+                    throw NotBar(foo: self.foo)
                 }
             }
         }
@@ -295,13 +295,13 @@ class JWTKitTests: XCTestCase {
         }
         """
 
-        try await keyCollection.use(jwksJSON: jwksString)
+        try await keyCollection.add(jwksJSON: jwksString)
         let foo = try await keyCollection.verify(jwt, as: Foo.self)
         XCTAssertEqual(foo.bar, 42)
     }
 
     func testMicrosoftJWKs() async throws {
-        await XCTAssertNoThrowAsync(try await JWTKeyCollection().use(jwksJSON: microsoftJWKS))
+        await XCTAssertNoThrowAsync(try await JWTKeyCollection().add(jwksJSON: microsoftJWKS))
     }
 
     func testFirebaseJWTAndCertificate() async throws {
@@ -351,9 +351,9 @@ class JWTKitTests: XCTestCase {
 
             func serialize(_ payload: some JWTPayload, header: JWTHeader) throws -> Data {
                 if header.b64?.asBool == true {
-                    try Data(jsonEncoder.encode(payload).base64URLEncodedBytes())
+                    try Data(self.jsonEncoder.encode(payload).base64URLEncodedBytes())
                 } else {
-                    try jsonEncoder.encode(payload)
+                    try self.jsonEncoder.encode(payload)
                 }
             }
         }
@@ -367,9 +367,9 @@ class JWTKitTests: XCTestCase {
                 let header = try jsonDecoder.decode(JWTHeader.self, from: .init(encodedHeader.base64URLDecodedBytes()))
 
                 let payload = if header.b64?.asBool ?? true {
-                    try jsonDecoder.decode(Payload.self, from: .init(encodedPayload.base64URLDecodedBytes()))
+                    try self.jsonDecoder.decode(Payload.self, from: .init(encodedPayload.base64URLDecodedBytes()))
                 } else {
-                    try jsonDecoder.decode(Payload.self, from: .init(encodedPayload))
+                    try self.jsonDecoder.decode(Payload.self, from: .init(encodedPayload))
                 }
 
                 let signature = Data(encodedSignature.base64URLDecodedBytes())
@@ -636,7 +636,7 @@ struct ExpirationPayload: JWTPayload {
     var exp: ExpirationClaim
 
     func verify(using _: some JWTAlgorithm) throws {
-        try exp.verifyNotExpired()
+        try self.exp.verifyNotExpired()
     }
 }
 
@@ -710,7 +710,7 @@ struct FirebasePayload: JWTPayload, Equatable {
     let expiration: ExpirationClaim
 
     func verify(using _: some JWTAlgorithm) throws {
-        try expiration.verifyNotExpired(currentDate: .distantPast)
+        try self.expiration.verifyNotExpired(currentDate: .distantPast)
     }
 }