forked from rnapier/RNCachingURLProtocol
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes the issue described at rnapier#14 using SHA1 instead of [NSStri…
…ng hash]
- Loading branch information
Dennis Wilson
committed
Dec 5, 2012
1 parent
b9cc717
commit 09b22f3
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <CommonCrypto/CommonDigest.h> | ||
|
||
/** | ||
* This extension contains several a helper | ||
* for creating a sha1 hash from instances of NSString | ||
*/ | ||
@interface NSString (Sha1) | ||
|
||
/** | ||
* Creates a SHA1 (hash) representation of NSString. | ||
* | ||
* @return NSString | ||
*/ | ||
- (NSString *)sha1; | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
#import "NSString+Sha1.h" | ||
|
||
@implementation NSString (Sha1) | ||
|
||
- (NSString *)sha1 | ||
{ | ||
// see http://www.makebetterthings.com/iphone/how-to-get-md5-and-sha1-in-objective-c-ios-sdk/ | ||
NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; | ||
uint8_t digest[CC_SHA1_DIGEST_LENGTH]; | ||
|
||
CC_SHA1(data.bytes, data.length, digest); | ||
|
||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; | ||
|
||
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { | ||
[output appendFormat:@"%02x", digest[i]]; | ||
} | ||
|
||
return output; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters