#ifdef STANDALONE
#undef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#undef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#endif
#include <Availability.h>
#include "SecFramework.h"
#include <dispatch/dispatch.h>
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFURLAccess.h>
#include <Security/SecRandom.h>
#include <CommonCrypto/CommonRandomSPI.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <utilities/debugging.h>
#include <utilities/SecCFWrappers.h>
#include <Security/SecBase.h>
#include <inttypes.h>
#if !TARGET_OS_OSX
static CFStringRef copyErrorMessageFromBundle(OSStatus status, CFStringRef tableName);
CFStringRef
SecCopyErrorMessageString(OSStatus status, void *reserved)
{
CFStringRef result = copyErrorMessageFromBundle(status, CFSTR("SecErrorMessages"));
if (!result)
result = copyErrorMessageFromBundle(status, CFSTR("SecDebugErrorMessages"));
if (!result)
{
result = CFStringCreateWithFormat(NULL, NULL, CFSTR("OSStatus %d"), (int)status);
}
return result;
}
CFStringRef
copyErrorMessageFromBundle(OSStatus status,CFStringRef tableName)
{
CFStringRef errorString = nil;
CFStringRef keyString = nil;
CFBundleRef secBundle = NULL;
secBundle = CFBundleGetBundleWithIdentifier(kSecFrameworkBundleID);
if (!secBundle)
goto exit;
keyString = CFStringCreateWithFormat (kCFAllocatorDefault, NULL, CFSTR("%d"), (int)status);
if (!keyString)
goto exit;
errorString = CFCopyLocalizedStringFromTableInBundle(keyString, tableName, secBundle, NULL);
if (CFStringCompare(errorString, keyString, 0) == kCFCompareEqualTo) {
if (errorString)
CFRelease(errorString);
errorString = nil;
}
exit:
if (keyString)
CFRelease(keyString);
return errorString;
}
const SecRandomRef kSecRandomDefault = NULL;
int SecRandomCopyBytes(__unused SecRandomRef rnd, size_t count, void *bytes) {
return CCRandomCopyBytes(kCCRandomDefault, bytes, count);
}
#endif // TARGET_OS_OSX