• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask Leaking...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTask Leaking...
      • From: "Mr. Gecko" <email@hidden>
    • Re: NSTask Leaking...
      • From: Rob Keniger <email@hidden>
  • Prev by Date: Re: Interface Builder Plugin Dependency
  • Next by Date: Re: Query on CrashReporter
  • Previous by thread: Re: NSTask Leaking...
  • Next by thread: Re: NSTask Leaking...
  • Index(es):
    • Date
    • Thread