Skip to content

Commit 70e9c03

Browse files
Fixed an issue where Base64-encoded key IDs would fail lookups against the known set of keys
Fixes #65
1 parent c938198 commit 70e9c03

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

Sources/WebPush/VAPID/VAPIDKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)