Skip to content

Commit b261a71

Browse files
committed
Make project compile in swift 2
1 parent 6788189 commit b261a71

File tree

12 files changed

+43
-18
lines changed

12 files changed

+43
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ profile
1818
DerivedData
1919
*.hmap
2020
*.ipa
21+
*.xcscmblueprint
2122

2223
# Bundler
2324
.bundle

Cartfile.private

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#Quick & Nimble
22

3-
github "Quick/Quick" ~> 0.3
4-
github "Quick/Nimble" ~> 0.4
3+
github "Quick/Quick" ~> 0.6
4+
github "Quick/Nimble" "v2.0.0-rc.3"

Cartfile.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "Quick/Nimble" "v0.4.2"
2-
github "Quick/Quick" "v0.3.1"
1+
github "Quick/Nimble" "811003c1e556d6fedd12a6e8b81da235a7479aca"
2+
github "Quick/Quick" "v0.6.0"

Carthage/Checkouts/Nimble

Submodule Nimble updated 72 files

Carthage/Checkouts/Quick

Submodule Quick updated 50 files

JWTDecode.playground/Contents.swift

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//: Playground - noun: a place where people can play
2+
3+
import JWTDecode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Timeline
3+
version = "3.0">
4+
<TimelineItems>
5+
</TimelineItems>
6+
</Timeline>

JWTDecode.xcodeproj/project.pbxproj

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
5F0069401B3C828F0048928E /* A0JWTDecodeSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0JWTDecodeSpec.m; sourceTree = "<group>"; };
5454
5F05AF7D1B62E9C200C4A9E6 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5555
5F05AF7E1B62E9C200C4A9E6 /* Quick.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Quick.framework; sourceTree = BUILT_PRODUCTS_DIR; };
56+
5F0A5E291B9A6D4A005289CF /* JWTDecode.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = JWTDecode.playground; sourceTree = SOURCE_ROOT; };
5657
/* End PBXFileReference section */
5758

5859
/* Begin PBXFrameworksBuildPhase section */
@@ -116,6 +117,7 @@
116117
5F0068E41B3B46240048928E /* JWTDecode */ = {
117118
isa = PBXGroup;
118119
children = (
120+
5F0A5E291B9A6D4A005289CF /* JWTDecode.playground */,
119121
5F0068E71B3B46240048928E /* JWTDecode.h */,
120122
5F0068E51B3B46240048928E /* Supporting Files */,
121123
5F0069021B3B511F0048928E /* JWTDecode.swift */,
@@ -252,6 +254,7 @@
252254
5F0068D91B3B46240048928E /* Project object */ = {
253255
isa = PBXProject;
254256
attributes = {
257+
LastSwiftUpdateCheck = 0700;
255258
LastUpgradeCheck = 0630;
256259
ORGANIZATIONNAME = Auth0;
257260
TargetAttributes = {

JWTDecode/JWTDecode.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Decodes the JWT and return it's payload
2929

3030
:returns: the JWT payload or nil when it can be decoded
3131
*/
32-
public func payload(#jwt: String) -> [String: AnyObject]? {
32+
public func payload(jwt jwt: String) -> [String: AnyObject]? {
3333
return JWTDecoder(jwt: jwt).payloadWithError(nil)
3434
}
3535

@@ -41,7 +41,7 @@ If the `exp` claim is missing or the jwt can't be decoded it will return true
4141

4242
:returns: if the JWT is expired or not
4343
*/
44-
public func expired(#jwt: String) -> Bool {
44+
public func expired(jwt jwt: String) -> Bool {
4545
return JWTDecoder(jwt: jwt).expired
4646
}
4747

@@ -52,7 +52,7 @@ Returns the value of the `exp` claim
5252

5353
:returns: date that the JWT will expire or nil
5454
*/
55-
public func expireDate(#jwt: String) -> NSDate? {
55+
public func expireDate(jwt jwt: String) -> NSDate? {
5656
return JWTDecoder(jwt: jwt).expireDate
5757
}
5858

@@ -105,7 +105,15 @@ public class JWTDecoder: NSObject {
105105
base64 = base64.stringByAppendingString(padding)
106106
}
107107
if let data = NSData(base64EncodedString: base64, options: .IgnoreUnknownCharacters) {
108-
return NSJSONSerialization.JSONObjectWithData(data, options: .allZeros, error: error) as? [String: AnyObject]
108+
do {
109+
let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
110+
return json as? [String: AnyObject]
111+
}
112+
catch let jsonError as NSError {
113+
if error != nil {
114+
error.memory = jsonError
115+
}
116+
}
109117
} else {
110118
if error != nil {
111119
error.memory = errorWithDescription(NSLocalizedString("malformed jwt token \(jwt). failed to decode base64 payload", comment: "Invalid base64"))

JWTDecodeTests/A0JWTDecodeSpec.m

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@
2323

2424
#define QUICK_DISABLE_SHORT_SYNTAX 1
2525

26-
#import <Quick/Quick.h>
27-
#import <Nimble/Nimble.h>
28-
26+
@import Quick;
27+
@import Nimble;
2928
@import JWTDecode;
3029

3130
QuickSpecBegin(A0JWTDecodeSpec)
3231

33-
__block JWTDecoder *decoder;
32+
__block A0JWTDecoder *decoder;
3433
__block NSError *error;
3534

3635
describe(@"Objc support", ^{
3736

3837
beforeEach(^{
39-
decoder = [[JWTDecoder alloc] initWithJwt:@"INVALID"];
38+
decoder = [[A0JWTDecoder alloc] initWithJwt:@"INVALID"];
4039
error = nil;
4140
});
4241

JWTDecodeTests/JWTDecodeSpec.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ let inTwoHours = NSDate(timeIntervalSinceNow: 2 * 60 * 60)
2929

3030
func jwtWithPayload(payload: [String: AnyObject]) -> String {
3131
var jwt: String = ""
32-
if let data = NSJSONSerialization.dataWithJSONObject(payload, options: .allZeros, error: nil) {
33-
let base64 = data.base64EncodedStringWithOptions(.allZeros)
32+
do {
33+
let data = try NSJSONSerialization.dataWithJSONObject(payload, options: NSJSONWritingOptions())
34+
let base64 = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions())
3435
.stringByReplacingOccurrencesOfString("+", withString: "-")
3536
.stringByReplacingOccurrencesOfString("/", withString: "_")
3637
.stringByReplacingOccurrencesOfString("=", withString: "")
3738
jwt = "HEADER.\(base64).SIGNATURE"
38-
} else {
39+
} catch _ {
3940
NSException(name: NSInvalidArgumentException, reason: "Failed to build jwt", userInfo: nil).raise()
4041
}
4142
return jwt

0 commit comments

Comments
 (0)