summaryrefslogtreecommitdiff
path: root/ckcapi-token.c
diff options
context:
space:
mode:
Diffstat (limited to 'ckcapi-token.c')
-rw-r--r--ckcapi-token.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/ckcapi-token.c b/ckcapi-token.c
index 4f0a7a3..0f93a45 100644
--- a/ckcapi-token.c
+++ b/ckcapi-token.c
@@ -172,18 +172,35 @@ ckcapi_token_lookup_object(CK_SLOT_ID slot, CK_OBJECT_HANDLE obj)
return ret;
}
+static unsigned int
+object_hash_func(const void* a)
+{
+ CkCapiObject* obj = (CkCapiObject*)a;
+ unsigned int hash = ckcapi_hash_pointer(obj->obj_funcs);
+ hash ^= (obj->obj_funcs->hash_object)(obj);
+ return hash;
+}
+
+static int
+object_equal_func(const void* a, const void* b)
+{
+ CkCapiObject* ca = (CkCapiObject*)a;
+ CkCapiObject* cb = (CkCapiObject*)b;
+ if(ca == cb)
+ return 1;
+ if(ca->obj_funcs != cb->obj_funcs)
+ return 0;
+ return (ca->obj_funcs->equal_object)(ca, cb);
+}
+
CK_RV
ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj)
{
CkCapiObject* prev;
CK_RV ret = CKR_OK;
- void* key;
- size_t klen;
ASSERT(slot);
ASSERT(obj->id == 0);
- ASSERT(obj->unique_key);
- ASSERT(obj->unique_len > 0);
DBG(("registering object"));
@@ -199,8 +216,7 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj)
ckcapi_array_append(object_array, blank);
}
- object_hash = ckcapi_hash_new();
-
+ object_hash = ckcapi_hash_new(object_hash_func, object_equal_func);
if(!object_array || !object_hash)
{
@@ -214,21 +230,14 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj)
ASSERT(object_array);
ASSERT(object_hash);
- /* The type of object is part of the hash */
- key = obj->unique_key;
- klen = obj->unique_len;
-
- /* Sanity check, in case calcs went wrong somewhere */
- ASSERT(klen < 0xFFFFFF);
-
/* Look in the hash and find a previous object */
- prev = ckcapi_hash_get(object_hash, key, klen);
+ prev = ckcapi_hash_get(object_hash, obj);
if(prev)
{
/* Register it in the previous object's place */
obj->id = prev->id;
ASSERT(prev->id < object_array->len);
- if(ckcapi_hash_set(object_hash, key, klen, obj))
+ if(ckcapi_hash_set(object_hash, obj, obj))
{
ckcapi_array_index(object_array, CkCapiObject*, obj->id) = obj;
object_free(prev);
@@ -245,7 +254,7 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj)
/* Register it at the end of the array */
obj->id = object_array->len;
ASSERT(obj->id > 0);
- if(ckcapi_hash_set(object_hash, key, klen, obj))
+ if(ckcapi_hash_set(object_hash, obj, obj))
{
if(ckcapi_array_append(object_array, obj))
{
@@ -256,7 +265,7 @@ ckcapi_token_register_object(CK_SLOT_ID slot, CkCapiObject* obj)
ret = CKR_HOST_MEMORY;
/* Roll back our addition */
- ckcapi_hash_rem(object_hash, key, klen);
+ ckcapi_hash_rem(object_hash, obj);
}
}
else