Skip to content

Commit

Permalink
fix: Force JWS/JWE string conversion to use compact representation
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed Feb 29, 2024
1 parent eb94a1d commit e1bd8df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/JWSETKit/Entities/JWE/JWE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ public struct JSONWebEncryption: Hashable, Sendable {

extension String {
public init(jwe: JSONWebEncryption) throws {
self = try String(String(decoding: JSONEncoder.encoder.encode(jwe), as: UTF8.self).dropFirst().dropLast())
var encoder = JSONEncoder.encoder
encoder.userInfo[.jwsEncodedRepresentation] = JSONWebEncryptionRepresentation.compact
self = try String(String(decoding: encoder.encode(jwe), as: UTF8.self).dropFirst().dropLast())
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/JWSETKit/Entities/JWS/JWS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public struct JSONWebSignature<Payload: ProtectedWebContainer>: Hashable, Sendab

extension String {
public init<Payload: ProtectedWebContainer>(jws: JSONWebSignature<Payload>) throws {
self = try String(String(decoding: JSONEncoder.encoder.encode(jws), as: UTF8.self).dropFirst().dropLast())
var encoder = JSONEncoder.encoder
encoder.userInfo[.jwsEncodedRepresentation] = JSONWebSignatureRepresentation.compact
self = try String(String(decoding: encoder.encode(jws), as: UTF8.self).dropFirst().dropLast())
}
}

Expand Down

0 comments on commit e1bd8df

Please sign in to comment.