KMF_RETURN GetIDFromSPKI(KMF_X509_SPKI *spki, KMF_DATA *ID) { KMF_RETURN rv = KMF_OK; KMF_DATA KeyParts[KMF_MAX_PUBLIC_KEY_PARTS]; uint32_t uNumKeyParts = KMF_MAX_PUBLIC_KEY_PARTS; KMF_ALGORITHM_INDEX algId; int i; if (ID == NULL || spki == NULL) return (KMF_ERR_BAD_PARAMETER); ID->Data = (uchar_t *)malloc(SHA1_HASH_LENGTH); if (ID->Data == NULL) return (KMF_ERR_MEMORY); ID->Length = SHA1_HASH_LENGTH; algId = x509_algoid_to_algid(&spki->algorithm.algorithm); if (algId == KMF_ALGID_NONE) return (KMF_ERR_BAD_ALGORITHM); rv = ExtractSPKIData(spki, algId, KeyParts, &uNumKeyParts); if (rv != KMF_OK) return (rv); /* Check the KEY algorithm */ if (algId == KMF_ALGID_RSA) { create_id_hash(&KeyParts[KMF_RSA_MODULUS], ID); } else if (algId == KMF_ALGID_DSA) { create_id_hash(&KeyParts[KMF_DSA_PUBLIC_VALUE], ID); } else if (algId == KMF_ALGID_SHA1WithECDSA || algId == KMF_ALGID_ECDSA) { create_id_hash(&KeyParts[KMF_ECDSA_POINT], ID); } else { /* We only support RSA and DSA keys for now */ rv = KMF_ERR_BAD_ALGORITHM; } for (i = 0; i < uNumKeyParts; i++) { if (KeyParts[i].Data != NULL) free(KeyParts[i].Data); } if (rv != KMF_OK && ID->Data != NULL) { free(ID->Data); ID->Data = NULL; ID->Length = 0; } return (rv); }
static VALUE initialize_native(VALUE self, VALUE UNUSED(options)) { JohnsonRuntime* runtime; Data_Get_Struct(self, JohnsonRuntime, runtime); if ((runtime->js = JS_NewRuntime(0x100000)) && (runtime->jsids = create_id_hash()) && (runtime->rbids = create_id_hash()) ) { JS_SetRuntimePrivate(runtime->js, (void *)self); JS_SetGCCallbackRT(runtime->js, gc_callback); JSContext* context = johnson_get_current_context(runtime); if( (runtime->global = JS_GetGlobalObject(context)) && (JS_AddNamedRoot(context, &(runtime->global), "runtime->global")) ) { return self; } } if (runtime->rbids) JS_HashTableDestroy(runtime->rbids); if (runtime->jsids) JS_HashTableDestroy(runtime->jsids); if (runtime->js) JS_DestroyRuntime(runtime->js); rb_raise(rb_eRuntimeError, "Couldn't initialize the runtime!"); return Qnil; }