Skip to content

Commit

Permalink
Move to FoundationEssentials
Browse files Browse the repository at this point in the history
  • Loading branch information
ptoffy committed Oct 4, 2024
1 parent edaa7f5 commit d6c451e
Show file tree
Hide file tree
Showing 44 changed files with 246 additions and 44 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that
You can add this JSON Web Key Set (JWKS) to your `JWTSigners`:

```swift
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif
import JWTKit

let rsaModulus = "..."
Expand Down
7 changes: 6 additions & 1 deletion Snippets/JWKExamples.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation
import JWTKit

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

let rsaModulus = "..."

let json = """
Expand Down
7 changes: 6 additions & 1 deletion Snippets/JWTKitExamples.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Foundation
// snippet.KEY_COLLECTION
import JWTKit

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

// Signs and verifies JWTs
let keys = JWTKeyCollection()

Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/ExpirationClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// The "exp" (expiration time) claim identifies the expiration time on
/// or after which the JWT MUST NOT be accepted for processing. The
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/IssuedAtClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// The "iat" (issued at) claim identifies the time at which the JWT was
/// issued. This claim can be used to determine the age of the JWT. Its
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/JWTMultiValueClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public protocol JWTMultiValueClaim: JWTClaim where Value: Collection, Value.Element: Codable {
init(value: Value.Element)
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/JWTUnixEpochClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public protocol JWTUnixEpochClaim: JWTClaim where Value == Date {}

Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/LocaleClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public struct LocaleClaim: JWTClaim, Equatable, ExpressibleByStringLiteral {
/// See ``JWTClaim``.
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Claims/NotBeforeClaim.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// The "nbf" (not before) claim identifies the time before which the JWT
/// MUST NOT be accepted for processing. The processing of the "nbf"
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/ECDSA/ECDSA.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Crypto
import Foundation
import X509

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public enum ECDSA: Sendable {}

public protocol ECDSAKey: Sendable {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/ECDSA/ECDSAKeyTypes.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Crypto
import Foundation
import X509

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// A typealias representing the parameters of an ECDSA (Elliptic Curve Digital Signature Algorithm) key.
///
/// This tuple consists of two strings representing the x and y coordinates on the elliptic curve.
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/ECDSA/ECDSASigner.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

struct ECDSASigner<Key: ECDSAKey>: JWTAlgorithm, CryptoSigner {
let privateKey: ECDSA.PrivateKey<Key.Curve>?
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/ECDSA/P256+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
extension P256: ECDSACurveType {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/ECDSA/P384+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
extension P384: ECDSACurveType {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/ECDSA/P521+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
extension P521: ECDSACurveType {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/EdDSA/EdDSA.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// Namespace for the EdDSA (Edwards-curve Digital Signature Algorithm) signing algorithm.
/// EdDSA is a modern signing algorithm that is efficient and fast.
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/EdDSA/EdDSASigner.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

struct EdDSASigner: JWTAlgorithm, Sendable {
let publicKey: EdDSA.PublicKey
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/EdDSA/JWTKeyCollection+EdDSA.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

extension JWTKeyCollection {
/// Adds an EdDSA key to the collection using an ``EdDSAKey``.
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/HMAC/HMAC.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@preconcurrency import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public struct HMACKey: Sendable {
let key: SymmetricKey
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/HMAC/HMACSigner.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@preconcurrency import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

struct HMACSigner<SHAType>: JWTAlgorithm where SHAType: HashFunction {
let key: SymmetricKey
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/HMAC/JWTKeyCollection+HMAC.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

extension JWTKeyCollection {
/// Adds an HMAC key to the collection.
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/JWTAlgorithm.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// A protocol defining the necessary functionality for a JWT (JSON Web Token) algorithm.
/// All algorithms conform to ``JWTAlgorithm`` to provide custom signing and verification logic for JWT tokens.
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/JWTError.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// JWT error type.
public struct JWTError: Error, Sendable, Equatable {
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/JWTHeaderField.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public indirect enum JWTHeaderField: Hashable, Sendable, Codable {
case null
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/JWTKeyCollection.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation
import Logging

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// A collection of JWT and JWK signers for handling JSON Web Tokens (JWTs).
///
/// This actor provides methods to manage multiple keys. It can be used to verify and decode JWTs, as well as to sign and encode JWTs.
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/JWTParser.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public protocol JWTParser: Sendable {
var jsonDecoder: JWTJSONDecoder { get set }
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/JWTSerializer.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation
import X509

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public protocol JWTSerializer: Sendable {
var jsonEncoder: any JWTJSONEncoder { get }
func serialize(_ payload: some JWTPayload, header: JWTHeader) throws -> Data
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/JWTSigner.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

/// A JWT signer.
final class JWTSigner: Sendable {
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/None/UnsecuredNoneSigner.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

struct UnsecuredNoneSigner: JWTAlgorithm {
var name: String {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/RSA/RSA.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Crypto
import Foundation
import X509
import _CryptoExtras

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

extension Insecure {
/// Namespace encompassing functionality related to the RSA (Rivest–Shamir–Adleman) cryptographic algorithm.
/// Relatively to other algorithms such as ECDSA and EdDSA, RSA is considered slow and should be avoided when possible.
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/RSA/RSASigner.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation
import _CryptoExtras

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

struct RSASigner: JWTAlgorithm, CryptoSigner {
let publicKey: Insecure.RSA.PublicKey
let privateKey: Insecure.RSA.PrivateKey?
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Utilities/Base64URL.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

extension String {
package func base64URLDecodedData() -> Data? {
Expand Down
7 changes: 6 additions & 1 deletion Sources/JWTKit/Utilities/CryptoSigner.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Crypto
import Foundation

#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public struct DigestAlgorithm: Sendable, Equatable {
enum Backing {
Expand Down
6 changes: 5 additions & 1 deletion Sources/JWTKit/Utilities/CustomizedJSONCoders.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
#if !canImport(Darwin)
import FoundationEssentials
#else
import Foundation
#endif

public protocol JWTJSONDecoder: Sendable {
func decode<T: Decodable>(_: T.Type, from string: Data) throws -> T
Expand Down
Loading

0 comments on commit d6c451e

Please sign in to comment.