blob: ba64151d021e3ec4c03b617cb41ce705b0af1e72 [file] [log] [blame]
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.
#import "NSData-CDExtensions.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSData (CDExtensions)
- (NSString *)hexString;
{
NSMutableString *str = [NSMutableString string];
const uint8_t *ptr = [self bytes];
for (NSUInteger index = 0; index < [self length]; index++) {
[str appendFormat:@"%02x", *ptr++];
}
return str;
}
- (NSData *)SHA1Digest;
{
NSParameterAssert([self length] <= UINT32_MAX);
unsigned char digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1([self bytes], (CC_LONG)[self length], digest);
return [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
}
@end