Re: NSTask Leaking...
Re: NSTask Leaking...
- Subject: Re: NSTask Leaking...
- From: "Mr. Gecko" <email@hidden>
- Date: Thu, 29 Jan 2009 20:36:17 -0600
Thanks for the help, I've got it working
On Jan 29, 2009, at 6:50 PM, Kirk Kerekes wrote:
// 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