Skip to content

Commit

Permalink
refactored base64 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiratanasov committed Mar 5, 2021
1 parent 34b723d commit 3ed8bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Source/IBMCloudAppID/internal/Utils.swift
Expand Up @@ -15,7 +15,16 @@ import BMSCore


public class Utils {


public static func base64urlToBase64(base64url: String) -> String {
var base64 = base64url
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
if base64.count % 4 != 0 {
base64.append(String(repeating: "=", count: 4 - base64.count % 4))
}
return base64
}

public static func JSONStringify(_ value: AnyObject, prettyPrinted:Bool = false) throws -> String{

Expand Down
4 changes: 2 additions & 2 deletions Source/IBMCloudAppID/internal/tokens/AbstractToken.swift
Expand Up @@ -45,8 +45,8 @@ internal class AbstractToken: Token {
self.signature = tokenComponents[2]

guard
let headerDecodedData = Utils.decodeBase64WithString(headerComponent, isSafeUrl: true),
let payloadDecodedData = Utils.decodeBase64WithString(payloadComponent, isSafeUrl: true)
let headerDecodedData = Data(base64Encoded: Utils.base64urlToBase64(base64url: headerComponent)),
let payloadDecodedData = Data(base64Encoded: Utils.base64urlToBase64(base64url: payloadComponent))
else {
return nil
}
Expand Down

0 comments on commit 3ed8bd1

Please sign in to comment.