#ifdef STANDALONE
#undef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#undef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#endif
#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_IPHONE
CFStringRef kSecFrameworkBundleID = CFSTR("com.apple.Security");
#else
CFStringRef kSecFrameworkBundleID = CFSTR("com.apple.security");
#endif
CFGiblisGetSingleton(CFBundleRef, SecFrameworkGetBundle, bundle, ^{
*bundle = CFRetainSafe(CFBundleGetBundleWithIdentifier(kSecFrameworkBundleID));
})
CFStringRef SecFrameworkCopyLocalizedString(CFStringRef key,
CFStringRef tableName) {
CFBundleRef bundle = SecFrameworkGetBundle();
if (bundle)
return CFBundleCopyLocalizedString(bundle, key, key, tableName);
return CFRetainSafe(key);
}
CFURLRef SecFrameworkCopyResourceURL(CFStringRef resourceName,
CFStringRef resourceType, CFStringRef subDirName) {
CFURLRef url = NULL;
CFBundleRef bundle = SecFrameworkGetBundle();
if (bundle) {
url = CFBundleCopyResourceURL(bundle, resourceName,
resourceType, subDirName);
if (!url) {
secwarning("resource: %@.%@ in %@ not found", resourceName,
resourceType, subDirName);
}
}
return url;
}
CFDataRef SecFrameworkCopyResourceContents(CFStringRef resourceName,
CFStringRef resourceType, CFStringRef subDirName) {
CFURLRef url = SecFrameworkCopyResourceURL(resourceName, resourceType,
subDirName);
CFDataRef data = NULL;
if (url) {
SInt32 error;
if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
url, &data, NULL, NULL, &error)) {
secwarning("read: %ld", (long) error);
}
CFRelease(url);
}
return data;
}