Updating ITFoundation to include updates spurred by Haven development.
[ITFoundation.git] / ITCategory-NSData.m
1 #import "ITCategory-NSData.h"
2 #import <openssl/md5.h>
3 #import <openssl/sha.h>
4
5 @implementation NSData (ITFoundationCategory)
6
7 - (NSString *)hexadecimalRepresentation {
8         int dataLength = [self length];
9         int stringLength = dataLength * 2;
10         
11         char *dataBytes = [self bytes];
12         char hexString[stringLength];
13         
14         int i;
15         for (i=0; i < dataLength; i++) {
16                 sprintf(hexString + (i * 2), "%02x", dataBytes[i]);
17         }
18         
19         return [NSString stringWithCString:hexString length:stringLength];
20 }
21
22 - (NSData *)MD5 {
23         int length = 16;
24         unsigned char digest[length];
25         MD5([self bytes], [self length], digest);
26         return [NSData dataWithBytes:&digest length:length];
27 }
28
29 - (NSData *)SHA1 {
30         int length = 20;
31         unsigned char digest[length];
32         SHA1([self bytes], [self length], digest);
33         return [NSData dataWithBytes:&digest length:length];
34 }
35
36 @end