File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,15 @@ extension DataProtocol {
1919 func base64URLEncodedString( ) -> String {
2020 Data ( self )
2121 . base64EncodedString ( )
22- . replacingOccurrences ( of: " + " , with: " - " )
22+ . transformToBase64URLEncoding ( )
23+ }
24+ }
25+
26+ extension String {
27+ /// Transform a regular Base64 encoded string to a Base64URL encoded one.
28+ @usableFromInline
29+ func transformToBase64URLEncoding( ) -> String {
30+ self . replacingOccurrences ( of: " + " , with: " - " )
2331 . replacingOccurrences ( of: " / " , with: " _ " )
2432 . replacingOccurrences ( of: " = " , with: " " )
2533 }
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ extension VAPID.Key: Identifiable {
8686
8787 public init ( from decoder: any Decoder ) throws {
8888 let container = try decoder. singleValueContainer ( )
89- self . rawValue = try container. decode ( String . self)
89+ self . rawValue = try container. decode ( String . self) . transformToBase64URLEncoding ( )
9090 }
9191
9292 public func encode( to encoder: any Encoder ) throws {
You can’t perform that action at this time.
0 commit comments