Skip to content

Commit

Permalink
Merge pull request #88 from lolgear/master
Browse files Browse the repository at this point in the history
New API Introduced
  • Loading branch information
Dmitry authored Aug 31, 2016
2 parents 2fd415b + 0d1d1b5 commit 9527ef4
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ script:
- pod install --project-directory=Framework

- echo Check if the library described by the podspec can be built
- pod lib lint
- pod lib lint --allow-warnings

# Build.
- echo "Build iOS Static library"
Expand Down
5 changes: 3 additions & 2 deletions Classes/Algorithms/Base/JWTAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "JWTDeprecations.h"

@protocol JWTAlgorithm <NSObject>

Expand All @@ -20,7 +21,7 @@
@param theSecret The secret to use for encryption
@return An NSData object containing the encrypted payload, or nil if something went wrong.
*/
- (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret;
- (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret __deprecated_and_will_be_removed_in_release_version(JWTVersion_3_0_0);

/**
Verifies the provided signature using the signed input and verification key
Expand All @@ -29,7 +30,7 @@
@param verificationKey The key to use for verifying the signature
@return YES if the provided signature is valid, NO otherwise
*/
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKey:(NSString *)verificationKey;
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKey:(NSString *)verificationKey __deprecated_and_will_be_removed_in_release_version(JWTVersion_3_0_0);

@optional

Expand Down
2 changes: 0 additions & 2 deletions Classes/Algorithms/Base/JWTAlgorithmFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

#import <Foundation/Foundation.h>

#import "JWTAlgorithm.h"

@interface JWTAlgorithmFactory : NSObject

+ (NSArray *)algorithms;
Expand Down
11 changes: 5 additions & 6 deletions Classes/Algorithms/Base/JWTAlgorithmFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
//

#import "JWTAlgorithmFactory.h"
//#import "JWTAlgorithmHS256.h"
//#import "JWTAlgorithmHS384.h"
//#import "JWTAlgorithmHS512.h"
#import "JWTAlgorithmHSBase.h"
#import <TargetConditionals.h>
#import "JWTAlgorithmRSBase.h"


#import "JWTAlgorithmNone.h"

// not implemented.
NSString *const JWTAlgorithmNameES256 = @"ES256";
NSString *const JWTAlgorithmNameES384 = @"ES384";
NSString *const JWTAlgorithmNameES512 = @"ES512";

@implementation JWTAlgorithmFactory

+ (NSArray *)algorithms {
Expand Down
1 change: 1 addition & 0 deletions Classes/Algorithms/Base/JWTAlgorithmNone.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Foundation/Foundation.h>
#import "JWTAlgorithm.h"
extern NSString *const JWTAlgorithmNameNone;

@interface JWTAlgorithmNone : NSObject <JWTAlgorithm>

Expand Down
3 changes: 2 additions & 1 deletion Classes/Algorithms/Base/JWTAlgorithmNone.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
//

#import "JWTAlgorithmNone.h"
NSString *const JWTAlgorithmNameNone = @"none";

@implementation JWTAlgorithmNone

- (NSString *)name {
return @"none";
return JWTAlgorithmNameNone;
}

- (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret {
Expand Down
3 changes: 3 additions & 0 deletions Classes/Algorithms/HSFamily/JWTAlgorithmHSBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#import <Foundation/Foundation.h>
#import "JWTAlgorithm.h"
extern NSString *const JWTAlgorithmNameHS256;
extern NSString *const JWTAlgorithmNameHS384;
extern NSString *const JWTAlgorithmNameHS512;

@interface JWTAlgorithmHSBase : NSObject <JWTAlgorithm>

Expand Down
4 changes: 4 additions & 0 deletions Classes/Algorithms/HSFamily/JWTAlgorithmHSBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#import "JWTAlgorithmHS384.h"
#import "JWTAlgorithmHS512.h"

NSString *const JWTAlgorithmNameHS256 = @"HS256";
NSString *const JWTAlgorithmNameHS384 = @"HS384";
NSString *const JWTAlgorithmNameHS512 = @"HS512";

// TODO:
// 1. hide algorithms as it was done in RSBase.
// 2. remove remain headers.
Expand Down
19 changes: 0 additions & 19 deletions Classes/Algorithms/HSFamily/JWTAlgorithmHSFamily.h

This file was deleted.

123 changes: 0 additions & 123 deletions Classes/Algorithms/HSFamily/JWTAlgorithmHSFamily.m

This file was deleted.

79 changes: 79 additions & 0 deletions Classes/Algorithms/Holders/JWTAlgorithmDataHolder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// JWTAlgorithmDataHolder.h
// JWT
//
// Created by Lobanov Dmitry on 31.08.16.
// Copyright © 2016 Karma. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "JWTAlgorithm.h"
#import "JWTDeprecations.h"

// TODO: available in 3.0
// All methods with secret as NSString in algorithms will be deprecated or removed.

@protocol JWTAlgorithmDataHolder <NSObject>
/**
The verification key to use when encoding/decoding a JWT in data form
*/
@property (copy, nonatomic, readonly) NSData *currentSecretData __deprecated_msg("msg");

/**
The <JWTAlgorithm> to use for encoding a JWT
*/
@property (strong, nonatomic, readonly) id <JWTAlgorithm> currentAlgorithm;
@end

@interface JWTAlgorithmBaseDataHolder : NSObject <JWTAlgorithmDataHolder>

#pragma mark - Getters
/**
The verification key to use when encoding/decoding a JWT
*/
@property (copy, nonatomic, readonly) NSString *currentSecret;

/**
The algorithm name to use for decoding the JWT. Required unless force decode is true
*/
@property (copy, nonatomic, readonly) NSString *currentAlgorithmName;

#pragma mark - Setters
/**
Sets jwtSecret and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
*/
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^secret)(NSString *secret);

/**
Sets jwtSecretData and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
*/
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^secretData)(NSData *secretData);

/**
Sets jwtAlgorithm and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
*/
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^algorithm)(id<JWTAlgorithm>algorithm);

/**
Sets jwtAlgorithmName and returns the JWTAlgorithmBaseDataHolder to allow for method chaining. See list of names in appropriate headers.
*/
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^algorithmName)(NSString *algorithmName);

@end

@interface JWTAlgorithmHSFamilyDataHolder : JWTAlgorithmBaseDataHolder
@end

@interface JWTAlgorithmRSFamilyDataHolder : JWTAlgorithmBaseDataHolder
#pragma mark - Getters
/**
The passphrase for the PKCS12 blob, which represents the certificate containing the private key for the RS algorithms.
*/
@property (copy, nonatomic, readonly) NSString *currentPrivateKeyCertificatePassphrase;

#pragma mark - Setters
/**
Sets jwtPrivateKeyCertificatePassphrase and returns the JWTAlgorithmRSFamilyDataHolder to allow for method chaining
*/
@property (copy, nonatomic, readonly) JWTAlgorithmRSFamilyDataHolder *(^privateKeyCertificatePassphrase)(NSString *privateKeyCertificatePassphrase);
@end
Loading

0 comments on commit 9527ef4

Please sign in to comment.