Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update benchmarking + Support Android + add .swift-format + other refinements #227

Merged
merged 7 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
name: benchmark
on:
workflow_dispatch:
inputs:
sha:
type: string
required: true
description: "The commit SHA to run the benchmarks against."
push:
branches: [main]
pull_request_review:
types: [submitted]
pull_request:
branches: [main]
types: [synchronize]
paths:
- Sources/*.swift
- Benchmarks/
- .github/workflows/benchmark.yml

jobs:
benchmark:
if: github.run_attempt > 1 || github.event.review.state == 'approved' || startsWith(github.event_name, 'pull_request') != true
uses: vapor/ci/.github/workflows/run-benchmark.yml@main
with:
sha: ${{ inputs.sha }}
secrets: inherit
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ concurrency:
cancel-in-progress: true
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [ main ] }
push: { branches: [main] }

jobs:
jobs:
linux-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:jammy
steps:
container: swift:noble
steps:
- name: Check out JWTKit
uses: actions/checkout@v4
with:
Expand All @@ -34,5 +34,6 @@ jobs:
with_linting: true
with_windows: true
with_musl: true
with_android: true
ios_scheme_name: jwt-kit
secrets: inherit
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Packages
.build
.index-build
.DS_Store
*.xcodeproj
Package.pins
Expand Down
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For vscode users

"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineLength": 140,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"tabWidth": 4,
"version": 1
}
1 change: 1 addition & 0 deletions Benchmarks/.gitignore
1 change: 1 addition & 0 deletions Benchmarks/.swiftformat
6 changes: 3 additions & 3 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "JWTKit", package: "jwt-kit"),
],
path: "Benchmarks/Signing",
path: "Signing",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made these the same as multipart-kit

plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
Expand All @@ -29,7 +29,7 @@ let package = Package(
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "JWTKit", package: "jwt-kit"),
],
path: "Benchmarks/Verifying",
path: "Verifying",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
Expand All @@ -40,7 +40,7 @@ let package = Package(
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "JWTKit", package: "jwt-kit"),
],
path: "Benchmarks/TokenLifecycle",
path: "TokenLifecycle",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
Expand Down
4 changes: 2 additions & 2 deletions Snippets/JWKExamples.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import JWTKit

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

let rsaModulus = "..."
Expand Down
4 changes: 2 additions & 2 deletions Snippets/JWTKitExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import JWTKit

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

// Signs and verifies JWTs
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/Claims/ExpirationClaim.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !canImport(Darwin)
import FoundationEssentials
import FoundationEssentials
#else
import Foundation
import Foundation
#endif

/// The "exp" (expiration time) claim identifies the expiration time on
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/Claims/IssuedAtClaim.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !canImport(Darwin)
import FoundationEssentials
import FoundationEssentials
#else
import Foundation
import Foundation
#endif

/// The "iat" (issued at) claim identifies the time at which the JWT was
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/Claims/JWTMultiValueClaim.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !canImport(Darwin)
import FoundationEssentials
import FoundationEssentials
#else
import Foundation
import Foundation
#endif

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

public protocol JWTUnixEpochClaim: JWTClaim where Value == Date {}
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/Claims/LocaleClaim.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !canImport(Darwin)
import FoundationEssentials
import FoundationEssentials
#else
import Foundation
import Foundation
#endif

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

/// The "nbf" (not before) claim identifies the time before which the JWT
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/ECDSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Crypto
import X509

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

public enum ECDSA: Sendable {}
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/ECDSAKeyTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Crypto
import X509

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

/// A typealias representing the parameters of an ECDSA (Elliptic Curve Digital Signature Algorithm) key.
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/ECDSASigner.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !canImport(Darwin)
import FoundationEssentials
import FoundationEssentials
#else
import Foundation
import Foundation
#endif

struct ECDSASigner<Key: ECDSAKey>: JWTAlgorithm, CryptoSigner {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/P256+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/P384+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/ECDSA/P521+CurveType.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

// TODO: Remove @unchecked Sendable when Crypto is updated to use Sendable
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/EdDSA/EdDSA.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

/// Namespace for the EdDSA (Edwards-curve Digital Signature Algorithm) signing algorithm.
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/EdDSA/EdDSASigner.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

struct EdDSASigner: JWTAlgorithm, Sendable {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/EdDSA/JWTKeyCollection+EdDSA.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

extension JWTKeyCollection {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/HMAC/HMAC.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@preconcurrency import Crypto

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

public struct HMACKey: Sendable {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/HMAC/HMACSigner.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@preconcurrency import Crypto

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

struct HMACSigner<SHAType>: JWTAlgorithm where SHAType: HashFunction {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWTKit/HMAC/JWTKeyCollection+HMAC.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Crypto

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

extension JWTKeyCollection {
Expand Down
Loading
Loading