-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customizable JSON encoders and decoders (#95)
* Require SwiftCrypto 2.x, as we should been doing for a long time at this point * Add fully API-compatible ability to specify custom JSONEncoders and JSONDecoders for both the JWTSigners type and individual JWTSigner instances. * Enable using alternative JSON encoder/decoder implementations. Provide an integer date encoding/decoding strategy for the Foundation JSON coders (as apparently some JWT implementations insist on non-decimal dates despite the RFC) * Do a major overhaul of most of the README.
- Loading branch information
Showing
15 changed files
with
363 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
@_implementationOnly import CJWTKitBoringSSL | ||
import class Foundation.JSONEncoder | ||
import class Foundation.JSONDecoder | ||
|
||
extension JWTSigner { | ||
public static func es256(key: ECDSAKey) -> JWTSigner { | ||
return .init(algorithm: ECDSASigner( | ||
public static func es256(key: ECDSAKey) -> JWTSigner { .es256(key: key, jsonEncoder: nil, jsonDecoder: nil) } | ||
|
||
public static func es256(key: ECDSAKey, jsonEncoder: (any JWTJSONEncoder)?, jsonDecoder: (any JWTJSONDecoder)?) -> JWTSigner { | ||
.init(algorithm: ECDSASigner( | ||
key: key, | ||
algorithm: CJWTKitBoringSSL_EVP_sha256(), | ||
name: "ES256" | ||
)) | ||
), jsonEncoder: jsonEncoder, jsonDecoder: jsonDecoder) | ||
} | ||
|
||
public static func es384(key: ECDSAKey) -> JWTSigner { | ||
return .init(algorithm: ECDSASigner( | ||
public static func es384(key: ECDSAKey) -> JWTSigner { .es384(key: key, jsonEncoder: nil, jsonDecoder: nil) } | ||
|
||
public static func es384(key: ECDSAKey, jsonEncoder: (any JWTJSONEncoder)?, jsonDecoder: (any JWTJSONDecoder)?) -> JWTSigner { | ||
.init(algorithm: ECDSASigner( | ||
key: key, | ||
algorithm: CJWTKitBoringSSL_EVP_sha384(), | ||
name: "ES384" | ||
)) | ||
), jsonEncoder: jsonEncoder, jsonDecoder: jsonDecoder) | ||
} | ||
|
||
public static func es512(key: ECDSAKey) -> JWTSigner { | ||
return .init(algorithm: ECDSASigner( | ||
public static func es512(key: ECDSAKey) -> JWTSigner { .es512(key: key, jsonEncoder: nil, jsonDecoder: nil) } | ||
|
||
public static func es512(key: ECDSAKey, jsonEncoder: (any JWTJSONEncoder)?, jsonDecoder: (any JWTJSONDecoder)?) -> JWTSigner { | ||
.init(algorithm: ECDSASigner( | ||
key: key, | ||
algorithm: CJWTKitBoringSSL_EVP_sha512(), | ||
name: "ES512" | ||
)) | ||
), jsonEncoder: jsonEncoder, jsonDecoder: jsonDecoder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.