NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name) { //notice("psst: GetStringIdentifier '%s'", name); CFDataRef data = CFDataCreate(NULL, (unsigned char *) name, strlen(name)); CFDataRef ret = CFSetGetValue(identifier_set, data); if(!ret) { CFSetAddValue(identifier_set, data); ret = data; } CFRelease(data); return (NPIdentifier) ret; }
NPIdentifier NPN_GetIntIdentifier(int32_t intid) { notice("Get*INT*Identifier: %d", intid); CFNumberRef number = CFNumberCreate(NULL, kCFNumberIntType, &intid); CFNumberRef ret = CFSetGetValue(identifier_set, number); if(!ret) { CFSetAddValue(identifier_set, number); ret = number; } CFRelease(number); return (NPIdentifier) ret; }
Boolean CFSetGetValueIfPresent (CFSetRef set, const void *candidate, const void **value) { const void *v; v = CFSetGetValue (set, candidate); if (v) { if (value) *value = v; return true; } return false; }
CF_INLINE _cfmp_deallocation_record *const _cfmp_find_record_for_port(CFSetRef const records, _CFMPLifetimeClient const client, mach_port_t const port) { _cfmp_deallocation_record const lookup = {.port = port, .client = client}; _cfmp_deallocation_record *const pr = (_cfmp_deallocation_record *)CFSetGetValue(records, &lookup); return pr; }
CFSetCallBacks dmcb = { .version = 0, .retain = NULL, .release = NULL, .copyDescription = NULL, .equal = (CFSetEqualCallBack)digest_mapping_equal, .hash = (CFSetHashCallBack)digest_mapping_hash }; algos = CFSetCreateMutable(NULL, mapping_count, &dmcb); int i; for(i = 0; i < mapping_count; i++) { CFSetAddValue(algos, i + (struct digest_mapping *)digest_mappings); } }); struct digest_mapping search; search.kclass = ckey->KeyHeader.AlgorithmId; search.digest_name = digest; search.digest_length = digest_length; struct digest_mapping *dmapping = (void*)CFSetGetValue(algos, &search); if (dmapping) { *picked = dmapping; return NULL; } // It is argueable better to gennerate these messages by looking at digest_mappings, but with only 3 keytypes and 4 digests (only one of which has signifigant length variations) a case statment is likely the best way. switch (ckey->KeyHeader.AlgorithmId) { case CSSM_ALGID_RSA: return fancy_error(kSecTransformErrorDomain, kSecTransformErrorInvalidAlgorithm, CFSTR("Invalid digest algorithm for RSA signature, choose one of: SHA1, SHA2 (512bits, 348bits, 256bits, or 224 bits), MD2, or MD5")); break; case CSSM_ALGID_ECDSA: return fancy_error(kSecTransformErrorDomain, kSecTransformErrorInvalidAlgorithm, CFSTR("Invalid digest algorithm for ECDSA signature, choose one of: SHA1, or SHA2 (512bits, 348bits, 256bits, or 224 bits)")); break;
static void printTickIfExists(CFSetRef keySet, CFStringRef key) { if (CFSetGetValue(keySet, key) != NULL) printf(" \xE2\x9C\x93 ||"); else printf(" ||"); }