Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
+ (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag type:(NSString *)type error:(NSError *__autoreleasing*)error;
+ (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag error:(NSError *__autoreleasing*)error;
+ (SecKeyRef)keyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error;
+ (void)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error;
+ (BOOL)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error;
@end

@interface JWTCryptoSecurity (Certificates)
Expand Down
22 changes: 17 additions & 5 deletions Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import "JWTCryptoSecurity.h"
#import "JWTErrorDescription.h"

@interface JWTMemoryLayout : NSObject
+ (NSString *)typeUInt8;
+ (NSString *)typeCUnsignedChar;
Expand Down Expand Up @@ -127,18 +129,28 @@ + (SecKeyRef)keyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
return NULL;
}

+ (void)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
+ (BOOL)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
NSData *tagData = [tag dataUsingEncoding:NSUTF8StringEncoding];
if (tagData == nil) {
// tell that nothing to remove.
return;
// tell that nothing to remove.
if (error) {
*error = [JWTErrorDescription errorWithCode:JWTUnexpectedError];
}
return NO;
}
NSDictionary *removeAttributes = @{
(__bridge NSString*)kSecClass: (__bridge NSString*)kSecClassKey,
(__bridge NSString*)kSecAttrKeyType: (__bridge NSString*)kSecAttrKeyTypeRSA,
(__bridge NSString*)kSecAttrApplicationTag: tagData,
(__bridge NSString*)kSecAttrApplicationTag: tagData
};
SecItemDelete((__bridge CFDictionaryRef)removeAttributes);
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)removeAttributes);
if (status != errSecSuccess) {
if (error) {
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
}
return NO;
}
return YES;
}
@end

Expand Down
3 changes: 2 additions & 1 deletion Core/Supplement/JWTErrorDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ typedef NS_ENUM(NSInteger, JWTError) {
JWTBlacklistedAlgorithmError,
JWTDecodingHeaderError,
JWTDecodingPayloadError,
JWTDecodingHoldersChainEmptyError
JWTDecodingHoldersChainEmptyError,
JWTUnexpectedError
};

@interface JWTErrorDescription : NSObject
Expand Down
6 changes: 4 additions & 2 deletions Core/Supplement/JWTErrorDescription.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ + (NSDictionary *)userDescriptionsAndCodes {
@(JWTBlacklistedAlgorithmError): @"Algorithm in blacklist? Try to check whitelist parameter",
@(JWTDecodingHeaderError): @"Error decoding the JWT Header segment.",
@(JWTDecodingPayloadError): @"Error decoding the JWT Payload segment.",
@(JWTDecodingHoldersChainEmptyError) : @"Error decoding the JWT algorithm and data holders chain is empty!"
@(JWTDecodingHoldersChainEmptyError): @"Error decoding the JWT algorithm and data holders chain is empty!",
@(JWTUnexpectedError): @"Unexpected Error"
});
}

Expand All @@ -49,7 +50,8 @@ + (NSDictionary *)errorDescriptionsAndCodes {
@(JWTBlacklistedAlgorithmError): @"JWTBlacklistedAlgorithmError",
@(JWTDecodingHeaderError): @"JWTDecodingHeaderError",
@(JWTDecodingPayloadError): @"JWTDecodingPayloadError",
@(JWTDecodingHoldersChainEmptyError) :@"JWTDecodingHoldersChainEmptyError"
@(JWTDecodingHoldersChainEmptyError): @"JWTDecodingHoldersChainEmptyError",
@(JWTUnexpectedError): @"JWTUnexpectedError"
});
}

Expand Down