I am getting a CFStringRef
out of a CFDictionaryRef
using CFDictionaryGetValue
.
I've been trying to convert the CFStringRef
to a char*
using CFStringGetCString
or CFStringGetCStringPtr
and they either return a NULL or it crashes.
Is there a way to do this? How?
Thank you.
EDIT: sample code:
SecStaticCodeRef staticCode;
CFDictionaryRef information;
SecCSFlags flags = kSecCSInternalInformation
| kSecCSSigningInformation
| kSecCSRequirementInformation
| kSecCSInternalInformation;
CFURLRef pathURL = NULL;
CFStringRef pathStr = NULL;
CFStringRef uniqueid;
char* str = NULL;
CFIndex length;
pathStr = CFStringCreateWithCString(kCFAllocatorDefault,
filename, kCFStringEncodingUTF8);
pathURL = CFURLCreateWithString(kCFAllocatorDefault, pathStr, NULL);
SecStaticCodeCreateWithPath(pathURL, kSecCSDefaultFlags, &staticCode);
SecCodeCopySigningInformation(staticCode, flags, &information);
uniqueid = (CFStringRef) CFDictionaryGetValue(information, kSecCodeInfoUnique);
// how do I convert it here to char *?
length = CFStringGetLength(uniqueid);
str = (char *)malloc( length + 1 );
CFStringGetCString(uniqueid, str, length, kCFStringEncodingUTF8);
printf("hash of signature is %s\n", str);
CFRelease(information);
CFRelease(staticCode);
CFStringGetCString()
look? Have you checked the guide?Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFData _getCString:maxLength:encoding:]: unrecognized selector sent to instance 0x100503460'
followed by a dump of the stack