Skip to content

Commit

Permalink
Merge pull request #85 from lolgear/master
Browse files Browse the repository at this point in the history
RS algorithms hierarchy refactoring
  • Loading branch information
Dmitry authored Aug 29, 2016
2 parents 0d00bd5 + 71e3d0a commit 2fd415b
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 408 deletions.
47 changes: 30 additions & 17 deletions Classes/Algorithms/HSFamily/JWTAlgorithmHSBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
#import <Base64/MF_Base64Additions.h>
#import <CommonCrypto/CommonCrypto.h>
#import <CommonCrypto/CommonHMAC.h>
#import "JWTAlgorithmHS256.h"
#import "JWTAlgorithmHS384.h"
#import "JWTAlgorithmHS512.h"

// TODO:
// 1. hide algorithms as it was done in RSBase.
// 2. remove remain headers.
@interface JWTAlgorithmHSBase ()

@end
Expand Down Expand Up @@ -79,14 +85,18 @@ - (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature

@end

@interface JWTAlgorithmHSFamilyMember : JWTAlgorithmHSBase @end
@implementation JWTAlgorithmHSFamilyMember @end

@interface JWTAlgorithmHSBaseTest : JWTAlgorithmHSBase
/* JWTAlgorithmHS256 : JWTAlgorithmHSFamilyMember and others */

@interface JWTAlgorithmHSFamilyMemberMutable : JWTAlgorithmHSFamilyMember
@property (assign, nonatomic, readwrite) size_t ccSHANumberDigestLength;
@property (assign, nonatomic, readwrite) uint32_t ccHmacAlgSHANumber;
@property (copy, nonatomic, readwrite) NSString *name;
@end

@implementation JWTAlgorithmHSBaseTest
@implementation JWTAlgorithmHSFamilyMemberMutable

@synthesize ccSHANumberDigestLength = _ccSHANumberDigestLength;
@synthesize ccHmacAlgSHANumber = _ccHmacAlgSHANumber;
Expand All @@ -105,27 +115,30 @@ - (uint32_t)ccHmacAlgSHANumber {
@implementation JWTAlgorithmHSBase (Create)

+ (instancetype)algorithm256 {
JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
base.ccSHANumberDigestLength = CC_SHA256_DIGEST_LENGTH;
base.ccHmacAlgSHANumber = kCCHmacAlgSHA256;
base.name = @"HS256";
return base;
// JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
// base.ccSHANumberDigestLength = CC_SHA256_DIGEST_LENGTH;
// base.ccHmacAlgSHANumber = kCCHmacAlgSHA256;
// base.name = @"HS256";
// return base;
return [JWTAlgorithmHS256 new];
}

+ (instancetype)algorithm384 {
JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
base.ccSHANumberDigestLength = CC_SHA384_DIGEST_LENGTH;
base.ccHmacAlgSHANumber = kCCHmacAlgSHA384;
base.name = @"HS384";
return base;
// JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
// base.ccSHANumberDigestLength = CC_SHA384_DIGEST_LENGTH;
// base.ccHmacAlgSHANumber = kCCHmacAlgSHA384;
// base.name = @"HS384";
// return base;
return [JWTAlgorithmHS384 new];
}

+ (instancetype)algorithm512 {
JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
base.ccSHANumberDigestLength = CC_SHA512_DIGEST_LENGTH;
base.ccHmacAlgSHANumber = kCCHmacAlgSHA512;
base.name = @"HS512";
return base;
// JWTAlgorithmHSBaseTest *base = [JWTAlgorithmHSBaseTest new];
// base.ccSHANumberDigestLength = CC_SHA512_DIGEST_LENGTH;
// base.ccHmacAlgSHANumber = kCCHmacAlgSHA512;
// base.name = @"HS512";
// return base;
return [JWTAlgorithmHS512 new];
}

@end
14 changes: 0 additions & 14 deletions Classes/Algorithms/RSFamily/JWTAlgorithmRS256.h

This file was deleted.

199 changes: 0 additions & 199 deletions Classes/Algorithms/RSFamily/JWTAlgorithmRS256.m

This file was deleted.

8 changes: 7 additions & 1 deletion Classes/Algorithms/RSFamily/JWTAlgorithmRSBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
+ (instancetype)algorithm256;
+ (instancetype)algorithm384;
+ (instancetype)algorithm512;
+ (instancetype)mutableAlgorithm __deprecated;

@end
@end

/*
// when you can't live without mutability, uncomment.
@class JWTAlgorithmRSFamilyMemberMutable;
*/
Loading

0 comments on commit 2fd415b

Please sign in to comment.