Re: NSTask Leaking...
Re: NSTask Leaking...
- Subject: Re: NSTask Leaking...
- From: Kirk Kerekes <email@hidden>
- Date: Thu, 29 Jan 2009 18:50:13 -0600
// must include Security framework to use this
// Tiger or later for SHA256
#import "libCdsaCrypt.h"
@implementation NSData (DataDigest)
- (NSData *) digestWithCDSAType:(CSSM_ALGORITHMS) algorithm
{ // does not validate algorithm selection, let the framework worry
about that.
NSData * result = nil;
int error = noErr;
CSSM_DATA inData;
CSSM_CSP_HANDLE cspHandle;
CSSM_DATA digestData;
error = cdsaCspAttach(&cspHandle);
if(!error)
{
inData.Data = (void *)[self bytes];
inData.Length = [self length];
/* calculate digest */
error = cdsaDigest(cspHandle, algorithm, &inData, &digestData);
if(!error)
{
result = [NSData dataWithBytesNoCopy: digestData.Data length:
digestData.Length freeWhenDone: YES];
}
}
return result;
}
- (NSData *) md5Digest
{
return [self digestWithCDSAType: CSSM_ALGID_MD5];
}
- (NSData *) sha1Digest
{
return [self digestWithCDSAType: CSSM_ALGID_SHA1];
}
#ifndef CSSM_ALGID_SHA256
#define CSSM_ALGID_SHA256 0
#endif
- (NSData *) sha256Digest
{
return [self digestWithCDSAType: CSSM_ALGID_SHA256];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden