Skip to content

Commit 5194f38

Browse files
Improved URL decoding to inline as needed and remove duplicate code
1 parent 7ccc1c6 commit 5194f38

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010

1111
extension DataProtocol {
1212
@_disfavoredOverload
13+
@usableFromInline
1314
func base64URLEncodedString() -> String {
1415
Data(self)
1516
.base64EncodedString()
@@ -20,18 +21,16 @@ extension DataProtocol {
2021
}
2122

2223
extension ContiguousBytes {
24+
@usableFromInline
2325
func base64URLEncodedString() -> String {
2426
withUnsafeBytes { bytes in
25-
Data(bytes)
26-
.base64EncodedString()
27-
.replacingOccurrences(of: "+", with: "-")
28-
.replacingOccurrences(of: "/", with: "_")
29-
.replacingOccurrences(of: "=", with: "")
27+
(bytes as any DataProtocol).base64URLEncodedString()
3028
}
3129
}
3230
}
3331

3432
extension DataProtocol where Self: RangeReplaceableCollection {
33+
@usableFromInline
3534
init?(base64URLEncoded string: some StringProtocol) {
3635
var base64String = string.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
3736
while base64String.count % 4 != 0 {

0 commit comments

Comments
 (0)