Skip to content

Commit

Permalink
fix: change api so there is no confusion with swift compiler
Browse files Browse the repository at this point in the history
This commit also makes a forgotten init of AudienceClaim as public
  • Loading branch information
beatt83 committed Jun 3, 2024
1 parent 1e90155 commit fce2fab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sources/JSONWebToken/Claims/AudienceClaim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct AudienceClaim: JWTRegisteredClaim {

/// Initializes an `AudienceClaim` with an array of audience values using a result builder.
/// - Parameter claims: A closure that returns an array of `StringClaim` using the result builder.
init(@ArrayClaim.ArrayClaimBuilder claims: () -> [StringClaim]) {
public init(@ArrayClaim.ArrayClaimBuilder claims: () -> [StringClaim]) {
self.value = .init(key: "aud", element: .array(claims().map(\.value)))
}
}
8 changes: 4 additions & 4 deletions Sources/JSONWebToken/JWT+Encryption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension JWT {
P: JWERegisteredFieldsHeader,
U: JWERegisteredFieldsHeader
>(
@JWTClaimsBuilder payload: () -> Claim,
@JWTClaimsBuilder claims: () -> Claim,
protectedHeader: P,
unprotectedHeader: U? = nil as DefaultJWEHeaderImpl?,
senderKey: KeyRepresentable?,
Expand All @@ -91,7 +91,7 @@ extension JWT {
if protectedHeader.type == nil {
protectedHeader.type = "JWT"
}
let encodedPayload = try JSONEncoder.jwt.encode(payload().value)
let encodedPayload = try JSONEncoder.jwt.encode(claims().value)
return JWT(
payload: encodedPayload,
format: .jwe(try JWE(
Expand Down Expand Up @@ -243,7 +243,7 @@ extension JWT {
NP: JWERegisteredFieldsHeader,
NU: JWERegisteredFieldsHeader
>(
@JWTClaimsBuilder payload: () -> Claim,
@JWTClaimsBuilder claims: () -> Claim,
protectedHeader: P,
unprotectedHeader: U? = nil as DefaultJWEHeaderImpl?,
senderKey: KeyRepresentable? = nil,
Expand All @@ -262,7 +262,7 @@ extension JWT {
nestedAdditionalAuthenticationData: Data? = nil
) throws -> JWE {
let jwt = try encrypt(
payload: payload,
claims: claims,
protectedHeader: nestedProtectedHeader,
unprotectedHeader: nestedUnprotectedHeader,
senderKey: nestedSenderKey,
Expand Down
8 changes: 4 additions & 4 deletions Sources/JSONWebToken/JWT+Signing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ extension JWT {
/// - Throws: An error if the signing process or encoding fails.
/// - Returns: A `JWT` instance in JWS format with the signed claims.
public static func signed<P: JWSRegisteredFieldsHeader, Key>(
@JWTClaimsBuilder payload: () -> Claim,
@JWTClaimsBuilder claims: () -> Claim,
protectedHeader: P,
key: Key?
) throws -> JWT {
var protectedHeader = protectedHeader
if protectedHeader.type == nil {
protectedHeader.type = "JWT"
}
let encodedPayload = try JSONEncoder.jwt.encode(payload().value)
let encodedPayload = try JSONEncoder.jwt.encode(claims().value)
return JWT(
payload: encodedPayload,
format: .jws(try JWS(
Expand Down Expand Up @@ -145,14 +145,14 @@ extension JWT {
P: JWSRegisteredFieldsHeader,
NP: JWSRegisteredFieldsHeader
>(
@JWTClaimsBuilder payload: () -> Claim,
@JWTClaimsBuilder claims: () -> Claim,
protectedHeader: P,
key: KeyRepresentable?,
nestedProtectedHeader: NP,
nestedKey: KeyRepresentable?
) throws -> JWS {
let jwt = try signed(
payload: payload,
claims: claims,
protectedHeader: nestedProtectedHeader,
key: nestedKey
)
Expand Down

0 comments on commit fce2fab

Please sign in to comment.