@@ -2,12 +2,12 @@ import Foundation
22
33/// URI Safe base64 encode
44func base64encode( _ input: Data ) -> String {
5- let data = input. base64EncodedData ( options : NSData . Base64EncodingOptions ( rawValue : 0 ) )
5+ let data = input. base64EncodedData ( )
66 let string = String ( data: data, encoding: . utf8) !
77 return string
8- . replacingOccurrences ( of: " + " , with: " - " , options : NSString . CompareOptions ( rawValue : 0 ) , range : nil )
9- . replacingOccurrences ( of: " / " , with: " _ " , options : NSString . CompareOptions ( rawValue : 0 ) , range : nil )
10- . replacingOccurrences ( of: " = " , with: " " , options : NSString . CompareOptions ( rawValue : 0 ) , range : nil )
8+ . replacingOccurrences ( of: " + " , with: " - " )
9+ . replacingOccurrences ( of: " / " , with: " _ " )
10+ . replacingOccurrences ( of: " = " , with: " " )
1111}
1212
1313/// URI Safe base64 decode
@@ -20,8 +20,8 @@ func base64decode(_ input: String) -> Data? {
2020 ending = String ( repeating: " = " , count: amount)
2121 }
2222
23- let base64 = input. replacingOccurrences ( of: " - " , with: " + " , options : NSString . CompareOptions ( rawValue : 0 ) , range : nil )
24- . replacingOccurrences ( of: " _ " , with: " / " , options : NSString . CompareOptions ( rawValue : 0 ) , range : nil ) + ending
23+ let base64 = input. replacingOccurrences ( of: " - " , with: " + " )
24+ . replacingOccurrences ( of: " _ " , with: " / " ) + ending
2525
26- return Data ( base64Encoded: base64, options : NSData . Base64DecodingOptions ( rawValue : 0 ) )
26+ return Data ( base64Encoded: base64)
2727}
0 commit comments