@@ -38,7 +38,7 @@ public struct EncodedBase64: ExpressibleByStringLiteral, Codable, Hashable, Equa
38
38
39
39
/// Return as Base64URL
40
40
public var urlEncoded : URLEncodedBase64 {
41
- return . init (
41
+ URLEncodedBase64 (
42
42
self . base64. replacingOccurrences ( of: " + " , with: " - " )
43
43
. replacingOccurrences ( of: " / " , with: " _ " )
44
44
. replacingOccurrences ( of: " = " , with: " " )
@@ -47,12 +47,12 @@ public struct EncodedBase64: ExpressibleByStringLiteral, Codable, Hashable, Equa
47
47
48
48
/// Decodes Base64 string and transforms result into `Data`
49
49
public var decoded : Data ? {
50
- return Data ( base64Encoded: self . base64)
50
+ Data ( base64Encoded: self . base64)
51
51
}
52
52
53
53
/// Returns Base64 data as a String
54
54
public func asString( ) -> String {
55
- return self . base64
55
+ self . base64
56
56
}
57
57
}
58
58
@@ -74,12 +74,12 @@ public struct URLEncodedBase64: ExpressibleByStringLiteral, Codable, Hashable, E
74
74
self . init ( value)
75
75
}
76
76
77
- public init ( from decoder: Decoder ) throws {
77
+ public init ( from decoder: any Decoder ) throws {
78
78
let container = try decoder. singleValueContainer ( )
79
79
self . base64URL = try container. decode ( String . self)
80
80
}
81
81
82
- public func encode( to encoder: Encoder ) throws {
82
+ public func encode( to encoder: any Encoder ) throws {
83
83
var container = encoder. singleValueContainer ( )
84
84
try container. encode ( self . base64URL)
85
85
}
@@ -90,12 +90,12 @@ public struct URLEncodedBase64: ExpressibleByStringLiteral, Codable, Hashable, E
90
90
while result. count % 4 != 0 {
91
91
result = result. appending ( " = " )
92
92
}
93
- return . init ( result)
93
+ return EncodedBase64 ( result)
94
94
}
95
95
96
96
/// Return Base64URL as a String
97
97
public func asString( ) -> String {
98
- return self . base64URL
98
+ self . base64URL
99
99
}
100
100
}
101
101
@@ -110,20 +110,20 @@ extension Array where Element == UInt8 {
110
110
/// Encodes an array of bytes into a base64 string
111
111
/// - Returns: A base64-encoded string
112
112
public func base64EncodedString( ) -> EncodedBase64 {
113
- return . init ( Data ( bytes: self , count: self . count) . base64EncodedString ( ) )
113
+ EncodedBase64 ( Data ( bytes: self , count: self . count) . base64EncodedString ( ) )
114
114
}
115
115
}
116
116
117
117
extension Data {
118
118
/// Encodes data into a base64url-encoded string
119
119
/// - Returns: A base64url-encoded string
120
120
public func base64URLEncodedString( ) -> URLEncodedBase64 {
121
- return [ UInt8] ( self ) . base64URLEncodedString ( )
121
+ [ UInt8] ( self ) . base64URLEncodedString ( )
122
122
}
123
123
}
124
124
125
125
extension String {
126
126
func toBase64( ) -> EncodedBase64 {
127
- return . init ( Data ( self . utf8) . base64EncodedString ( ) )
127
+ EncodedBase64 ( Data ( self . utf8) . base64EncodedString ( ) )
128
128
}
129
129
}
0 commit comments