Skip to content

Commit

Permalink
feat: Add support for Linux
Browse files Browse the repository at this point in the history
Closes kylef#51
  • Loading branch information
kylef committed Dec 2, 2016
1 parent 50d8236 commit 6729371
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/Base64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
/// URI Safe base64 encode
func base64encode(_ input:Data) -> String {
let data = input.base64EncodedData(options: NSData.Base64EncodingOptions(rawValue: 0))
let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
let string = String(data: data, encoding: .utf8)!
return string
.replacingOccurrences(of: "+", with: "-", options: NSString.CompareOptions(rawValue: 0), range: nil)
.replacingOccurrences(of: "/", with: "_", options: NSString.CompareOptions(rawValue: 0), range: nil)
Expand Down
24 changes: 12 additions & 12 deletions Sources/JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public func encode(_ payload:Payload, algorithm:Algorithm) -> String {
return nil
}

let header = encodeJSON(["typ": "JWT" as AnyObject, "alg": algorithm.description as AnyObject])!
let header = encodeJSON(["typ": "JWT", "alg": algorithm.description])!
let payload = encodeJSON(payload)!
let signingInput = "\(header).\(payload)"
let signature = algorithm.sign(signingInput)
Expand All @@ -91,25 +91,25 @@ public func encode(_ payload:Payload, algorithm:Algorithm) -> String {
open class PayloadBuilder {
var payload = Payload()

open var issuer:String? {
open var issuer: String? {
get {
return payload["iss"] as? String
}
set {
payload["iss"] = newValue as AnyObject?
payload["iss"] = newValue
}
}

open var audience:String? {
open var audience: String? {
get {
return payload["aud"] as? String
}
set {
payload["aud"] = newValue as AnyObject?
payload["aud"] = newValue
}
}

open var expiration:Date? {
open var expiration: Date? {
get {
if let expiration = payload["exp"] as? TimeInterval {
return Date(timeIntervalSince1970: expiration)
Expand All @@ -118,11 +118,11 @@ open class PayloadBuilder {
return nil
}
set {
payload["exp"] = newValue?.timeIntervalSince1970 as AnyObject?
payload["exp"] = newValue?.timeIntervalSince1970
}
}

open var notBefore:Date? {
open var notBefore: Date? {
get {
if let notBefore = payload["nbf"] as? TimeInterval {
return Date(timeIntervalSince1970: notBefore)
Expand All @@ -131,11 +131,11 @@ open class PayloadBuilder {
return nil
}
set {
payload["nbf"] = newValue?.timeIntervalSince1970 as AnyObject?
payload["nbf"] = newValue?.timeIntervalSince1970
}
}

open var issuedAt:Date? {
open var issuedAt: Date? {
get {
if let issuedAt = payload["iat"] as? TimeInterval {
return Date(timeIntervalSince1970: issuedAt)
Expand All @@ -144,11 +144,11 @@ open class PayloadBuilder {
return nil
}
set {
payload["iat"] = newValue?.timeIntervalSince1970 as AnyObject?
payload["iat"] = newValue?.timeIntervalSince1970
}
}

open subscript(key: String) -> Any {
open subscript(key: String) -> Any? {
get {
return payload[key]
}
Expand Down

0 comments on commit 6729371

Please sign in to comment.