Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Factor out +ks_stringFromSHA1Digest:

  • Loading branch information...
commit 32acd849ec514825a58dd20f1daf30ac67393178 1 parent 04e5ec2
@mikeabdullah mikeabdullah authored
Showing with 10 additions and 4 deletions.
  1. +2 −0  KSSHA1Stream.h
  2. +8 −4 KSSHA1Stream.m
View
2  KSSHA1Stream.h
@@ -55,6 +55,8 @@
// Cryptographic hashes
- (NSData *)ks_SHA1Digest;
+
- (NSString *)ks_SHA1DigestString;
++ (NSString *)ks_stringFromSHA1Digest:(NSData *)digest;
@end
View
12 KSSHA1Stream.m
@@ -82,11 +82,15 @@ - (NSData *)ks_SHA1Digest
- (NSString *)ks_SHA1DigestString
{
- static char sHEHexDigits[] = "0123456789abcdef";
+ return [[self class] ks_stringFromSHA1Digest:[self ks_SHA1Digest]];
+}
- NSData *digestData = [self ks_SHA1Digest];
++ (NSString *)ks_stringFromSHA1Digest:(NSData *)digestData;
+{
+ static char sHEHexDigits[] = "0123456789abcdef";
+
unsigned char *digest = (unsigned char *)[digestData bytes];
-
+
unsigned char digestString[2 * CC_SHA1_DIGEST_LENGTH];
NSUInteger i;
for (i=0; i<CC_SHA1_DIGEST_LENGTH; i++)
@@ -94,7 +98,7 @@ - (NSString *)ks_SHA1DigestString
digestString[2*i] = sHEHexDigits[digest[i] >> 4];
digestString[2*i+1] = sHEHexDigits[digest[i] & 0x0f];
}
-
+
return [[[NSString alloc] initWithBytes:(const char *)digestString
length:2 * CC_SHA1_DIGEST_LENGTH
encoding:NSASCIIStringEncoding] autorelease];
Please sign in to comment.
Something went wrong with that request. Please try again.