From a108ff1a5e76aedb24db06812742e640c178f976 Mon Sep 17 00:00:00 2001 From: Gijs Molenaar Date: Fri, 16 Feb 2018 14:42:01 +0200 Subject: [PATCH] add nedtrie for function mapping --- LICENSE | 30 + generate/filters.py | 13 + generate/generate.py | 4 +- generate/templates/test/test_pack.c | 5 +- src/CMakeLists.txt | 10 +- src/generated/test/test_pack.c | 1042 +++++------- src/generated/unpack.c | 640 +++---- src/static/convert.c | 250 +-- src/static/convert.h | 15 +- src/static/derget.c | 3 +- src/static/derput.c | 14 +- src/static/nedtrie.h | 2396 +++++++++++++++++++++++++++ 12 files changed, 3334 insertions(+), 1088 deletions(-) create mode 100644 src/static/nedtrie.h diff --git a/LICENSE b/LICENSE index b04aba9..5c650be 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,33 @@ + +files: src/static/nedtrie.h +license: Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +files: * +license: BSD 3 clause + Copyright (c) 2017 Gijs Molenaar All rights reserved. diff --git a/generate/filters.py b/generate/filters.py index 2771330..109669b 100644 --- a/generate/filters.py +++ b/generate/filters.py @@ -217,6 +217,19 @@ def initialise_test(type_, identifier): return "{} {} = NULL_PTR; /* todo: probably requires finetuning */".format(type_, identifier) +def initialise_verify(type_, identifier): + """used to initialise the verification variables used in tests, typically set to something else than the test + initialise variables :)""" + if type_ in ("CK_SESSION_HANDLE", "CK_SLOT_ID", "CK_OBJECT_HANDLE", "CK_ULONG", "CK_MECHANISM_TYPE", "CK_USER_TYPE", "CK_FLAGS", "CK_BBOOL"): + return "{} {} = 0;".format(type_, identifier) + elif type_ in type_test_templates: + return type_test_templates[type_].format(identifier=identifier, type_=type_) + elif not type_.endswith("_PTR"): + return "{} {} = NULL; /* todo: probably requires finetuning */".format(type_, identifier) + else: + return "{} {} = NULL_PTR; /* todo: probably requires finetuning */".format(type_, identifier) + + def free(type_, identifier): if type_ == "CK_ATTRIBUTE_PTR": return "free({});\n".format(identifier) diff --git a/generate/generate.py b/generate/generate.py index af7446e..fbc3775 100644 --- a/generate/generate.py +++ b/generate/generate.py @@ -10,7 +10,8 @@ from asn1ate.sema import dependency_sort from jinja2 import Environment, FileSystemLoader, StrictUndefined -from filters import combined_args, under, extract_args, initialise, free, is_pointer, depointerize, initialise_test, is_notify +from filters import combined_args, under, extract_args, initialise, free, is_pointer, depointerize, initialise_test,\ + is_notify, initialise_verify # not required in pkcs11 or not exposed @@ -101,6 +102,7 @@ def main(pickle_file): env.globals['extract_args'] = extract_args env.globals['initialise'] = initialise env.globals['initialise_test'] = initialise_test + env.globals['initialise_verify'] = initialise_verify env.globals['free'] = free data = load_data(pickle_file) diff --git a/generate/templates/test/test_pack.c b/generate/templates/test/test_pack.c index 2b6645a..9329819 100644 --- a/generate/templates/test/test_pack.c +++ b/generate/templates/test/test_pack.c @@ -29,8 +29,7 @@ void test_pack_{{ f.type_name|under }}(void **state) { assert_int_equal(status, CKR_OK); {% for type_, pointerized, identifier, other in extract_args(f, o) -%} - //{{ initialise(type_, identifier + "_unpack") }} - {{ type_ }} {{ identifier }}_unpack; + {{ initialise_verify(type_, identifier + "_unpack") }} {% endfor %} status = unpack_{{ f.type_name|under }}( @@ -61,7 +60,7 @@ void test_pack_{{ f.type_name|under }}(void **state) { int main(void) { const struct CMUnitTest tests[] = { - {% for f in functions[:2] %} + {% for f in functions[:4] %} cmocka_unit_test(test_pack_{{ f.type_name|under }}){% if not loop.last %},{% endif -%} {% endfor %} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be106ab..69379f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,9 @@ set(LIB_H static/util.h static/returncodes.h static/derput.h - static/derget.h) + static/derget.h + static/nedtrie.h + ) set(LIB_SRC generated/pack.c @@ -39,10 +41,11 @@ enable_testing() add_executable(client.test generated/test/test_client.c) add_executable(pack.test generated/test/test_pack.c) - +#add_executable(server.test generated/test/test_server.c) add_dependencies(client.test client.test) add_dependencies(pack.test pack.test) +#add_dependencies(server.test server.test) set(KEEHIVE_TEST_LINK_LIRARIES @@ -52,7 +55,8 @@ set(KEEHIVE_TEST_LINK_LIRARIES target_link_libraries(client.test keehive ${KEEHIVE_TEST_LINK_LIRARIES}) target_link_libraries(pack.test keehive ${KEEHIVE_TEST_LINK_LIRARIES}) - +#target_link_libraries(server.test keehive ${KEEHIVE_TEST_LINK_LIRARIES}) add_test(client.test client.test) add_test(pack.test pack.test) +#add_test(server.test server.test) \ No newline at end of file diff --git a/src/generated/test/test_pack.c b/src/generated/test/test_pack.c index 9a0d017..8d99ffa 100644 --- a/src/generated/test/test_pack.c +++ b/src/generated/test/test_pack.c @@ -24,8 +24,7 @@ void test_pack_C_CancelFunction_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_CancelFunction_Call( @@ -60,8 +59,7 @@ void test_pack_C_CancelFunction_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_CancelFunction_Return( @@ -98,8 +96,7 @@ void test_pack_C_CloseAllSessions_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; + CK_SLOT_ID slotID_unpack = 0; status = unpack_C_CloseAllSessions_Call( @@ -134,8 +131,7 @@ void test_pack_C_CloseAllSessions_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_CloseAllSessions_Return( @@ -172,8 +168,7 @@ void test_pack_C_CloseSession_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_CloseSession_Call( @@ -208,8 +203,7 @@ void test_pack_C_CloseSession_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_CloseSession_Return( @@ -254,14 +248,12 @@ void test_pack_C_CopyObject_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hObject_unpack = 0; - CK_OBJECT_HANDLE hObject_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hObject_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_CopyObject_Call( @@ -310,10 +302,8 @@ void test_pack_C_CopyObject_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phObject_unpack = 0; - CK_OBJECT_HANDLE phObject_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phObject_unpack = 0; status = unpack_C_CopyObject_Return( @@ -360,12 +350,11 @@ void test_pack_C_CreateObject_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_CreateObject_Call( @@ -410,10 +399,8 @@ void test_pack_C_CreateObject_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phObject_unpack = 0; - CK_OBJECT_HANDLE phObject_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phObject_unpack = 0; status = unpack_C_CreateObject_Return( @@ -460,14 +447,10 @@ void test_pack_C_Decrypt_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pEncryptedData_unpack = NULL; - CK_BYTE_ARRAY pEncryptedData_unpack; - //CK_ULONG ulEncryptedDataLen_unpack = 0; - CK_ULONG ulEncryptedDataLen_unpack; - //CK_ULONG pulDataLen_unpack = 0; - CK_ULONG pulDataLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pEncryptedData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulEncryptedDataLen_unpack = 0; + CK_ULONG pulDataLen_unpack = 0; status = unpack_C_Decrypt_Call( @@ -518,12 +501,9 @@ void test_pack_C_Decrypt_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG pulDataLen_unpack = 0; - CK_ULONG pulDataLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulDataLen_unpack = 0; status = unpack_C_Decrypt_Return( @@ -574,14 +554,10 @@ void test_pack_C_DecryptDigestUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG ulEncryptedPartLen_unpack = 0; - CK_ULONG ulEncryptedPartLen_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulEncryptedPartLen_unpack = 0; + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptDigestUpdate_Call( @@ -632,12 +608,9 @@ void test_pack_C_DecryptDigestUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptDigestUpdate_Return( @@ -684,10 +657,8 @@ void test_pack_C_DecryptFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG pulLastPartLen_unpack = 0; - CK_ULONG pulLastPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG pulLastPartLen_unpack = 0; status = unpack_C_DecryptFinal_Call( @@ -730,12 +701,9 @@ void test_pack_C_DecryptFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pLastPart_unpack = NULL; - CK_BYTE_ARRAY pLastPart_unpack; - //CK_ULONG pulLastPartLen_unpack = 0; - CK_ULONG pulLastPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pLastPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulLastPartLen_unpack = 0; status = unpack_C_DecryptFinal_Return( @@ -785,12 +753,10 @@ void test_pack_C_DecryptInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_DecryptInit_Call( @@ -833,8 +799,7 @@ void test_pack_C_DecryptInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_DecryptInit_Return( @@ -877,14 +842,10 @@ void test_pack_C_DecryptUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG ulEncryptedPartLen_unpack = 0; - CK_ULONG ulEncryptedPartLen_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulEncryptedPartLen_unpack = 0; + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptUpdate_Call( @@ -935,12 +896,9 @@ void test_pack_C_DecryptUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptUpdate_Return( @@ -991,14 +949,10 @@ void test_pack_C_DecryptVerifyUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG ulEncryptedPartLen_unpack = 0; - CK_ULONG ulEncryptedPartLen_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulEncryptedPartLen_unpack = 0; + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptVerifyUpdate_Call( @@ -1049,12 +1003,9 @@ void test_pack_C_DecryptVerifyUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG pulPartLen_unpack = 0; - CK_ULONG pulPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulPartLen_unpack = 0; status = unpack_C_DecryptVerifyUpdate_Return( @@ -1110,16 +1061,14 @@ void test_pack_C_DeriveKey_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hBaseKey_unpack = 0; - CK_OBJECT_HANDLE hBaseKey_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulAttributeCount_unpack = 0; - CK_ULONG ulAttributeCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hBaseKey_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulAttributeCount_unpack = 0; status = unpack_C_DeriveKey_Call( @@ -1172,10 +1121,8 @@ void test_pack_C_DeriveKey_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phKey_unpack = 0; - CK_OBJECT_HANDLE phKey_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phKey_unpack = 0; status = unpack_C_DeriveKey_Return( @@ -1218,10 +1165,8 @@ void test_pack_C_DestroyObject_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hObject_unpack = 0; - CK_OBJECT_HANDLE hObject_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hObject_unpack = 0; status = unpack_C_DestroyObject_Call( @@ -1260,8 +1205,7 @@ void test_pack_C_DestroyObject_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_DestroyObject_Return( @@ -1304,14 +1248,10 @@ void test_pack_C_Digest_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG ulDataLen_unpack = 0; - CK_ULONG ulDataLen_unpack; - //CK_ULONG pulDigestLen_unpack = 0; - CK_ULONG pulDigestLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulDataLen_unpack = 0; + CK_ULONG pulDigestLen_unpack = 0; status = unpack_C_Digest_Call( @@ -1362,12 +1302,9 @@ void test_pack_C_Digest_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pDigest_unpack = NULL; - CK_BYTE_ARRAY pDigest_unpack; - //CK_ULONG pulDigestLen_unpack = 0; - CK_ULONG pulDigestLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pDigest_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulDigestLen_unpack = 0; status = unpack_C_Digest_Return( @@ -1418,14 +1355,10 @@ void test_pack_C_DigestEncryptUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_DigestEncryptUpdate_Call( @@ -1476,12 +1409,9 @@ void test_pack_C_DigestEncryptUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_DigestEncryptUpdate_Return( @@ -1528,10 +1458,8 @@ void test_pack_C_DigestFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG pulDigestLen_unpack = 0; - CK_ULONG pulDigestLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG pulDigestLen_unpack = 0; status = unpack_C_DigestFinal_Call( @@ -1574,12 +1502,9 @@ void test_pack_C_DigestFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pDigest_unpack = NULL; - CK_BYTE_ARRAY pDigest_unpack; - //CK_ULONG pulDigestLen_unpack = 0; - CK_ULONG pulDigestLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pDigest_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulDigestLen_unpack = 0; status = unpack_C_DigestFinal_Return( @@ -1627,10 +1552,9 @@ void test_pack_C_DigestInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; status = unpack_C_DigestInit_Call( @@ -1669,8 +1593,7 @@ void test_pack_C_DigestInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_DigestInit_Return( @@ -1709,10 +1632,8 @@ void test_pack_C_DigestKey_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_DigestKey_Call( @@ -1751,8 +1672,7 @@ void test_pack_C_DigestKey_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_DigestKey_Return( @@ -1793,12 +1713,9 @@ void test_pack_C_DigestUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; status = unpack_C_DigestUpdate_Call( @@ -1841,8 +1758,7 @@ void test_pack_C_DigestUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_DigestUpdate_Return( @@ -1885,14 +1801,10 @@ void test_pack_C_Encrypt_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG ulDataLen_unpack = 0; - CK_ULONG ulDataLen_unpack; - //CK_ULONG pulEncryptedDataLen_unpack = 0; - CK_ULONG pulEncryptedDataLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulDataLen_unpack = 0; + CK_ULONG pulEncryptedDataLen_unpack = 0; status = unpack_C_Encrypt_Call( @@ -1943,12 +1855,9 @@ void test_pack_C_Encrypt_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pEncryptedData_unpack = NULL; - CK_BYTE_ARRAY pEncryptedData_unpack; - //CK_ULONG pulEncryptedDataLen_unpack = 0; - CK_ULONG pulEncryptedDataLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pEncryptedData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulEncryptedDataLen_unpack = 0; status = unpack_C_Encrypt_Return( @@ -1995,10 +1904,8 @@ void test_pack_C_EncryptFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG pulEncryptedDataLen_unpack = 0; - CK_ULONG pulEncryptedDataLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG pulEncryptedDataLen_unpack = 0; status = unpack_C_EncryptFinal_Call( @@ -2041,12 +1948,9 @@ void test_pack_C_EncryptFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pEncryptedData_unpack = NULL; - CK_BYTE_ARRAY pEncryptedData_unpack; - //CK_ULONG pulEncryptedDataLen_unpack = 0; - CK_ULONG pulEncryptedDataLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pEncryptedData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulEncryptedDataLen_unpack = 0; status = unpack_C_EncryptFinal_Return( @@ -2096,12 +2000,10 @@ void test_pack_C_EncryptInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_EncryptInit_Call( @@ -2144,8 +2046,7 @@ void test_pack_C_EncryptInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_EncryptInit_Return( @@ -2188,14 +2089,10 @@ void test_pack_C_EncryptUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_EncryptUpdate_Call( @@ -2246,12 +2143,9 @@ void test_pack_C_EncryptUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_EncryptUpdate_Return( @@ -2296,8 +2190,7 @@ void test_pack_C_Finalize_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_VOID_PTR pReserved_unpack = NULL_PTR; - CK_VOID_PTR pReserved_unpack; + CK_VOID_PTR pReserved_unpack = NULL_PTR; /* todo: probably requires finetuning */ status = unpack_C_Finalize_Call( @@ -2334,10 +2227,8 @@ void test_pack_C_Finalize_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //ANY pReserved_unpack = NULL; - ANY pReserved_unpack; + CK_RV retval_unpack = CKR_OK; + ANY pReserved_unpack = NULL; /* todo: probably requires finetuning */ status = unpack_C_Finalize_Return( @@ -2380,10 +2271,8 @@ void test_pack_C_FindObjects_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG ulMaxObjectCount_unpack = 0; - CK_ULONG ulMaxObjectCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG ulMaxObjectCount_unpack = 0; status = unpack_C_FindObjects_Call( @@ -2426,12 +2315,9 @@ void test_pack_C_FindObjects_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE_ARRAY phObject_unpack = NULL; - CK_OBJECT_HANDLE_ARRAY phObject_unpack; - //CK_ULONG pulObjectCount_unpack = 0; - CK_ULONG pulObjectCount_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE_ARRAY phObject_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulObjectCount_unpack = 0; status = unpack_C_FindObjects_Return( @@ -2476,8 +2362,7 @@ void test_pack_C_FindObjectsFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_FindObjectsFinal_Call( @@ -2512,8 +2397,7 @@ void test_pack_C_FindObjectsFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_FindObjectsFinal_Return( @@ -2556,12 +2440,11 @@ void test_pack_C_FindObjectsInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_FindObjectsInit_Call( @@ -2608,10 +2491,10 @@ void test_pack_C_FindObjectsInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; + CK_RV retval_unpack = CKR_OK; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; status = unpack_C_FindObjectsInit_Return( @@ -2661,14 +2544,13 @@ void test_pack_C_GenerateKey_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_GenerateKey_Call( @@ -2717,10 +2599,8 @@ void test_pack_C_GenerateKey_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phKey_unpack = 0; - CK_OBJECT_HANDLE phKey_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phKey_unpack = 0; status = unpack_C_GenerateKey_Return( @@ -2776,18 +2656,17 @@ void test_pack_C_GenerateKeyPair_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_ATTRIBUTE_ARRAY pPublicKeyTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pPublicKeyTemplate_unpack; - //CK_ULONG ulPublicKeyAttributeCount_unpack = 0; - CK_ULONG ulPublicKeyAttributeCount_unpack; - //CK_ATTRIBUTE_ARRAY pPrivateKeyTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pPrivateKeyTemplate_unpack; - //CK_ULONG ulPrivateKeyAttributeCount_unpack = 0; - CK_ULONG ulPrivateKeyAttributeCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_UTF8CHAR pPublicKeyTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pPublicKeyTemplate_unpack[] = { + {CKA_LABEL, pPublicKeyTemplate_unpack_label, sizeof(pPublicKeyTemplate_unpack_label)-1} }; + CK_ULONG ulPublicKeyAttributeCount_unpack = 0; + CK_UTF8CHAR pPrivateKeyTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pPrivateKeyTemplate_unpack[] = { + {CKA_LABEL, pPrivateKeyTemplate_unpack_label, sizeof(pPrivateKeyTemplate_unpack_label)-1} }; + CK_ULONG ulPrivateKeyAttributeCount_unpack = 0; status = unpack_C_GenerateKeyPair_Call( @@ -2846,12 +2725,9 @@ void test_pack_C_GenerateKeyPair_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phPublicKey_unpack = 0; - CK_OBJECT_HANDLE phPublicKey_unpack; - //CK_OBJECT_HANDLE phPrivateKey_unpack = 0; - CK_OBJECT_HANDLE phPrivateKey_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phPublicKey_unpack = 0; + CK_OBJECT_HANDLE phPrivateKey_unpack = 0; status = unpack_C_GenerateKeyPair_Return( @@ -2898,10 +2774,8 @@ void test_pack_C_GenerateRandom_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG ulRandomLen_unpack = 0; - CK_ULONG ulRandomLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG ulRandomLen_unpack = 0; status = unpack_C_GenerateRandom_Call( @@ -2942,10 +2816,8 @@ void test_pack_C_GenerateRandom_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pSeed_unpack = NULL; - CK_BYTE_ARRAY pSeed_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pSeed_unpack = NULL; /* todo: probably requires finetuning */ status = unpack_C_GenerateRandom_Return( @@ -2994,14 +2866,12 @@ void test_pack_C_GetAttributeValue_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hObject_unpack = 0; - CK_OBJECT_HANDLE hObject_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hObject_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_GetAttributeValue_Call( @@ -3052,10 +2922,10 @@ void test_pack_C_GetAttributeValue_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; + CK_RV retval_unpack = CKR_OK; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; status = unpack_C_GetAttributeValue_Return( @@ -3096,8 +2966,7 @@ void test_pack_C_GetFunctionStatus_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_GetFunctionStatus_Call( @@ -3132,8 +3001,7 @@ void test_pack_C_GetFunctionStatus_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_GetFunctionStatus_Return( @@ -3206,10 +3074,14 @@ void test_pack_C_GetInfo_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_INFO pInfo_unpack = NULL; - CK_INFO pInfo_unpack; + CK_RV retval_unpack = CKR_OK; + CK_INFO pInfo_unpack = { .cryptokiVersion.major = 1, + .cryptokiVersion.minor = 1, + .manufacturerID = "gijs", + .flags = 1, + .libraryDescription = "gijs", + .libraryVersion.major = 1, + .libraryVersion.minor = 1 }; status = unpack_C_GetInfo_Return( @@ -3253,10 +3125,8 @@ void test_pack_C_GetMechanismInfo_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; - //CK_MECHANISM_TYPE type_unpack = 0; - CK_MECHANISM_TYPE type_unpack; + CK_SLOT_ID slotID_unpack = 0; + CK_MECHANISM_TYPE type_unpack = 0; status = unpack_C_GetMechanismInfo_Call( @@ -3299,10 +3169,10 @@ void test_pack_C_GetMechanismInfo_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_MECHANISM_INFO pInfo_unpack = NULL; - CK_MECHANISM_INFO pInfo_unpack; + CK_RV retval_unpack = CKR_OK; + CK_MECHANISM_INFO pInfo_unpack = { .ulMinKeySize = 1, + .ulMaxKeySize = 1, + .flags = 1 }; status = unpack_C_GetMechanismInfo_Return( @@ -3346,10 +3216,8 @@ void test_pack_C_GetMechanismList_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; - //CK_ULONG pulCount_unpack = 0; - CK_ULONG pulCount_unpack; + CK_SLOT_ID slotID_unpack = 0; + CK_ULONG pulCount_unpack = 0; status = unpack_C_GetMechanismList_Call( @@ -3392,12 +3260,9 @@ void test_pack_C_GetMechanismList_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_MECHANISM_TYPE_ARRAY pMechanismList_unpack = NULL; - CK_MECHANISM_TYPE_ARRAY pMechanismList_unpack; - //CK_ULONG pulCount_unpack = 0; - CK_ULONG pulCount_unpack; + CK_RV retval_unpack = CKR_OK; + CK_MECHANISM_TYPE_ARRAY pMechanismList_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulCount_unpack = 0; status = unpack_C_GetMechanismList_Return( @@ -3444,10 +3309,8 @@ void test_pack_C_GetObjectSize_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hObject_unpack = 0; - CK_OBJECT_HANDLE hObject_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hObject_unpack = 0; status = unpack_C_GetObjectSize_Call( @@ -3488,10 +3351,8 @@ void test_pack_C_GetObjectSize_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_ULONG pulSize_unpack = 0; - CK_ULONG pulSize_unpack; + CK_RV retval_unpack = CKR_OK; + CK_ULONG pulSize_unpack = 0; status = unpack_C_GetObjectSize_Return( @@ -3534,10 +3395,8 @@ void test_pack_C_GetOperationState_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG pulOperationStateLen_unpack = 0; - CK_ULONG pulOperationStateLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG pulOperationStateLen_unpack = 0; status = unpack_C_GetOperationState_Call( @@ -3580,12 +3439,9 @@ void test_pack_C_GetOperationState_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pOperationState_unpack = NULL; - CK_BYTE_ARRAY pOperationState_unpack; - //CK_ULONG pulOperationStateLen_unpack = 0; - CK_ULONG pulOperationStateLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pOperationState_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulOperationStateLen_unpack = 0; status = unpack_C_GetOperationState_Return( @@ -3630,8 +3486,7 @@ void test_pack_C_GetSessionInfo_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_GetSessionInfo_Call( @@ -3668,10 +3523,8 @@ void test_pack_C_GetSessionInfo_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_SESSION_INFO pInfo_unpack = NULL; - CK_SESSION_INFO pInfo_unpack; + CK_RV retval_unpack = CKR_OK; + CK_SESSION_INFO pInfo_unpack = { .slotID = 1, .state = 1, .flags = 1 }; status = unpack_C_GetSessionInfo_Return( @@ -3713,8 +3566,7 @@ void test_pack_C_GetSlotInfo_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; + CK_SLOT_ID slotID_unpack = 0; status = unpack_C_GetSlotInfo_Call( @@ -3757,10 +3609,14 @@ void test_pack_C_GetSlotInfo_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_SLOT_INFO pInfo_unpack = NULL; - CK_SLOT_INFO pInfo_unpack; + CK_RV retval_unpack = CKR_OK; + CK_SLOT_INFO pInfo_unpack = { .slotDescription = "gijs", + .manufacturerID = "gijs", + .flags = 1, + .hardwareVersion.major = 1, + .hardwareVersion.minor = 1, + .firmwareVersion.major = 1, + .firmwareVersion.minor = 1 }; status = unpack_C_GetSlotInfo_Return( @@ -3804,10 +3660,8 @@ void test_pack_C_GetSlotList_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_BBOOL tokenPresent_unpack = 0; - CK_BBOOL tokenPresent_unpack; - //CK_ULONG pulCount_unpack = 0; - CK_ULONG pulCount_unpack; + CK_BBOOL tokenPresent_unpack = 0; + CK_ULONG pulCount_unpack = 0; status = unpack_C_GetSlotList_Call( @@ -3850,12 +3704,9 @@ void test_pack_C_GetSlotList_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_SLOT_ID_ARRAY pSlotList_unpack = NULL; - CK_SLOT_ID_ARRAY pSlotList_unpack; - //CK_ULONG pulCount_unpack = 0; - CK_ULONG pulCount_unpack; + CK_RV retval_unpack = CKR_OK; + CK_SLOT_ID_ARRAY pSlotList_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulCount_unpack = 0; status = unpack_C_GetSlotList_Return( @@ -3900,8 +3751,7 @@ void test_pack_C_GetTokenInfo_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; + CK_SLOT_ID slotID_unpack = 0; status = unpack_C_GetTokenInfo_Call( @@ -3958,10 +3808,28 @@ void test_pack_C_GetTokenInfo_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_TOKEN_INFO pInfo_unpack = NULL; - CK_TOKEN_INFO pInfo_unpack; + CK_RV retval_unpack = CKR_OK; + CK_TOKEN_INFO pInfo_unpack = { + .label = "labeltje", + .manufacturerID = "manufacturetje", + .model = "modeletje", + .serialNumber = "serialletje", + .flags = 10, + .ulMaxSessionCount = 1, + .ulSessionCount = 2, + .ulMaxRwSessionCount = 3, + .ulRwSessionCount = 4, + .ulMaxPinLen = 5, + .ulMinPinLen = 6, + .ulTotalPublicMemory = 7, + .ulFreePublicMemory = 8, + .ulTotalPrivateMemory = 9, + .ulFreePrivateMemory = 10, + .hardwareVersion.major = 11, + .hardwareVersion.minor = 12, + .firmwareVersion.major = 13, + .firmwareVersion.minor = 14, + .utcTime = "gijs time" }; status = unpack_C_GetTokenInfo_Return( @@ -4007,12 +3875,9 @@ void test_pack_C_InitPIN_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_UTF8CHAR_ARRAY pPin_unpack = NULL; - CK_UTF8CHAR_ARRAY pPin_unpack; - //CK_ULONG ulPinLen_unpack = 0; - CK_ULONG ulPinLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_UTF8CHAR_ARRAY pPin_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPinLen_unpack = 0; status = unpack_C_InitPIN_Call( @@ -4055,8 +3920,7 @@ void test_pack_C_InitPIN_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_InitPIN_Return( @@ -4099,14 +3963,10 @@ void test_pack_C_InitToken_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; - //UTF8String pPin_unpack = NULL; - UTF8String pPin_unpack; - //CK_ULONG ulPinLen_unpack = 0; - CK_ULONG ulPinLen_unpack; - //UTF8String pLabel_unpack = NULL; - UTF8String pLabel_unpack; + CK_SLOT_ID slotID_unpack = 0; + UTF8String pPin_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPinLen_unpack = 0; + UTF8String pLabel_unpack = NULL; /* todo: probably requires finetuning */ status = unpack_C_InitToken_Call( @@ -4153,8 +4013,7 @@ void test_pack_C_InitToken_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_InitToken_Return( @@ -4191,8 +4050,7 @@ void test_pack_C_Initialize_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_C_INITIALIZE_ARGS_PTR pInitArgs_unpack = NULL_PTR; - CK_C_INITIALIZE_ARGS_PTR pInitArgs_unpack; + CK_C_INITIALIZE_ARGS_PTR pInitArgs_unpack = NULL_PTR; /* todo: probably requires finetuning */ status = unpack_C_Initialize_Call( @@ -4229,10 +4087,8 @@ void test_pack_C_Initialize_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //ANY pInitArgs_unpack = NULL; - ANY pInitArgs_unpack; + CK_RV retval_unpack = CKR_OK; + ANY pInitArgs_unpack = NULL; /* todo: probably requires finetuning */ status = unpack_C_Initialize_Return( @@ -4279,14 +4135,10 @@ void test_pack_C_Login_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_USER_TYPE userType_unpack = 0; - CK_USER_TYPE userType_unpack; - //CK_UTF8CHAR_ARRAY pPin_unpack = NULL; - CK_UTF8CHAR_ARRAY pPin_unpack; - //CK_ULONG ulPinLen_unpack = 0; - CK_ULONG ulPinLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_USER_TYPE userType_unpack = 0; + CK_UTF8CHAR_ARRAY pPin_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPinLen_unpack = 0; status = unpack_C_Login_Call( @@ -4333,8 +4185,7 @@ void test_pack_C_Login_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_Login_Return( @@ -4371,8 +4222,7 @@ void test_pack_C_Logout_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; status = unpack_C_Logout_Call( @@ -4407,8 +4257,7 @@ void test_pack_C_Logout_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_Logout_Return( @@ -4451,14 +4300,10 @@ void test_pack_C_OpenSession_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SLOT_ID slotID_unpack = 0; - CK_SLOT_ID slotID_unpack; - //CK_FLAGS flags_unpack = 0; - CK_FLAGS flags_unpack; - //ANY pApplication_unpack = NULL; - ANY pApplication_unpack; - //CK_NOTIFY notify_unpack = NULL; - CK_NOTIFY notify_unpack; + CK_SLOT_ID slotID_unpack = 0; + CK_FLAGS flags_unpack = 0; + ANY pApplication_unpack = NULL; /* todo: probably requires finetuning */ + CK_NOTIFY notify_unpack = NULL; /* todo: probably requires finetuning */ status = unpack_C_OpenSession_Call( @@ -4507,10 +4352,8 @@ void test_pack_C_OpenSession_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_SESSION_HANDLE phSession_unpack = 0; - CK_SESSION_HANDLE phSession_unpack; + CK_RV retval_unpack = CKR_OK; + CK_SESSION_HANDLE phSession_unpack = 0; status = unpack_C_OpenSession_Return( @@ -4555,12 +4398,9 @@ void test_pack_C_SeedRandom_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pSeed_unpack = NULL; - CK_BYTE_ARRAY pSeed_unpack; - //CK_ULONG ulSeedLen_unpack = 0; - CK_ULONG ulSeedLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pSeed_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulSeedLen_unpack = 0; status = unpack_C_SeedRandom_Call( @@ -4603,8 +4443,7 @@ void test_pack_C_SeedRandom_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SeedRandom_Return( @@ -4649,14 +4488,12 @@ void test_pack_C_SetAttributeValue_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_OBJECT_HANDLE hObject_unpack = 0; - CK_OBJECT_HANDLE hObject_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulCount_unpack = 0; - CK_ULONG ulCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_OBJECT_HANDLE hObject_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulCount_unpack = 0; status = unpack_C_SetAttributeValue_Call( @@ -4703,8 +4540,7 @@ void test_pack_C_SetAttributeValue_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SetAttributeValue_Return( @@ -4749,16 +4585,11 @@ void test_pack_C_SetOperationState_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pOperationState_unpack = NULL; - CK_BYTE_ARRAY pOperationState_unpack; - //CK_ULONG ulOperationStateLen_unpack = 0; - CK_ULONG ulOperationStateLen_unpack; - //CK_OBJECT_HANDLE hEncryptionKey_unpack = 0; - CK_OBJECT_HANDLE hEncryptionKey_unpack; - //CK_OBJECT_HANDLE hAuthenticationKey_unpack = 0; - CK_OBJECT_HANDLE hAuthenticationKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pOperationState_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulOperationStateLen_unpack = 0; + CK_OBJECT_HANDLE hEncryptionKey_unpack = 0; + CK_OBJECT_HANDLE hAuthenticationKey_unpack = 0; status = unpack_C_SetOperationState_Call( @@ -4809,8 +4640,7 @@ void test_pack_C_SetOperationState_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SetOperationState_Return( @@ -4855,16 +4685,11 @@ void test_pack_C_SetPIN_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_UTF8CHAR_ARRAY pOldPin_unpack = NULL; - CK_UTF8CHAR_ARRAY pOldPin_unpack; - //CK_ULONG ulOldLen_unpack = 0; - CK_ULONG ulOldLen_unpack; - //CK_UTF8CHAR_ARRAY pNewPin_unpack = NULL; - CK_UTF8CHAR_ARRAY pNewPin_unpack; - //CK_ULONG ulNewPin_unpack = 0; - CK_ULONG ulNewPin_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_UTF8CHAR_ARRAY pOldPin_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulOldLen_unpack = 0; + CK_UTF8CHAR_ARRAY pNewPin_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulNewPin_unpack = 0; status = unpack_C_SetPIN_Call( @@ -4915,8 +4740,7 @@ void test_pack_C_SetPIN_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SetPIN_Return( @@ -4959,14 +4783,10 @@ void test_pack_C_Sign_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG ulDataLen_unpack = 0; - CK_ULONG ulDataLen_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulDataLen_unpack = 0; + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_Sign_Call( @@ -5017,12 +4837,9 @@ void test_pack_C_Sign_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_Sign_Return( @@ -5073,14 +4890,10 @@ void test_pack_C_SignEncryptUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_SignEncryptUpdate_Call( @@ -5131,12 +4944,9 @@ void test_pack_C_SignEncryptUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; - CK_BYTE_ARRAY pEncryptedPart_unpack; - //CK_ULONG pulEncryptedPartLen_unpack = 0; - CK_ULONG pulEncryptedPartLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pEncryptedPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulEncryptedPartLen_unpack = 0; status = unpack_C_SignEncryptUpdate_Return( @@ -5183,10 +4993,8 @@ void test_pack_C_SignFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_SignFinal_Call( @@ -5229,12 +5037,9 @@ void test_pack_C_SignFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_SignFinal_Return( @@ -5284,12 +5089,10 @@ void test_pack_C_SignInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_SignInit_Call( @@ -5332,8 +5135,7 @@ void test_pack_C_SignInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SignInit_Return( @@ -5376,14 +5178,10 @@ void test_pack_C_SignRecover_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG ulDataLen_unpack = 0; - CK_ULONG ulDataLen_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulDataLen_unpack = 0; + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_SignRecover_Call( @@ -5434,12 +5232,9 @@ void test_pack_C_SignRecover_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG pulSignatureLen_unpack = 0; - CK_ULONG pulSignatureLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulSignatureLen_unpack = 0; status = unpack_C_SignRecover_Return( @@ -5489,12 +5284,10 @@ void test_pack_C_SignRecoverInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_SignRecoverInit_Call( @@ -5537,8 +5330,7 @@ void test_pack_C_SignRecoverInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SignRecoverInit_Return( @@ -5579,12 +5371,9 @@ void test_pack_C_SignUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; status = unpack_C_SignUpdate_Call( @@ -5627,8 +5416,7 @@ void test_pack_C_SignUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_SignUpdate_Return( @@ -5680,20 +5468,16 @@ void test_pack_C_UnwrapKey_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hUnwrappingKey_unpack = 0; - CK_OBJECT_HANDLE hUnwrappingKey_unpack; - //CK_BYTE_ARRAY pWrappedKey_unpack = NULL; - CK_BYTE_ARRAY pWrappedKey_unpack; - //CK_ULONG ulWrappedKeyLen_unpack = 0; - CK_ULONG ulWrappedKeyLen_unpack; - //CK_ATTRIBUTE_ARRAY pTemplate_unpack = NULL; - CK_ATTRIBUTE_ARRAY pTemplate_unpack; - //CK_ULONG ulAttributeCount_unpack = 0; - CK_ULONG ulAttributeCount_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hUnwrappingKey_unpack = 0; + CK_BYTE_ARRAY pWrappedKey_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulWrappedKeyLen_unpack = 0; + CK_UTF8CHAR pTemplate_unpack_label[] = "Just a simple attribute array"; + CK_ATTRIBUTE pTemplate_unpack[] = { + {CKA_LABEL, pTemplate_unpack_label, sizeof(pTemplate_unpack_label)-1} }; + CK_ULONG ulAttributeCount_unpack = 0; status = unpack_C_UnwrapKey_Call( @@ -5754,10 +5538,8 @@ void test_pack_C_UnwrapKey_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_OBJECT_HANDLE phKey_unpack = 0; - CK_OBJECT_HANDLE phKey_unpack; + CK_RV retval_unpack = CKR_OK; + CK_OBJECT_HANDLE phKey_unpack = 0; status = unpack_C_UnwrapKey_Return( @@ -5806,16 +5588,11 @@ void test_pack_C_Verify_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG ulDataLen_unpack = 0; - CK_ULONG ulDataLen_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG ulSignatureLen_unpack = 0; - CK_ULONG ulSignatureLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulDataLen_unpack = 0; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulSignatureLen_unpack = 0; status = unpack_C_Verify_Call( @@ -5866,8 +5643,7 @@ void test_pack_C_Verify_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_Verify_Return( @@ -5908,12 +5684,9 @@ void test_pack_C_VerifyFinal_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG ulSignatureLen_unpack = 0; - CK_ULONG ulSignatureLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulSignatureLen_unpack = 0; status = unpack_C_VerifyFinal_Call( @@ -5956,8 +5729,7 @@ void test_pack_C_VerifyFinal_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_VerifyFinal_Return( @@ -5999,12 +5771,10 @@ void test_pack_C_VerifyInit_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hKey_unpack = 0; status = unpack_C_VerifyInit_Call( @@ -6047,8 +5817,7 @@ void test_pack_C_VerifyInit_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_VerifyInit_Return( @@ -6091,14 +5860,10 @@ void test_pack_C_VerifyRecover_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pSignature_unpack = NULL; - CK_BYTE_ARRAY pSignature_unpack; - //CK_ULONG ulSignatureLen_unpack = 0; - CK_ULONG ulSignatureLen_unpack; - //CK_ULONG pulDataLen_unpack = 0; - CK_ULONG pulDataLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pSignature_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulSignatureLen_unpack = 0; + CK_ULONG pulDataLen_unpack = 0; status = unpack_C_VerifyRecover_Call( @@ -6149,12 +5914,9 @@ void test_pack_C_VerifyRecover_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pData_unpack = NULL; - CK_BYTE_ARRAY pData_unpack; - //CK_ULONG pulDataLen_unpack = 0; - CK_ULONG pulDataLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pData_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulDataLen_unpack = 0; status = unpack_C_VerifyRecover_Return( @@ -6203,12 +5965,9 @@ void test_pack_C_VerifyUpdate_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_BYTE_ARRAY pPart_unpack = NULL; - CK_BYTE_ARRAY pPart_unpack; - //CK_ULONG ulPartLen_unpack = 0; - CK_ULONG ulPartLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_BYTE_ARRAY pPart_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG ulPartLen_unpack = 0; status = unpack_C_VerifyUpdate_Call( @@ -6251,8 +6010,7 @@ void test_pack_C_VerifyUpdate_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; + CK_RV retval_unpack = CKR_OK; status = unpack_C_VerifyUpdate_Return( @@ -6291,10 +6049,8 @@ void test_pack_C_WaitForSlotEvent_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_FLAGS flags_unpack = 0; - CK_FLAGS flags_unpack; - //CK_VOID_PTR pReserved_unpack = NULL_PTR; - CK_VOID_PTR pReserved_unpack; + CK_FLAGS flags_unpack = 0; + CK_VOID_PTR pReserved_unpack = NULL_PTR; /* todo: probably requires finetuning */ status = unpack_C_WaitForSlotEvent_Call( @@ -6337,12 +6093,9 @@ void test_pack_C_WaitForSlotEvent_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_SLOT_ID pSlot_unpack = 0; - CK_SLOT_ID pSlot_unpack; - //CK_VOID_PTR pReserved_unpack = NULL_PTR; - CK_VOID_PTR pReserved_unpack; + CK_RV retval_unpack = CKR_OK; + CK_SLOT_ID pSlot_unpack = 0; + CK_VOID_PTR pReserved_unpack = NULL_PTR; /* todo: probably requires finetuning */ status = unpack_C_WaitForSlotEvent_Return( @@ -6396,16 +6149,12 @@ void test_pack_C_WrapKey_Call(void **state) { assert_int_equal(status, CKR_OK); - //CK_SESSION_HANDLE hSession_unpack = 0; - CK_SESSION_HANDLE hSession_unpack; - //CK_MECHANISM_PTR pMechanism_unpack = NULL_PTR; - CK_MECHANISM_PTR pMechanism_unpack; - //CK_OBJECT_HANDLE hWrappingKey_unpack = 0; - CK_OBJECT_HANDLE hWrappingKey_unpack; - //CK_OBJECT_HANDLE hKey_unpack = 0; - CK_OBJECT_HANDLE hKey_unpack; - //CK_ULONG pulWrappedKeyLen_unpack = 0; - CK_ULONG pulWrappedKeyLen_unpack; + CK_SESSION_HANDLE hSession_unpack = 0; + CK_MECHANISM pMechanism_unpack_pointed = {CKM_MD5, NULL_PTR, 0}; + CK_MECHANISM_PTR pMechanism_unpack = &pMechanism_unpack_pointed; + CK_OBJECT_HANDLE hWrappingKey_unpack = 0; + CK_OBJECT_HANDLE hKey_unpack = 0; + CK_ULONG pulWrappedKeyLen_unpack = 0; status = unpack_C_WrapKey_Call( @@ -6460,12 +6209,9 @@ void test_pack_C_WrapKey_Return(void **state) { assert_int_equal(status, CKR_OK); - //CK_RV retval_unpack = NULL; - CK_RV retval_unpack; - //CK_BYTE_ARRAY pWrappedKey_unpack = NULL; - CK_BYTE_ARRAY pWrappedKey_unpack; - //CK_ULONG pulWrappedKeyLen_unpack = 0; - CK_ULONG pulWrappedKeyLen_unpack; + CK_RV retval_unpack = CKR_OK; + CK_BYTE_ARRAY pWrappedKey_unpack = NULL; /* todo: probably requires finetuning */ + CK_ULONG pulWrappedKeyLen_unpack = 0; status = unpack_C_WrapKey_Return( @@ -6499,7 +6245,9 @@ int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_pack_C_CancelFunction_Call), - cmocka_unit_test(test_pack_C_CloseAllSessions_Call) + cmocka_unit_test(test_pack_C_CloseAllSessions_Call), + cmocka_unit_test(test_pack_C_CloseSession_Call), + cmocka_unit_test(test_pack_C_CopyObject_Call) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/src/generated/unpack.c b/src/generated/unpack.c index 117549d..cd94962 100644 --- a/src/generated/unpack.c +++ b/src/generated/unpack.c @@ -697,7 +697,7 @@ unpack_C_CancelFunction_Call( status = der_get_ulong(C_CancelFunction_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -727,7 +727,7 @@ unpack_C_CancelFunction_Return( status = der_get_ulong(C_CancelFunction_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -759,7 +759,7 @@ unpack_C_CloseAllSessions_Call( status = der_get_ulong(C_CloseAllSessions_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -789,7 +789,7 @@ unpack_C_CloseAllSessions_Return( status = der_get_ulong(C_CloseAllSessions_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -821,7 +821,7 @@ unpack_C_CloseSession_Call( status = der_get_ulong(C_CloseSession_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -851,7 +851,7 @@ unpack_C_CloseSession_Return( status = der_get_ulong(C_CloseSession_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -886,25 +886,25 @@ unpack_C_CopyObject_Call( status = der_get_ulong(C_CopyObject_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_CopyObject_Call.hObject, hObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_CopyObject_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_CopyObject_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -935,13 +935,13 @@ unpack_C_CopyObject_Return( status = der_get_ulong(C_CopyObject_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_CopyObject_Return.phObject, phObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -975,19 +975,19 @@ unpack_C_CreateObject_Call( status = der_get_ulong(C_CreateObject_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_CreateObject_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_CreateObject_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1018,13 +1018,13 @@ unpack_C_CreateObject_Return( status = der_get_ulong(C_CreateObject_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_CreateObject_Return.phObject, phObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1059,25 +1059,25 @@ unpack_C_Decrypt_Call( status = der_get_ulong(C_Decrypt_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Decrypt_Call.pEncryptedData, pEncryptedData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Decrypt_Call.ulEncryptedDataLen, ulEncryptedDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Decrypt_Call.pulDataLen, pulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1109,19 +1109,19 @@ unpack_C_Decrypt_Return( status = der_get_ulong(C_Decrypt_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Decrypt_Return.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Decrypt_Return.pulDataLen, pulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1156,25 +1156,25 @@ unpack_C_DecryptDigestUpdate_Call( status = der_get_ulong(C_DecryptDigestUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptDigestUpdate_Call.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptDigestUpdate_Call.ulEncryptedPartLen, ulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptDigestUpdate_Call.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1206,19 +1206,19 @@ unpack_C_DecryptDigestUpdate_Return( status = der_get_ulong(C_DecryptDigestUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptDigestUpdate_Return.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptDigestUpdate_Return.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1251,13 +1251,13 @@ unpack_C_DecryptFinal_Call( status = der_get_ulong(C_DecryptFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptFinal_Call.pulLastPartLen, pulLastPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1289,19 +1289,19 @@ unpack_C_DecryptFinal_Return( status = der_get_ulong(C_DecryptFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptFinal_Return.pLastPart, pLastPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptFinal_Return.pulLastPartLen, pulLastPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1335,19 +1335,19 @@ unpack_C_DecryptInit_Call( status = der_get_ulong(C_DecryptInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_DecryptInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptInit_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1377,7 +1377,7 @@ unpack_C_DecryptInit_Return( status = der_get_ulong(C_DecryptInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1412,25 +1412,25 @@ unpack_C_DecryptUpdate_Call( status = der_get_ulong(C_DecryptUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptUpdate_Call.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptUpdate_Call.ulEncryptedPartLen, ulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptUpdate_Call.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1462,19 +1462,19 @@ unpack_C_DecryptUpdate_Return( status = der_get_ulong(C_DecryptUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptUpdate_Return.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptUpdate_Return.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1509,25 +1509,25 @@ unpack_C_DecryptVerifyUpdate_Call( status = der_get_ulong(C_DecryptVerifyUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptVerifyUpdate_Call.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptVerifyUpdate_Call.ulEncryptedPartLen, ulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptVerifyUpdate_Call.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1559,19 +1559,19 @@ unpack_C_DecryptVerifyUpdate_Return( status = der_get_ulong(C_DecryptVerifyUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DecryptVerifyUpdate_Return.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DecryptVerifyUpdate_Return.pulPartLen, pulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1607,31 +1607,31 @@ unpack_C_DeriveKey_Call( status = der_get_ulong(C_DeriveKey_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_DeriveKey_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DeriveKey_Call.hBaseKey, hBaseKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_DeriveKey_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DeriveKey_Call.ulAttributeCount, ulAttributeCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1662,13 +1662,13 @@ unpack_C_DeriveKey_Return( status = der_get_ulong(C_DeriveKey_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DeriveKey_Return.phKey, phKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1701,13 +1701,13 @@ unpack_C_DestroyObject_Call( status = der_get_ulong(C_DestroyObject_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DestroyObject_Call.hObject, hObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1737,7 +1737,7 @@ unpack_C_DestroyObject_Return( status = der_get_ulong(C_DestroyObject_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1772,25 +1772,25 @@ unpack_C_Digest_Call( status = der_get_ulong(C_Digest_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Digest_Call.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Digest_Call.ulDataLen, ulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Digest_Call.pulDigestLen, pulDigestLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1822,19 +1822,19 @@ unpack_C_Digest_Return( status = der_get_ulong(C_Digest_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Digest_Return.pDigest, pDigest); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Digest_Return.pulDigestLen, pulDigestLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1869,25 +1869,25 @@ unpack_C_DigestEncryptUpdate_Call( status = der_get_ulong(C_DigestEncryptUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DigestEncryptUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestEncryptUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestEncryptUpdate_Call.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1919,19 +1919,19 @@ unpack_C_DigestEncryptUpdate_Return( status = der_get_ulong(C_DigestEncryptUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DigestEncryptUpdate_Return.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestEncryptUpdate_Return.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -1964,13 +1964,13 @@ unpack_C_DigestFinal_Call( status = der_get_ulong(C_DigestFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestFinal_Call.pulDigestLen, pulDigestLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2002,19 +2002,19 @@ unpack_C_DigestFinal_Return( status = der_get_ulong(C_DigestFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DigestFinal_Return.pDigest, pDigest); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestFinal_Return.pulDigestLen, pulDigestLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2047,13 +2047,13 @@ unpack_C_DigestInit_Call( status = der_get_ulong(C_DigestInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_DigestInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2083,7 +2083,7 @@ unpack_C_DigestInit_Return( status = der_get_ulong(C_DigestInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2116,13 +2116,13 @@ unpack_C_DigestKey_Call( status = der_get_ulong(C_DigestKey_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestKey_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2152,7 +2152,7 @@ unpack_C_DigestKey_Return( status = der_get_ulong(C_DigestKey_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2186,19 +2186,19 @@ unpack_C_DigestUpdate_Call( status = der_get_ulong(C_DigestUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_DigestUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_DigestUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2228,7 +2228,7 @@ unpack_C_DigestUpdate_Return( status = der_get_ulong(C_DigestUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2263,25 +2263,25 @@ unpack_C_Encrypt_Call( status = der_get_ulong(C_Encrypt_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Encrypt_Call.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Encrypt_Call.ulDataLen, ulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Encrypt_Call.pulEncryptedDataLen, pulEncryptedDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2313,19 +2313,19 @@ unpack_C_Encrypt_Return( status = der_get_ulong(C_Encrypt_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Encrypt_Return.pEncryptedData, pEncryptedData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Encrypt_Return.pulEncryptedDataLen, pulEncryptedDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2358,13 +2358,13 @@ unpack_C_EncryptFinal_Call( status = der_get_ulong(C_EncryptFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptFinal_Call.pulEncryptedDataLen, pulEncryptedDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2396,19 +2396,19 @@ unpack_C_EncryptFinal_Return( status = der_get_ulong(C_EncryptFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_EncryptFinal_Return.pEncryptedData, pEncryptedData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptFinal_Return.pulEncryptedDataLen, pulEncryptedDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2442,19 +2442,19 @@ unpack_C_EncryptInit_Call( status = der_get_ulong(C_EncryptInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_EncryptInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptInit_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2484,7 +2484,7 @@ unpack_C_EncryptInit_Return( status = der_get_ulong(C_EncryptInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2519,25 +2519,25 @@ unpack_C_EncryptUpdate_Call( status = der_get_ulong(C_EncryptUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_EncryptUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptUpdate_Call.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2569,19 +2569,19 @@ unpack_C_EncryptUpdate_Return( status = der_get_ulong(C_EncryptUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_EncryptUpdate_Return.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_EncryptUpdate_Return.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2613,7 +2613,7 @@ unpack_C_Finalize_Call( status = der_get_CK_VOID_PTR(&C_Finalize_Call.pReserved, pReserved); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2644,7 +2644,7 @@ unpack_C_Finalize_Return( status = der_get_ulong(C_Finalize_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2681,13 +2681,13 @@ unpack_C_FindObjects_Call( status = der_get_ulong(C_FindObjects_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_FindObjects_Call.ulMaxObjectCount, ulMaxObjectCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2719,19 +2719,19 @@ unpack_C_FindObjects_Return( status = der_get_ulong(C_FindObjects_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_OBJECT_HANDLE_ARRAY(&C_FindObjects_Return.phObject, phObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_FindObjects_Return.pulObjectCount, pulObjectCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2763,7 +2763,7 @@ unpack_C_FindObjectsFinal_Call( status = der_get_ulong(C_FindObjectsFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2793,7 +2793,7 @@ unpack_C_FindObjectsFinal_Return( status = der_get_ulong(C_FindObjectsFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2827,19 +2827,19 @@ unpack_C_FindObjectsInit_Call( status = der_get_ulong(C_FindObjectsInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_FindObjectsInit_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_FindObjectsInit_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2870,13 +2870,13 @@ unpack_C_FindObjectsInit_Return( status = der_get_ulong(C_FindObjectsInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_FindObjectsInit_Return.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2911,25 +2911,25 @@ unpack_C_GenerateKey_Call( status = der_get_ulong(C_GenerateKey_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_GenerateKey_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_GenerateKey_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKey_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -2960,13 +2960,13 @@ unpack_C_GenerateKey_Return( status = der_get_ulong(C_GenerateKey_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKey_Return.phKey, phKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3003,37 +3003,37 @@ unpack_C_GenerateKeyPair_Call( status = der_get_ulong(C_GenerateKeyPair_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_GenerateKeyPair_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_GenerateKeyPair_Call.pPublicKeyTemplate, pPublicKeyTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKeyPair_Call.ulPublicKeyAttributeCount, ulPublicKeyAttributeCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_GenerateKeyPair_Call.pPrivateKeyTemplate, pPrivateKeyTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKeyPair_Call.ulPrivateKeyAttributeCount, ulPrivateKeyAttributeCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3065,19 +3065,19 @@ unpack_C_GenerateKeyPair_Return( status = der_get_ulong(C_GenerateKeyPair_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKeyPair_Return.phPublicKey, phPublicKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateKeyPair_Return.phPrivateKey, phPrivateKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3110,13 +3110,13 @@ unpack_C_GenerateRandom_Call( status = der_get_ulong(C_GenerateRandom_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GenerateRandom_Call.ulRandomLen, ulRandomLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3147,13 +3147,13 @@ unpack_C_GenerateRandom_Return( status = der_get_ulong(C_GenerateRandom_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_GenerateRandom_Return.pSeed, pSeed); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3188,25 +3188,25 @@ unpack_C_GetAttributeValue_Call( status = der_get_ulong(C_GetAttributeValue_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetAttributeValue_Call.hObject, hObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_GetAttributeValue_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetAttributeValue_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3237,13 +3237,13 @@ unpack_C_GetAttributeValue_Return( status = der_get_ulong(C_GetAttributeValue_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_GetAttributeValue_Return.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3275,7 +3275,7 @@ unpack_C_GetFunctionStatus_Call( status = der_get_ulong(C_GetFunctionStatus_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3305,7 +3305,7 @@ unpack_C_GetFunctionStatus_Return( status = der_get_ulong(C_GetFunctionStatus_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3361,13 +3361,13 @@ unpack_C_GetInfo_Return( status = der_get_ulong(C_GetInfo_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_INFO_PTR(&C_GetInfo_Return.pInfo, pInfo); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3400,13 +3400,13 @@ unpack_C_GetMechanismInfo_Call( status = der_get_ulong(C_GetMechanismInfo_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetMechanismInfo_Call.type, type); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3437,13 +3437,13 @@ unpack_C_GetMechanismInfo_Return( status = der_get_ulong(C_GetMechanismInfo_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_INFO_PTR(&C_GetMechanismInfo_Return.pInfo, pInfo); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3476,13 +3476,13 @@ unpack_C_GetMechanismList_Call( status = der_get_ulong(C_GetMechanismList_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetMechanismList_Call.pulCount, pulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3514,19 +3514,19 @@ unpack_C_GetMechanismList_Return( status = der_get_ulong(C_GetMechanismList_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_TYPE_ARRAY(&C_GetMechanismList_Return.pMechanismList, pMechanismList); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetMechanismList_Return.pulCount, pulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3559,13 +3559,13 @@ unpack_C_GetObjectSize_Call( status = der_get_ulong(C_GetObjectSize_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetObjectSize_Call.hObject, hObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3596,13 +3596,13 @@ unpack_C_GetObjectSize_Return( status = der_get_ulong(C_GetObjectSize_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetObjectSize_Return.pulSize, pulSize); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3635,13 +3635,13 @@ unpack_C_GetOperationState_Call( status = der_get_ulong(C_GetOperationState_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetOperationState_Call.pulOperationStateLen, pulOperationStateLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3673,19 +3673,19 @@ unpack_C_GetOperationState_Return( status = der_get_ulong(C_GetOperationState_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_GetOperationState_Return.pOperationState, pOperationState); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetOperationState_Return.pulOperationStateLen, pulOperationStateLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3717,7 +3717,7 @@ unpack_C_GetSessionInfo_Call( status = der_get_ulong(C_GetSessionInfo_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3748,13 +3748,13 @@ unpack_C_GetSessionInfo_Return( status = der_get_ulong(C_GetSessionInfo_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_SESSION_INFO_PTR(&C_GetSessionInfo_Return.pInfo, pInfo); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3786,7 +3786,7 @@ unpack_C_GetSlotInfo_Call( status = der_get_ulong(C_GetSlotInfo_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3817,13 +3817,13 @@ unpack_C_GetSlotInfo_Return( status = der_get_ulong(C_GetSlotInfo_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_SLOT_INFO_PTR(&C_GetSlotInfo_Return.pInfo, pInfo); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3856,13 +3856,13 @@ unpack_C_GetSlotList_Call( status = der_get_CK_BBOOL_PTR(&C_GetSlotList_Call.tokenPresent, tokenPresent); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetSlotList_Call.pulCount, pulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3894,19 +3894,19 @@ unpack_C_GetSlotList_Return( status = der_get_ulong(C_GetSlotList_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_SLOT_ID_ARRAY(&C_GetSlotList_Return.pSlotList, pSlotList); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_GetSlotList_Return.pulCount, pulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3938,7 +3938,7 @@ unpack_C_GetTokenInfo_Call( status = der_get_ulong(C_GetTokenInfo_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -3969,13 +3969,13 @@ unpack_C_GetTokenInfo_Return( status = der_get_ulong(C_GetTokenInfo_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_TOKEN_INFO_PTR(&C_GetTokenInfo_Return.pInfo, pInfo); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4009,19 +4009,19 @@ unpack_C_InitPIN_Call( status = der_get_ulong(C_InitPIN_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_UTF8CHAR_ARRAY(&C_InitPIN_Call.pPin, pPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_InitPIN_Call.ulPinLen, ulPinLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4051,7 +4051,7 @@ unpack_C_InitPIN_Return( status = der_get_ulong(C_InitPIN_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4086,25 +4086,25 @@ unpack_C_InitToken_Call( status = der_get_ulong(C_InitToken_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_UTF8String(&C_InitToken_Call.pPin, pPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_InitToken_Call.ulPinLen, ulPinLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_UTF8String(&C_InitToken_Call.pLabel, pLabel); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4134,7 +4134,7 @@ unpack_C_InitToken_Return( status = der_get_ulong(C_InitToken_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4166,7 +4166,7 @@ unpack_C_Initialize_Call( status = der_get_CK_C_INITIALIZE_ARGS_PTR(&C_Initialize_Call.pInitArgs, pInitArgs); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4197,7 +4197,7 @@ unpack_C_Initialize_Return( status = der_get_ulong(C_Initialize_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4236,25 +4236,25 @@ unpack_C_Login_Call( status = der_get_ulong(C_Login_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Login_Call.userType, userType); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_UTF8CHAR_ARRAY(&C_Login_Call.pPin, pPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Login_Call.ulPinLen, ulPinLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4284,7 +4284,7 @@ unpack_C_Login_Return( status = der_get_ulong(C_Login_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4316,7 +4316,7 @@ unpack_C_Logout_Call( status = der_get_ulong(C_Logout_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4346,7 +4346,7 @@ unpack_C_Logout_Return( status = der_get_ulong(C_Logout_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4381,13 +4381,13 @@ unpack_C_OpenSession_Call( status = der_get_ulong(C_OpenSession_Call.slotID, slotID); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_FLAGS_PTR(&C_OpenSession_Call.flags, flags); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4397,7 +4397,7 @@ unpack_C_OpenSession_Call( status = der_get_CK_NOTIFY(&C_OpenSession_Call.notify, notify); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4428,13 +4428,13 @@ unpack_C_OpenSession_Return( status = der_get_ulong(C_OpenSession_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_OpenSession_Return.phSession, phSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4468,19 +4468,19 @@ unpack_C_SeedRandom_Call( status = der_get_ulong(C_SeedRandom_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SeedRandom_Call.pSeed, pSeed); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SeedRandom_Call.ulSeedLen, ulSeedLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4510,7 +4510,7 @@ unpack_C_SeedRandom_Return( status = der_get_ulong(C_SeedRandom_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4545,25 +4545,25 @@ unpack_C_SetAttributeValue_Call( status = der_get_ulong(C_SetAttributeValue_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetAttributeValue_Call.hObject, hObject); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_SetAttributeValue_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetAttributeValue_Call.ulCount, ulCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4593,7 +4593,7 @@ unpack_C_SetAttributeValue_Return( status = der_get_ulong(C_SetAttributeValue_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4629,31 +4629,31 @@ unpack_C_SetOperationState_Call( status = der_get_ulong(C_SetOperationState_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SetOperationState_Call.pOperationState, pOperationState); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetOperationState_Call.ulOperationStateLen, ulOperationStateLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetOperationState_Call.hEncryptionKey, hEncryptionKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetOperationState_Call.hAuthenticationKey, hAuthenticationKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4683,7 +4683,7 @@ unpack_C_SetOperationState_Return( status = der_get_ulong(C_SetOperationState_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4719,31 +4719,31 @@ unpack_C_SetPIN_Call( status = der_get_ulong(C_SetPIN_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_UTF8CHAR_ARRAY(&C_SetPIN_Call.pOldPin, pOldPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetPIN_Call.ulOldLen, ulOldLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_UTF8CHAR_ARRAY(&C_SetPIN_Call.pNewPin, pNewPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SetPIN_Call.ulNewPin, ulNewPin); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4773,7 +4773,7 @@ unpack_C_SetPIN_Return( status = der_get_ulong(C_SetPIN_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4808,25 +4808,25 @@ unpack_C_Sign_Call( status = der_get_ulong(C_Sign_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Sign_Call.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Sign_Call.ulDataLen, ulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Sign_Call.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4858,19 +4858,19 @@ unpack_C_Sign_Return( status = der_get_ulong(C_Sign_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Sign_Return.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Sign_Return.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4905,25 +4905,25 @@ unpack_C_SignEncryptUpdate_Call( status = der_get_ulong(C_SignEncryptUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignEncryptUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignEncryptUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignEncryptUpdate_Call.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -4955,19 +4955,19 @@ unpack_C_SignEncryptUpdate_Return( status = der_get_ulong(C_SignEncryptUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignEncryptUpdate_Return.pEncryptedPart, pEncryptedPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignEncryptUpdate_Return.pulEncryptedPartLen, pulEncryptedPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5000,13 +5000,13 @@ unpack_C_SignFinal_Call( status = der_get_ulong(C_SignFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignFinal_Call.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5038,19 +5038,19 @@ unpack_C_SignFinal_Return( status = der_get_ulong(C_SignFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignFinal_Return.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignFinal_Return.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5084,19 +5084,19 @@ unpack_C_SignInit_Call( status = der_get_ulong(C_SignInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_SignInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignInit_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5126,7 +5126,7 @@ unpack_C_SignInit_Return( status = der_get_ulong(C_SignInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5161,25 +5161,25 @@ unpack_C_SignRecover_Call( status = der_get_ulong(C_SignRecover_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignRecover_Call.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignRecover_Call.ulDataLen, ulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignRecover_Call.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5211,19 +5211,19 @@ unpack_C_SignRecover_Return( status = der_get_ulong(C_SignRecover_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignRecover_Return.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignRecover_Return.pulSignatureLen, pulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5257,19 +5257,19 @@ unpack_C_SignRecoverInit_Call( status = der_get_ulong(C_SignRecoverInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_SignRecoverInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignRecoverInit_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5299,7 +5299,7 @@ unpack_C_SignRecoverInit_Return( status = der_get_ulong(C_SignRecoverInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5333,19 +5333,19 @@ unpack_C_SignUpdate_Call( status = der_get_ulong(C_SignUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_SignUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_SignUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5375,7 +5375,7 @@ unpack_C_SignUpdate_Return( status = der_get_ulong(C_SignUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5413,43 +5413,43 @@ unpack_C_UnwrapKey_Call( status = der_get_ulong(C_UnwrapKey_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_UnwrapKey_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_UnwrapKey_Call.hUnwrappingKey, hUnwrappingKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_UnwrapKey_Call.pWrappedKey, pWrappedKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_UnwrapKey_Call.ulWrappedKeyLen, ulWrappedKeyLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_ATTRIBUTE_ARRAY(&C_UnwrapKey_Call.pTemplate, pTemplate); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_UnwrapKey_Call.ulAttributeCount, ulAttributeCount); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5480,13 +5480,13 @@ unpack_C_UnwrapKey_Return( status = der_get_ulong(C_UnwrapKey_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_UnwrapKey_Return.phKey, phKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5522,31 +5522,31 @@ unpack_C_Verify_Call( status = der_get_ulong(C_Verify_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Verify_Call.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Verify_Call.ulDataLen, ulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_Verify_Call.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_Verify_Call.ulSignatureLen, ulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5576,7 +5576,7 @@ unpack_C_Verify_Return( status = der_get_ulong(C_Verify_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5610,19 +5610,19 @@ unpack_C_VerifyFinal_Call( status = der_get_ulong(C_VerifyFinal_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_VerifyFinal_Call.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyFinal_Call.ulSignatureLen, ulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5652,7 +5652,7 @@ unpack_C_VerifyFinal_Return( status = der_get_ulong(C_VerifyFinal_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5686,19 +5686,19 @@ unpack_C_VerifyInit_Call( status = der_get_ulong(C_VerifyInit_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_VerifyInit_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyInit_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5728,7 +5728,7 @@ unpack_C_VerifyInit_Return( status = der_get_ulong(C_VerifyInit_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5763,25 +5763,25 @@ unpack_C_VerifyRecover_Call( status = der_get_ulong(C_VerifyRecover_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_VerifyRecover_Call.pSignature, pSignature); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyRecover_Call.ulSignatureLen, ulSignatureLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyRecover_Call.pulDataLen, pulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5813,19 +5813,19 @@ unpack_C_VerifyRecover_Return( status = der_get_ulong(C_VerifyRecover_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_VerifyRecover_Return.pData, pData); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyRecover_Return.pulDataLen, pulDataLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5859,19 +5859,19 @@ unpack_C_VerifyUpdate_Call( status = der_get_ulong(C_VerifyUpdate_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_VerifyUpdate_Call.pPart, pPart); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_VerifyUpdate_Call.ulPartLen, ulPartLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5901,7 +5901,7 @@ unpack_C_VerifyUpdate_Return( status = der_get_ulong(C_VerifyUpdate_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5934,13 +5934,13 @@ unpack_C_WaitForSlotEvent_Call( status = der_get_CK_FLAGS_PTR(&C_WaitForSlotEvent_Call.flags, flags); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_VOID_PTR(&C_WaitForSlotEvent_Call.pReserved, pReserved); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -5972,19 +5972,19 @@ unpack_C_WaitForSlotEvent_Return( status = der_get_ulong(C_WaitForSlotEvent_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_WaitForSlotEvent_Return.pSlot, pSlot); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_VOID_PTR(&C_WaitForSlotEvent_Return.pReserved, pReserved); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -6020,31 +6020,31 @@ unpack_C_WrapKey_Call( status = der_get_ulong(C_WrapKey_Call.hSession, hSession); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_MECHANISM_PTR(&C_WrapKey_Call.pMechanism, pMechanism); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_WrapKey_Call.hWrappingKey, hWrappingKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_WrapKey_Call.hKey, hKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_WrapKey_Call.pulWrappedKeyLen, pulWrappedKeyLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; @@ -6076,19 +6076,19 @@ unpack_C_WrapKey_Return( status = der_get_ulong(C_WrapKey_Return.retval, retval); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_CK_BYTE_ARRAY(&C_WrapKey_Return.pWrappedKey, pWrappedKey); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; status = der_get_ulong(C_WrapKey_Return.pulWrappedKeyLen, pulWrappedKeyLen); if (status == -1) - return CKR_KEEHIVE_DER_UNKNOWN_ERROR; + return CKR_KEEHIVE_DER_RANGE_ERROR; diff --git a/src/static/convert.c b/src/static/convert.c index c178d03..c71a463 100644 --- a/src/static/convert.c +++ b/src/static/convert.c @@ -2,120 +2,150 @@ #include "convert.h" + dercursor not_implemented(uint8_t *der_buf_uint32, uint32_t value) { dercursor cursor; return cursor; }; -void populate() { - //func_array[CKA_ALLOWED_MECHANISMS+1] = { not_implemented }; - func_array[CKA_TOKEN] = not_implemented; - func_array[CKA_CLASS] = not_implemented; - func_array[CKA_PRIVATE] = not_implemented; - func_array[CKA_LABEL] = not_implemented; - func_array[CKA_APPLICATION] = not_implemented; - func_array[CKA_VALUE] = not_implemented; - func_array[CKA_OBJECT_ID] = not_implemented; - func_array[CKA_CERTIFICATE_TYPE] = not_implemented; - func_array[CKA_ISSUER] = not_implemented; - func_array[CKA_SERIAL_NUMBER] = not_implemented; - func_array[CKA_AC_ISSUER] = not_implemented; - func_array[CKA_OWNER] = not_implemented; - func_array[CKA_ATTR_TYPES] = not_implemented; - func_array[CKA_TRUSTED] = not_implemented; - func_array[CKA_CERTIFICATE_CATEGORY] = not_implemented; - func_array[CKA_JAVA_MIDP_SECURITY_DOMAIN] = not_implemented; - func_array[CKA_URL] = not_implemented; - func_array[CKA_HASH_OF_SUBJECT_PUBLIC_KEY] = not_implemented; - func_array[CKA_HASH_OF_ISSUER_PUBLIC_KEY] = not_implemented; - func_array[CKA_NAME_HASH_ALGORITHM] = not_implemented; - func_array[CKA_CHECK_VALUE] = not_implemented; - func_array[CKA_KEY_TYPE] = not_implemented; - func_array[CKA_SUBJECT] = not_implemented; - func_array[CKA_ID] = not_implemented; - func_array[CKA_SENSITIVE] = not_implemented; - func_array[CKA_ENCRYPT] = not_implemented; - func_array[CKA_DECRYPT] = not_implemented; - func_array[CKA_WRAP] = not_implemented; - func_array[CKA_UNWRAP] = not_implemented; - func_array[CKA_SIGN] = not_implemented; - func_array[CKA_SIGN_RECOVER] = not_implemented; - func_array[CKA_VERIFY] = not_implemented; - func_array[CKA_VERIFY_RECOVER] = not_implemented; - func_array[CKA_DERIVE] = not_implemented; - func_array[CKA_START_DATE] = not_implemented; - func_array[CKA_END_DATE] = not_implemented; - func_array[CKA_MODULUS] = not_implemented; - func_array[CKA_MODULUS_BITS] = not_implemented; - func_array[CKA_PUBLIC_EXPONENT] = not_implemented; - func_array[CKA_PRIVATE_EXPONENT] = not_implemented; - func_array[CKA_PRIME_1] = not_implemented; - func_array[CKA_PRIME_2] = not_implemented; - func_array[CKA_EXPONENT_1] = not_implemented; - func_array[CKA_EXPONENT_2] = not_implemented; - func_array[CKA_COEFFICIENT] = not_implemented; - func_array[CKA_PUBLIC_KEY_INFO] = not_implemented; - func_array[CKA_PRIME] = not_implemented; - func_array[CKA_SUBPRIME] = not_implemented; - func_array[CKA_BASE] = not_implemented; - func_array[CKA_PRIME_BITS] = not_implemented; - func_array[CKA_SUBPRIME_BITS] = not_implemented; - func_array[CKA_SUB_PRIME_BITS] = not_implemented; - func_array[CKA_VALUE_BITS] = not_implemented; - func_array[CKA_VALUE_LEN] = not_implemented; - func_array[CKA_EXTRACTABLE] = not_implemented; - func_array[CKA_LOCAL] = not_implemented; - func_array[CKA_NEVER_EXTRACTABLE] = not_implemented; - func_array[CKA_ALWAYS_SENSITIVE] = not_implemented; - func_array[CKA_KEY_GEN_MECHANISM] = not_implemented; - func_array[CKA_MODIFIABLE] = not_implemented; - func_array[CKA_COPYABLE] = not_implemented; - func_array[CKA_DESTROYABLE] = not_implemented; - func_array[CKA_ECDSA_PARAMS] = not_implemented; - func_array[CKA_EC_PARAMS] = not_implemented; - func_array[CKA_EC_POINT] = not_implemented; - func_array[CKA_SECONDARY_AUTH] = not_implemented; - func_array[CKA_AUTH_PIN_FLAGS] = not_implemented; - func_array[CKA_ALWAYS_AUTHENTICATE] = not_implemented; - func_array[CKA_WRAP_WITH_TRUSTED] = not_implemented; - //func_array[CKA_WRAP_TEMPLATE] = not_implemented; - //func_array[CKA_UNWRAP_TEMPLATE] = not_implemented; - //func_array[CKA_DERIVE_TEMPLATE] = not_implemented; - func_array[CKA_OTP_FORMAT] = not_implemented; - func_array[CKA_OTP_LENGTH] = not_implemented; - func_array[CKA_OTP_TIME_INTERVAL] = not_implemented; - func_array[CKA_OTP_USER_FRIENDLY_MODE] = not_implemented; - func_array[CKA_OTP_CHALLENGE_REQUIREMENT] = not_implemented; - func_array[CKA_OTP_TIME_REQUIREMENT] = not_implemented; - func_array[CKA_OTP_COUNTER_REQUIREMENT] = not_implemented; - func_array[CKA_OTP_PIN_REQUIREMENT] = not_implemented; - func_array[CKA_OTP_COUNTER] = not_implemented; - func_array[CKA_OTP_TIME] = not_implemented; - func_array[CKA_OTP_USER_IDENTIFIER] = not_implemented; - func_array[CKA_OTP_SERVICE_IDENTIFIER] = not_implemented; - func_array[CKA_OTP_SERVICE_LOGO] = not_implemented; - func_array[CKA_OTP_SERVICE_LOGO_TYPE] = not_implemented; - func_array[CKA_GOSTR3410_PARAMS] = not_implemented; - func_array[CKA_GOSTR3411_PARAMS] = not_implemented; - func_array[CKA_GOST28147_PARAMS] = not_implemented; - func_array[CKA_HW_FEATURE_TYPE] = not_implemented; - func_array[CKA_RESET_ON_INIT] = not_implemented; - func_array[CKA_HAS_RESET] = not_implemented; - func_array[CKA_PIXEL_X] = not_implemented; - func_array[CKA_PIXEL_Y] = not_implemented; - func_array[CKA_RESOLUTION] = not_implemented; - func_array[CKA_CHAR_ROWS] = not_implemented; - func_array[CKA_CHAR_COLUMNS] = not_implemented; - func_array[CKA_COLOR] = not_implemented; - func_array[CKA_BITS_PER_PIXEL] = not_implemented; - func_array[CKA_CHAR_SETS] = not_implemented; - func_array[CKA_ENCODING_METHODS] = not_implemented; - func_array[CKA_MIME_TYPES] = not_implemented; - func_array[CKA_MECHANISM_TYPE] = not_implemented; - func_array[CKA_REQUIRED_CMS_ATTRIBUTES] = not_implemented; - func_array[CKA_DEFAULT_CMS_ATTRIBUTES] = not_implemented; - func_array[CKA_SUPPORTED_CMS_ATTRIBUTES] = not_implemented; - //func_array[CKA_ALLOWED_MECHANISMS] = not_implemented; - //func_array[CKA_VENDOR_DEFINED] = not_implemented; +static func_tree_t functree; + + +func_t func_array[] = { + {.key=CKA_TOKEN, .func=not_implemented}, + {.key=CKA_CLASS, .func=not_implemented}, + {.key=CKA_PRIVATE, .func=not_implemented}, + {.key=CKA_LABEL, .func=not_implemented}, + {.key=CKA_APPLICATION, .func=not_implemented}, + {.key=CKA_VALUE, .func=not_implemented}, + {.key=CKA_OBJECT_ID, .func=not_implemented}, + {.key=CKA_CERTIFICATE_TYPE, .func=not_implemented}, + {.key=CKA_ISSUER, .func=not_implemented}, + {.key=CKA_SERIAL_NUMBER, .func=not_implemented}, + {.key=CKA_AC_ISSUER, .func=not_implemented}, + {.key=CKA_OWNER, .func=not_implemented}, + {.key=CKA_ATTR_TYPES, .func=not_implemented}, + {.key=CKA_TRUSTED, .func=not_implemented}, + {.key=CKA_CERTIFICATE_CATEGORY, .func=not_implemented}, + {.key=CKA_JAVA_MIDP_SECURITY_DOMAIN, .func=not_implemented}, + {.key=CKA_URL, .func=not_implemented}, + {.key=CKA_HASH_OF_SUBJECT_PUBLIC_KEY, .func=not_implemented}, + {.key=CKA_HASH_OF_ISSUER_PUBLIC_KEY, .func=not_implemented}, + {.key=CKA_NAME_HASH_ALGORITHM, .func=not_implemented}, + {.key=CKA_CHECK_VALUE, .func=not_implemented}, + {.key=CKA_KEY_TYPE, .func=not_implemented}, + {.key=CKA_SUBJECT, .func=not_implemented}, + {.key=CKA_ID, .func=not_implemented}, + {.key=CKA_SENSITIVE, .func=not_implemented}, + {.key=CKA_ENCRYPT, .func=not_implemented}, + {.key=CKA_DECRYPT, .func=not_implemented}, + {.key=CKA_WRAP, .func=not_implemented}, + {.key=CKA_UNWRAP, .func=not_implemented}, + {.key=CKA_SIGN, .func=not_implemented}, + {.key=CKA_SIGN_RECOVER, .func=not_implemented}, + {.key=CKA_VERIFY, .func=not_implemented}, + {.key=CKA_VERIFY_RECOVER, .func=not_implemented}, + {.key=CKA_DERIVE, .func=not_implemented}, + {.key=CKA_START_DATE, .func=not_implemented}, + {.key=CKA_END_DATE, .func=not_implemented}, + {.key=CKA_MODULUS, .func=not_implemented}, + {.key=CKA_MODULUS_BITS, .func=not_implemented}, + {.key=CKA_PUBLIC_EXPONENT, .func=not_implemented}, + {.key=CKA_PRIVATE_EXPONENT, .func=not_implemented}, + {.key=CKA_PRIME_1, .func=not_implemented}, + {.key=CKA_PRIME_2, .func=not_implemented}, + {.key=CKA_EXPONENT_1, .func=not_implemented}, + {.key=CKA_EXPONENT_2, .func=not_implemented}, + {.key=CKA_COEFFICIENT, .func=not_implemented}, + {.key=CKA_PUBLIC_KEY_INFO, .func=not_implemented}, + {.key=CKA_PRIME, .func=not_implemented}, + {.key=CKA_SUBPRIME, .func=not_implemented}, + {.key=CKA_BASE, .func=not_implemented}, + {.key=CKA_PRIME_BITS, .func=not_implemented}, + {.key=CKA_SUBPRIME_BITS, .func=not_implemented}, + {.key=CKA_SUB_PRIME_BITS, .func=not_implemented}, + {.key=CKA_VALUE_BITS, .func=not_implemented}, + {.key=CKA_VALUE_LEN, .func=not_implemented}, + {.key=CKA_EXTRACTABLE, .func=not_implemented}, + {.key=CKA_LOCAL, .func=not_implemented}, + {.key=CKA_NEVER_EXTRACTABLE, .func=not_implemented}, + {.key=CKA_ALWAYS_SENSITIVE, .func=not_implemented}, + {.key=CKA_KEY_GEN_MECHANISM, .func=not_implemented}, + {.key=CKA_MODIFIABLE, .func=not_implemented}, + {.key=CKA_COPYABLE, .func=not_implemented}, + {.key=CKA_DESTROYABLE, .func=not_implemented}, + {.key=CKA_ECDSA_PARAMS, .func=not_implemented}, + {.key=CKA_EC_PARAMS, .func=not_implemented}, + {.key=CKA_EC_POINT, .func=not_implemented}, + {.key=CKA_SECONDARY_AUTH, .func=not_implemented}, + {.key=CKA_AUTH_PIN_FLAGS, .func=not_implemented}, + {.key=CKA_ALWAYS_AUTHENTICATE, .func=not_implemented}, + {.key=CKA_WRAP_WITH_TRUSTED, .func=not_implemented}, + {.key=CKA_WRAP_TEMPLATE, .func=not_implemented}, + {.key=CKA_UNWRAP_TEMPLATE, .func=not_implemented}, + {.key=CKA_DERIVE_TEMPLATE, .func=not_implemented}, + {.key=CKA_OTP_FORMAT, .func=not_implemented}, + {.key=CKA_OTP_LENGTH, .func=not_implemented}, + {.key=CKA_OTP_TIME_INTERVAL, .func=not_implemented}, + {.key=CKA_OTP_USER_FRIENDLY_MODE, .func=not_implemented}, + {.key=CKA_OTP_CHALLENGE_REQUIREMENT, .func=not_implemented}, + {.key=CKA_OTP_TIME_REQUIREMENT, .func=not_implemented}, + {.key=CKA_OTP_COUNTER_REQUIREMENT, .func=not_implemented}, + {.key=CKA_OTP_PIN_REQUIREMENT, .func=not_implemented}, + {.key=CKA_OTP_COUNTER, .func=not_implemented}, + {.key=CKA_OTP_TIME, .func=not_implemented}, + {.key=CKA_OTP_USER_IDENTIFIER, .func=not_implemented}, + {.key=CKA_OTP_SERVICE_IDENTIFIER, .func=not_implemented}, + {.key=CKA_OTP_SERVICE_LOGO, .func=not_implemented}, + {.key=CKA_OTP_SERVICE_LOGO_TYPE, .func=not_implemented}, + {.key=CKA_GOSTR3410_PARAMS, .func=not_implemented}, + {.key=CKA_GOSTR3411_PARAMS, .func=not_implemented}, + {.key=CKA_GOST28147_PARAMS, .func=not_implemented}, + {.key=CKA_HW_FEATURE_TYPE, .func=not_implemented}, + {.key=CKA_RESET_ON_INIT, .func=not_implemented}, + {.key=CKA_HAS_RESET, .func=not_implemented}, + {.key=CKA_PIXEL_X, .func=not_implemented}, + {.key=CKA_PIXEL_Y, .func=not_implemented}, + {.key=CKA_RESOLUTION, .func=not_implemented}, + {.key=CKA_CHAR_ROWS, .func=not_implemented}, + {.key=CKA_CHAR_COLUMNS, .func=not_implemented}, + {.key=CKA_COLOR, .func=not_implemented}, + {.key=CKA_BITS_PER_PIXEL, .func=not_implemented}, + {.key=CKA_CHAR_SETS, .func=not_implemented}, + {.key=CKA_ENCODING_METHODS, .func=not_implemented}, + {.key=CKA_MIME_TYPES, .func=not_implemented}, + {.key=CKA_MECHANISM_TYPE, .func=not_implemented}, + {.key=CKA_REQUIRED_CMS_ATTRIBUTES, .func=not_implemented}, + {.key=CKA_DEFAULT_CMS_ATTRIBUTES, .func=not_implemented}, + {.key=CKA_SUPPORTED_CMS_ATTRIBUTES, .func=not_implemented}, + {.key=CKA_ALLOWED_MECHANISMS, .func=not_implemented}, + {.key=CKA_VENDOR_DEFINED, .func=not_implemented} }; + +size_t funckeyfunct(const func_t *r) +{ + return r->key; +} + + +NEDTRIE_HEAD(func_tree_s, func_s); + + +NEDTRIE_GENERATE(static, func_tree_s, func_s, link, funckeyfunct, NEDTRIE_NOBBLEZEROS(func_tree_s)); + + +void init_func_tree() +{ + NEDTRIE_INIT(&functree); + int i; + for (i=0; i< sizeof(func_array)/ sizeof(func_t); i++) + NEDTRIE_INSERT(func_tree_s, &functree, &func_array[i]); +} + +func_t* find_func(size_t key) { + func_t s, *r; + s.key = key; + r = NEDTRIE_FIND(func_tree_s, &functree, &s); + return r; +} diff --git a/src/static/convert.h b/src/static/convert.h index 2783dbf..e6ff524 100644 --- a/src/static/convert.h +++ b/src/static/convert.h @@ -4,9 +4,22 @@ #include "pkcs11/pkcs11unix.h" #include #include +#include "nedtrie.h" dercursor not_implemented(uint8_t *der_buf_uint32, uint32_t value); -dercursor (*func_array[CKA_SUPPORTED_CMS_ATTRIBUTES+1]) (uint8_t *der_buf_uint32, uint32_t value); +struct func_s { + NEDTRIE_ENTRY(func_s) link; + size_t key; + dercursor (*func)(uint8_t*, uint32_t); +}; + +typedef struct func_s func_t; + +typedef struct func_tree_s func_tree_t; + +void init_func_tree(); + +func_t* find_func(size_t key); #endif //KEEHIVE_CONVERT_H \ No newline at end of file diff --git a/src/static/derget.c b/src/static/derget.c index 3e5419f..3f0045c 100644 --- a/src/static/derget.c +++ b/src/static/derget.c @@ -31,8 +31,9 @@ int der_get_long(dercursor cursor, long int *valp) int der_get_ulong( dercursor cursor, - long unsigned int *valp + long unsigned int* valp ) { + *valp = 0; // make sure long part is reset return der_get_uint32 (cursor, (u_int32_t *)valp); }; diff --git a/src/static/derput.c b/src/static/derput.c index 53799e6..26d24ad 100644 --- a/src/static/derput.c +++ b/src/static/derput.c @@ -138,16 +138,23 @@ der_put_CK_ATTRIBUTE_ARRAY( size_t* pLength, const derwalk* pack ) { + init_func_tree(); + int i; der_buf_uint32_t buf = { 0 }; dercursor crs; CK_ATTRIBUTE attribute; size_t innerlen = 0; size_t tmp = 0; + func_t* func; for (i = 0; i < *count; i++) { attribute = pTemplate[i]; - crs = (*func_array[attribute.type])(buf, *(uint32_t*)attribute.pValue); + func = find_func(attribute.type); + if (func == NULL) + return CKR_KEEHIVE_NOT_IMPLEMENTED_ERROR; + crs = (*func->func)(buf, *(uint32_t*)attribute.pValue); + tmp = der_pack(pack, &crs, NULL); if (tmp == 0) return CKR_KEEHIVE_DER_UNKNOWN_ERROR; @@ -161,7 +168,10 @@ der_put_CK_ATTRIBUTE_ARRAY( while (i-- > 0) { assert(innerlen >= 0); attribute = pTemplate[i]; - crs = (*func_array[attribute.type])(buf, *(uint32_t*)attribute.pValue); + func = find_func(attribute.type); + if (func == NULL) + return CKR_KEEHIVE_NOT_IMPLEMENTED_ERROR; + crs = (*func->func)(buf, *(uint32_t*)attribute.pValue); tmp = der_pack(pack, &crs, *pInnerlist + innerlen); if (tmp == 0) return CKR_KEEHIVE_DER_UNKNOWN_ERROR; diff --git a/src/static/nedtrie.h b/src/static/nedtrie.h new file mode 100644 index 0000000..875c41b --- /dev/null +++ b/src/static/nedtrie.h @@ -0,0 +1,2396 @@ +/* An in-place binary trie implementation for C and C++ aka. the +ridiculously fast way of indexing stuff. (C) 2010-2012 Niall Douglas. + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include /* For INT_MAX */ + +#ifdef _MSC_VER +/* Disable stupid warnings */ +#pragma warning(push) +#pragma warning(disable: 4702) /* unreachable code */ +#pragma warning(disable: 4706) /* assignment within conditional expression */ +#pragma warning(disable: 4127) /* conditional expression is constant */ +#pragma warning(disable: 4133) /* incompatible types */ +#endif + +/*! \def RESTRICT +\brief Defined to the restrict keyword or equivalent if available */ +#ifndef RESTRICT +#if __STDC_VERSION__ >= 199901L /* C99 or better */ + #define RESTRICT restrict +#else + #if defined(_MSC_VER) && _MSC_VER>=1400 + #define RESTRICT __restrict + #endif + #ifdef __GNUC__ + #define RESTRICT __restrict + #endif +#endif +#ifndef RESTRICT + #define RESTRICT +#endif +#endif + +/*! \def INLINE +\brief Defined to the inline keyword or equivalent if available */ +#ifndef INLINE +#if __STDC_VERSION__ >= 199901L /* C99 or better */ || defined(__cplusplus) + #define INLINE inline +#else + #if defined(_MSC_VER) + #define INLINE __inline + #endif + #ifdef __GNUC__ + #define INLINE __inline + #endif +#endif +#ifndef INLINE + #define INLINE +#endif +#endif + +/*! \def NOINLINE +\brief Defined to whatever compiler magic inhibits inlining if available */ +#ifndef NOINLINE + #if defined(__GNUC__) + #define NOINLINE __attribute__ ((noinline)) + #elif defined(_MSC_VER) + #define NOINLINE __declspec(noinline) + #else + #define NOINLINE + #endif +#endif + +/*! \def DEBUGINLINE +\brief Defined to be INLINE when NDEBUG is defined, NOINLINE when DEBUG is defined, unset otherwise. +*/ +#ifndef DEBUGINLINE +#ifdef NDEBUG +#define DEBUGINLINE INLINE +#elif defined(DEBUG) +#define DEBUGINLINE NOINLINE +#else +#define DEBUGINLINE +#endif +#endif + +/*! \def NEDTRIEUSEMACROS +\brief Define to 1 to force usage of the macro implementation of nedtries. This is always 1 when +compiling in C, but defaults to 0 when compiling in C++ as a template function implementation offers +much more scope to the optimiser and is much easier to debug. +*/ +#ifndef NEDTRIEUSEMACROS +#ifdef __cplusplus +#define NEDTRIEUSEMACROS 0 +#else +#define NEDTRIEUSEMACROS 1 +#endif +#endif + +/*! \def NEDTRIEDEBUG +\brief Define to 1 if you wish a full trie validation to be performed every time you modify the trie. +Requires assert() to work, so disables itself if NDEBUG is defined. +*/ +#ifndef NEDTRIEDEBUG +#ifdef DEBUG +#define NEDTRIEDEBUG 1 +#else +#define NEDTRIEDEBUG 0 +#endif +#endif +#ifdef NDEBUG +#undef NEDTRIEDEBUG +#define NEDTRIEDEBUG 0 +#endif + +/* Define bit scanning intrinsics */ +#ifdef _MSC_VER +#include +#endif + +#ifdef __cplusplus +#include +#if (defined(_MSC_VER) && _MSC_VER<=1500) || (defined(__GNUC__) && !defined(HAVE_CPP0X)) +// Doesn't have std::move<> by default, so define +namespace std +{ + template T &move(T &a) { return a; } + template T &move(const T &a) { return const_cast(a); } + template T &forward(A &a) { return a; } +} +#endif +namespace { +#endif +static INLINE unsigned nedtriebitscanr(size_t value) +{ + if(!value) return 0; +#if defined(_MSC_VER) && !defined(__cplusplus_cli) + { + unsigned long bitpos; +#if defined(_M_IA64) || defined(_M_X64) || defined(WIN64) + assert(8==sizeof(size_t)); + _BitScanReverse64(&bitpos, value); +#else + assert(4==sizeof(size_t)); + _BitScanReverse(&bitpos, value); +#endif + return (unsigned) bitpos; + } +#elif defined(__GNUC__) + return sizeof(value)*__CHAR_BIT__ - 1 - (unsigned) __builtin_clzl(value); +#else + /* The following code is illegal C, but it almost certainly will work. + If not use the legal implementation below */ +#if !defined(__cplusplus_cli) + union { + unsigned asInt[2]; + double asDouble; + }; + int n; + + asDouble = (double)value + 0.5; + n = (asInt[0 /*Use 1 if your CPU is big endian!*/] >> 20) - 1023; +#ifdef _MSC_VER +#pragma message(__FILE__ ": WARNING: Make sure you change the line above me if your CPU is big endian!") +#else +#warning Make sure you change the line above me if your CPU is big endian! +#endif + return (unsigned) n; +#else + /* This is a generic 32 and 64 bit compatible branch free bitscan right */ + size_t x=value; + const size_t allbits1=~(size_t)0; + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + if(8==sizeof(x)) x = x | (x >>32); + x = ~x; + x = x - ((x >> 1) & (allbits1/3)); + x = (x & (allbits1/15*3)) + ((x >> 2) & (allbits1/15*3)); + x = ((x + (x >> 4)) & (allbits1/255*15)) * (allbits1/255); + x = (8*sizeof(x)-1) - (x >> (8*(sizeof(x)-1))); + return (unsigned) x; +#endif +#endif +} + +#ifdef __cplusplus +} /* Anonymous namespace */ +#endif + +/*! \def NEDTRIE_INDEXBINS +\brief Defines the number of top level bit bins to use. The default based on size_t is usually fine. +*/ +#define NEDTRIE_INDEXBINS (8*sizeof(void *)) +/*! \def NEDTRIE_HEAD +\brief Substitutes the type used to store the head of the trie. +*/ +#define NEDTRIE_HEAD2(name, type) \ +struct name { \ + size_t count; \ + type *triebins[NEDTRIE_INDEXBINS]; /* each containing (1<count) +/*! \def NEDTRIE_COUNT +\brief Returns the number of items in a nedtrie. +*/ +#define NEDTRIE_COUNT(head) ((head)->count) + +/* As macro instantiated code is a royal PITA to debug and even to see what +the hell is going on, we use a templated implementation when in C++. This +aids future debuggability by keeping the template and macro implementations +side by side and hopefully harmonised. */ +#ifdef __cplusplus +namespace nedtries { + + template int trienobblezeros(trietype *) + { + return 0; + } + template int trienobbleones(trietype *) + { + return 1; + } + template int trienobbleequally(trietype *head) + { + return (head->nobbledir=!head->nobbledir); + } +/*! \def NEDTRIE_NOBBLEZEROS +\brief A nobble function which preferentially nobbles zeros. +*/ +#define NEDTRIE_NOBBLEZEROS(name) nedtries::trienobblezeros +/*! \def NEDTRIE_NOBBLEONES +\brief A nobble function which preferentially nobbles ones. +*/ +#define NEDTRIE_NOBBLEONES(name) nedtries::trienobbleones +/*! \def NEDTRIE_NOBBLEEQUALLY +\brief A nobble function which alternates between nobbling zeros and ones. +*/ +#define NEDTRIE_NOBBLEEQUALLY(name) nedtries::trienobbleequally +#define NEDTRIE_GENERATE_NOBBLES(proto, name, type, field, keyfunct) +#else +#define NEDTRIE_NOBBLEZEROS(name) name##_nobblezeros +#define NEDTRIE_NOBBLEONES(name) name##_nobbleones +#define NEDTRIE_NOBBLEEQUALLY(name) name##_nobbleequally +#define NEDTRIE_GENERATE_NOBBLES(proto, name, type, field, keyfunct) \ + static INLINE int name##_nobblezeros(struct name *head) { (void) head; return 0; } \ + static INLINE int name##_nobbleones(struct name *head) { (void) head; return 1; } \ + static INLINE int name##_nobbleequally(struct name *head) { return (head->nobbledir=!head->nobbledir); } +#endif /* __cplusplus */ + +#ifdef __cplusplus + template struct TrieLink_t { + type *trie_parent; /* parent element */ + type *trie_child[2]; /* my children based on whether they are zero or one. */ + type *trie_prev, *trie_next; /* my siblings of identical key to me. */ + }; + template DEBUGINLINE void triecheckvalidity(trietype *head); + namespace testtrielinksize { + struct foo1; struct foo2; + struct foo1 { NEDTRIE_ENTRY(foo1) link; size_t n; }; + struct foo2 { TrieLink_t link; size_t n; }; + static char test_sizeof_trielink_t_equal[sizeof(foo1)==sizeof(foo2)]; + } + +} /* namespace */ +#endif + +/* GCC recently has started puking if you use operators -> and & in template parameters :( */ +#ifdef __GNUC__ +#define NEDTRIEFIELDOFFSET2(type, field) __builtin_offsetof(type, field) +#else +#define NEDTRIEFIELDOFFSET2(type, field) ((size_t) &(((type *)0)->field)) +#endif +#define NEDTRIEFIELDOFFSET(type, field) NEDTRIEFIELDOFFSET2(struct type, field) + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE void trieinsert(trietype *RESTRICT head, type *RESTRICT r) + { + type *RESTRICT node, *RESTRICT childnode; + TrieLink_t *RESTRICT nodelink, *RESTRICT rlink; + size_t rkey=keyfunct(r), keybit, nodekey; + unsigned bitidx; + int keybitset; + + rlink=(TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + memset(rlink, 0, sizeof(TrieLink_t)); + bitidx=nedtriebitscanr(rkey); + assert(bitidxtriebins[bitidx])) + { /* Bottom two bits set indicates a node hanging off of head */ + rlink->trie_parent=(type *RESTRICT)(size_t)(3|(bitidx<<2)); + head->triebins[bitidx]=r; + goto end; + } + /* Avoid variable bit shifts where possible, their performance can suck */ + keybit=(size_t) 1< *RESTRICT)((size_t) node + fieldoffset); + nodekey=keyfunct(node); + if(nodekey==rkey) + { /* Insert into ring list */ + rlink->trie_parent=0; + rlink->trie_prev=node; + rlink->trie_next=nodelink->trie_next; + nodelink->trie_next=r; + if(rlink->trie_next) ((TrieLink_t *RESTRICT)((size_t) rlink->trie_next + fieldoffset))->trie_prev=r; + break; + } + keybit>>=1; + keybitset=!!(rkey&keybit); + childnode=nodelink->trie_child[keybitset]; + if(!childnode) + { /* Insert here */ + rlink->trie_parent=node; + nodelink->trie_child[keybitset]=r; + break; + } + } +end: + head->count++; +#if NEDTRIEDEBUG + triecheckvalidity(head); +#endif + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_INSERT(proto, name, type, field, keyfunct) \ + proto INLINE void name##_NEDTRIE_INSERT(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node, *RESTRICT childnode; \ + size_t rkey=keyfunct(r), keybit, nodekey; \ + unsigned bitidx; \ + int keybitset; \ +\ + memset(&r->field, 0, sizeof(r->field)); \ + bitidx=nedtriebitscanr(rkey); \ + assert(bitidxtriebins[bitidx])) \ + { /* Bottom two bits set indicates a node hanging off of head */ \ + r->field.trie_parent=(struct type *RESTRICT)(size_t)(3|(bitidx<<2)); \ + head->triebins[bitidx]=r; \ + goto end; \ + } \ + /* Avoid variable bit shifts where possible, their performance can suck */ \ + keybit=(size_t) 1<field.trie_parent=0; \ + r->field.trie_prev=node; \ + r->field.trie_next=node->field.trie_next; \ + node->field.trie_next=r; \ + if(r->field.trie_next) r->field.trie_next->field.trie_prev=r; \ + break; \ + } \ + keybit>>=1; \ + keybitset=!!(rkey&keybit); \ + childnode=node->field.trie_child[keybitset]; \ + if(!childnode) \ + { /* Insert here */ \ + r->field.trie_parent=node; \ + node->field.trie_child[keybitset]=r; \ + break; \ + } \ + } \ +end: \ + head->count++; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_INSERT(proto, name, type, field, keyfunct) \ + proto INLINE void name##_NEDTRIE_INSERT(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + nedtries::trieinsert(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE void trieremove(trietype *RESTRICT head, type *RESTRICT r) + { + type *RESTRICT node, **myaddrinparent=0; + TrieLink_t *RESTRICT nodelink, *RESTRICT childlink, *RESTRICT rlink; + unsigned bitidx; + + rlink=(TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + /* Am I a leaf off the tree? */ + if(rlink->trie_prev) + { /* Remove from linked list */ + assert(!rlink->trie_parent); + node=rlink->trie_prev; + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + nodelink->trie_next=rlink->trie_next; + if(rlink->trie_next) + { + nodelink=(TrieLink_t *RESTRICT)((size_t) rlink->trie_next + fieldoffset); + nodelink->trie_prev=node; + } + goto functexit; + } + /* I must therefore be part of the tree */ + assert(rlink->trie_parent); + assert(!rlink->trie_prev); + /* Am I at the top of the tree? */ + if(((size_t) rlink->trie_parent & 3)==3) + { /* Extract my bitidx */ + bitidx=(unsigned)(((size_t) rlink->trie_parent)>>2); + assert(head->triebins[bitidx]==r); + /* Set the node addr to be modified */ + myaddrinparent=&head->triebins[bitidx]; + } + else + { /* Otherwise I am one of my parent's children */ + node=rlink->trie_parent; + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + myaddrinparent=(nodelink->trie_child[0]==r) ? &nodelink->trie_child[0] : &nodelink->trie_child[1]; + } + assert(*myaddrinparent==r); + node=0; + /* Can I replace me with a sibling? */ + if(rlink->trie_next) + { + node=rlink->trie_next; + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + assert(nodelink->trie_prev==r); + nodelink->trie_prev=0; + goto end; + } + /* Can I simply remove myself from my parent? */ + if(!rlink->trie_child[0] && !rlink->trie_child[1]) + goto end; + /* I need someone to replace me in the trie, so simply find any + grandchild of mine (who has the right bits to be here) which has no children. + */ + { + type *RESTRICT *RESTRICT childaddrinparent=myaddrinparent, *RESTRICT *RESTRICT newchildaddrinparent; + int nobbledir=nobblefunct(head); + while(*(newchildaddrinparent=&(((TrieLink_t *RESTRICT)((size_t) *childaddrinparent + fieldoffset))->trie_child[nobbledir])) + || *(newchildaddrinparent=&(((TrieLink_t *RESTRICT)((size_t) *childaddrinparent + fieldoffset))->trie_child[!nobbledir]))) + childaddrinparent=newchildaddrinparent; + node=*childaddrinparent; + *childaddrinparent=0; + } + end: + if(node) + { + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + assert(!nodelink->trie_child[0] && !nodelink->trie_child[1]); + nodelink->trie_parent=rlink->trie_parent; + nodelink->trie_child[0]=rlink->trie_child[0]; + nodelink->trie_child[1]=rlink->trie_child[1]; + if(nodelink->trie_child[0]) + { + childlink=(TrieLink_t *RESTRICT)((size_t) nodelink->trie_child[0] + fieldoffset); + childlink->trie_parent=node; + } + if(nodelink->trie_child[1]) + { + childlink=(TrieLink_t *RESTRICT)((size_t) nodelink->trie_child[1] + fieldoffset); + childlink->trie_parent=node; + } + } + *myaddrinparent=node; + functexit: + head->count--; +#if NEDTRIEDEBUG + triecheckvalidity(head); +#endif + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_REMOVE(proto, name, type, field, keyfunct, nobblefunct) \ + proto INLINE void name##_NEDTRIE_REMOVE(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node, **myaddrinparent=0; \ + unsigned bitidx; \ +\ + /* Am I a leaf off the tree? */ \ + if(r->field.trie_prev) \ + { /* Remove from linked list */ \ + assert(!r->field.trie_parent); \ + node=r->field.trie_prev; \ + node->field.trie_next=r->field.trie_next; \ + if(r->field.trie_next) \ + { \ + r->field.trie_next->field.trie_prev=node; \ + } \ + goto functexit; \ + } \ + /* I must therefore be part of the tree */ \ + assert(r->field.trie_parent); \ + assert(!r->field.trie_prev); \ + /* Am I at the top of the tree? */ \ + if(((size_t) r->field.trie_parent & 3)==3) \ + { /* Extract my bitidx */ \ + bitidx=(unsigned)(((size_t) r->field.trie_parent)>>2); \ + assert(head->triebins[bitidx]==r); \ + /* Set the node addr to be modified */ \ + myaddrinparent=&head->triebins[bitidx]; \ + } \ + else \ + { /* Otherwise I am one of my parent's children */ \ + node=r->field.trie_parent; \ + myaddrinparent=(node->field.trie_child[0]==r) ? &node->field.trie_child[0] : &node->field.trie_child[1]; \ + } \ + assert(*myaddrinparent==r); \ + node=0; \ + /* Can I replace me with a sibling? */ \ + if(r->field.trie_next) \ + { \ + node=r->field.trie_next; \ + assert(node->field.trie_prev==r); \ + node->field.trie_prev=0; \ + goto end; \ + } \ + /* Can I simply remove myself from my parent? */ \ + if(!r->field.trie_child[0] && !r->field.trie_child[1]) \ + goto end; \ + /* I need someone to replace me in the trie, so simply find any \ + grandchild of mine (who has the right bits to be here) which has no children. \ + */ \ + { \ + struct type *RESTRICT *RESTRICT childaddrinparent=myaddrinparent, *RESTRICT *RESTRICT newchildaddrinparent; \ + int nobbledir=nobblefunct(head); \ + while(*(newchildaddrinparent=&(*childaddrinparent)->field.trie_child[nobbledir]) \ + || *(newchildaddrinparent=&(*childaddrinparent)->field.trie_child[!nobbledir])) \ + childaddrinparent=newchildaddrinparent; \ + node=*childaddrinparent; \ + *childaddrinparent=0; \ + } \ + end: \ + if(node) \ + { \ + assert(!node->field.trie_child[0] && !node->field.trie_child[1]); \ + node->field.trie_parent=r->field.trie_parent; \ + node->field.trie_child[0]=r->field.trie_child[0]; \ + node->field.trie_child[1]=r->field.trie_child[1]; \ + if(node->field.trie_child[0]) \ + { \ + node->field.trie_child[0]->field.trie_parent=node; \ + } \ + if(node->field.trie_child[1]) \ + { \ + node->field.trie_child[1]->field.trie_parent=node; \ + } \ + } \ + *myaddrinparent=node; \ + functexit: \ + head->count--; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_REMOVE(proto, name, type, field, keyfunct, nobblefunct) \ + proto INLINE void name##_NEDTRIE_REMOVE(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + nedtries::trieremove(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *triefind(const trietype *RESTRICT head, const type *RESTRICT r) + { + const type *RESTRICT node, *RESTRICT childnode; + const TrieLink_t *RESTRICT nodelink, *RESTRICT rlink; + size_t rkey=keyfunct(r), keybit, nodekey; + unsigned bitidx; + int keybitset; + + if(!head->count) return 0; + rlink=(const TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + bitidx=nedtriebitscanr(rkey); + assert(bitidxtriebins[bitidx])) + return 0; + /* Avoid variable bit shifts where possible, their performance can suck */ + keybit=(size_t) 1< *RESTRICT)((size_t) node + fieldoffset); + nodekey=keyfunct(node); + if(nodekey==rkey) + goto end; + keybit>>=1; + keybitset=!!(rkey&keybit); + childnode=nodelink->trie_child[keybitset]; + if(!childnode) + return 0; + } + return 0; + end: + return nodelink->trie_next ? nodelink->trie_next : (type *) node; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_FIND(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_FIND(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node, *RESTRICT childnode; \ + size_t rkey=keyfunct(r), keybit, nodekey; \ + unsigned bitidx; \ + int keybitset; \ +\ + if(!head->count) return 0; \ + bitidx=nedtriebitscanr(rkey); \ + assert(bitidxtriebins[bitidx])) \ + return 0; \ + /* Avoid variable bit shifts where possible, their performance can suck */ \ + keybit=(size_t) 1<>=1; \ + keybitset=!!(rkey&keybit); \ + childnode=node->field.trie_child[keybitset]; \ + if(!childnode) \ + return 0; \ + } \ + return 0; \ + end: \ + return node->field.trie_next ? node->field.trie_next : node; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_FIND(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_FIND(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + return nedtries::triefind(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE int trieexactfind(const trietype *RESTRICT head, const type *RESTRICT r) + { + const type *RESTRICT node; + const TrieLink_t *RESTRICT nodelink; + + if(!head->count) return 0; + if(!(node=triefind(head, r))) return 0; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + if(nodelink->trie_prev) node=nodelink->trie_prev; + do + { + if(node==r) return 1; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + node=nodelink->trie_next; + } while(node); + return 0; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_EXACTFIND(proto, name, type, field, keyfunct) \ + proto INLINE int name##_NEDTRIE_EXACTFIND(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node; \ +\ + if(!head->count) return 0; \ + if(!(node=name##_NEDTRIE_FIND(head, r))) return 0; \ + if(node->field.trie_prev) node=node->field.trie_prev; \ + do \ + { \ + if(node==r) return 1; \ + node=node->field.trie_next; \ + } while(node); \ + return 0; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_EXACTFIND(proto, name, type, field, keyfunct) \ + proto INLINE int name##_NEDTRIE_EXACTFIND(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + return nedtries::trieexactfind(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *trieCfind(const trietype *RESTRICT head, const type *RESTRICT r, int rounds) + { + const type *RESTRICT node=0, *RESTRICT childnode, *RESTRICT ret=0; + const TrieLink_t *RESTRICT nodelink, *RESTRICT rlink; + size_t rkey=keyfunct(r), keybit, nodekey; + unsigned binbitidx; + int keybitset; + + if(!head->count) return 0; + rlink=(const TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + binbitidx=nedtriebitscanr(rkey); + assert(binbitidxtriebins[binbitidx])) + binbitidx++; + if(binbitidx>=NEDTRIE_INDEXBINS) + return 0; + bitidx=binbitidx; + /* Avoid variable bit shifts where possible, their performance can suck */ + keybit=(size_t) 1< *RESTRICT)((size_t) node + fieldoffset); + nodekey=keyfunct(node); + /* If nodekey is a closer fit to search key, mark as best result so far */ + if(nodekey>=rkey && nodekey-rkey *RESTRICT)((size_t) node + fieldoffset); + /* If a child is a closer fit to search key, mark as best result so far */ + if(nodelink->trie_child[0]) + { + nodekey=keyfunct(nodelink->trie_child[0]); + if(nodekey>=rkey && nodekey-rkeytrie_child[0]; + retkey=nodekey-rkey; + } + } + if(nodelink->trie_child[1]) + { + nodekey=keyfunct(nodelink->trie_child[1]); + if(nodekey>=rkey && nodekey-rkeytrie_child[1]; + retkey=nodekey-rkey; + } + } + if(rounds--<=0 && ret) return (type *) ret; + /* Which child branch should we check? */ + keybit>>=1; + keybitset=!!(rkey&keybit); + childnode=nodelink->trie_child[keybitset]; + /* If no child and we were checking lowest, check highest */ + if(!childnode && !keybitset) + childnode=nodelink->trie_child[1]; + if(!childnode) break; + } + if(!ret) + { /* If we didn't find any node bigger than rkey, bump up a bin + and look for the smallest possible key in that */ + binbitidx++; + /* From now on, always match lowest */ + retkey+=rkey; + rkey=0; + continue; + } + } while(!ret); + nodelink=(const TrieLink_t *RESTRICT)((size_t) ret + fieldoffset); + return nodelink->trie_next ? nodelink->trie_next : (type *) ret; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_CFIND(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_CFIND(struct name *RESTRICT head, struct type *RESTRICT r, int rounds) \ + { \ + struct type *RESTRICT node=0, *RESTRICT childnode, *RESTRICT ret=0; \ + size_t rkey=keyfunct(r), keybit, nodekey; \ + unsigned binbitidx; \ + int keybitset; \ + \ + if(!head->count) return 0; \ + binbitidx=nedtriebitscanr(rkey); \ + assert(binbitidxtriebins[binbitidx])) \ + binbitidx++; \ + if(binbitidx>=NEDTRIE_INDEXBINS) \ + return 0; \ + bitidx=binbitidx; \ + /* Avoid variable bit shifts where possible, their performance can suck */ \ + keybit=(size_t) 1<=rkey && nodekey-rkeyfield.trie_child[0]) \ + { \ + nodekey=keyfunct(node->field.trie_child[0]); \ + if(nodekey>=rkey && nodekey-rkeyfield.trie_child[0]; \ + retkey=nodekey-rkey; \ + } \ + } \ + if(node->field.trie_child[1]) \ + { \ + nodekey=keyfunct(node->field.trie_child[1]); \ + if(nodekey>=rkey && nodekey-rkeyfield.trie_child[1]; \ + retkey=nodekey-rkey; \ + } \ + } \ + if(rounds--<=0 && ret) return ret; \ + /* Which child branch should we check? */ \ + keybit>>=1; \ + keybitset=!!(rkey&keybit); \ + childnode=node->field.trie_child[keybitset]; \ + /* If no child and we were checking lowest, check highest */ \ + if(!childnode && !keybitset) \ + childnode=node->field.trie_child[1]; \ + if(!childnode) break; \ + } \ + if(!ret) \ + { /* If we didn't find any node bigger than rkey, bump up a bin \ + and look for the smallest possible key in that */ \ + binbitidx++; \ + /* From now on, always match lowest */ \ + retkey+=rkey; \ + rkey=0; \ + continue; \ + } \ + } while(!ret); \ + return ret->field.trie_next ? ret->field.trie_next : ret; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_CFIND(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_CFIND(struct name *RESTRICT head, struct type *RESTRICT r, int rounds) \ +{ \ + return nedtries::trieCfind(head, r, rounds); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *trieminmax(const trietype *RESTRICT head, const unsigned dir) + { + const type *RESTRICT node=0, *RESTRICT child; + const TrieLink_t *RESTRICT nodelink; + unsigned bitidx; + if(!head->count) return 0; + if(!dir) + { /* He wants min */ + for(bitidx=0; bitidxtriebins[bitidx]); bitidx++); + assert(node); + return (type *) node; + } + /* He wants max */ + for(bitidx=NEDTRIE_INDEXBINS-1; bitidxtriebins[bitidx]); bitidx--); + assert(node); + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + while((child=nodelink->trie_child[1] ? nodelink->trie_child[1] : nodelink->trie_child[0])) + { + node=child; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + /* Now go to end leaf */ + while(nodelink->trie_next) + { + node=nodelink->trie_next; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + return (type *) node; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_MINMAX(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_MINMAX(struct name *RESTRICT head, const unsigned dir) \ + { \ + struct type *RESTRICT node=0, *RESTRICT child; \ + unsigned bitidx; \ + if(!head->count) return 0; \ + if(!dir) \ + { /* He wants min */ \ + for(bitidx=0; bitidxtriebins[bitidx]); bitidx++); \ + assert(node); \ + return node; \ + } \ + /* He wants max */ \ + for(bitidx=NEDTRIE_INDEXBINS-1; bitidxtriebins[bitidx]); bitidx--); \ + assert(node); \ + while((child=node->field.trie_child[1] ? node->field.trie_child[1] : node->field.trie_child[0])) \ + { \ + node=child; \ + } \ + /* Now go to end leaf */ \ + while(node->field.trie_next) \ + { \ + node=node->field.trie_next; \ + } \ + return node; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_MINMAX(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_MINMAX(struct name *RESTRICT head, unsigned dir) \ +{ \ + return nedtries::trieminmax(head, dir); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *triebranchprev(const type *RESTRICT r, const TrieLink_t *RESTRICT *rlinkaddr) + { + const type *RESTRICT node=0, *RESTRICT child; + const TrieLink_t *RESTRICT nodelink, *RESTRICT rlink; + + rlink=(TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + /* Am I a leaf off the tree? */ + if(rlink->trie_prev) + { + assert(!rlink->trie_parent); + return rlink->trie_prev; + } + /* Trace up my parents to prev branch */ + while(((size_t) rlink->trie_parent & 3)!=3) + { + node=rlink->trie_parent; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + /* If I was on child[1] and there is a child[0], go to bottom of child[0] */ + if(nodelink->trie_child[1]==r && nodelink->trie_child[0]) + { + node=nodelink->trie_child[0]; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + /* Follow child[1] preferentially downwards */ + while((child=nodelink->trie_child[1] ? nodelink->trie_child[1] : nodelink->trie_child[0])) + { + node=child; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + } + /* If I was already on child[0] or there are no more children, return this node */ + /* Now go to end leaf */ + while(nodelink->trie_next) + { + node=nodelink->trie_next; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + return (type *) node; + } + /* I have reached the top of my trie, no more on this branch */ + if(rlinkaddr) *rlinkaddr=rlink; + return 0; + } + + template DEBUGINLINE type *trieprev(const trietype *RESTRICT head, const type *RESTRICT r) + { + const type *RESTRICT node=0, *RESTRICT child; + const TrieLink_t *RESTRICT nodelink, *RESTRICT rlink=0; + unsigned bitidx; + + if((node=triebranchprev(r, &rlink))) return (type *) node; + /* I have reached the top of my trie, so on to prev bin */ + bitidx=(unsigned)(((size_t) rlink->trie_parent)>>2); + assert(head->triebins[bitidx]==r); + for(bitidx--; bitidxtriebins[bitidx]); bitidx--); + if(bitidx>=NEDTRIE_INDEXBINS) return 0; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + /* Follow child[1] preferentially downwards */ + while((child=nodelink->trie_child[1] ? nodelink->trie_child[1] : nodelink->trie_child[0])) + { + node=child; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + /* Now go to end leaf */ + while(nodelink->trie_next) + { + node=nodelink->trie_next; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + } + return (type *) node; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_PREV(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_BRANCHPREV(struct type *RESTRICT *RESTRICT r) \ + { \ + struct type *RESTRICT node=0, *RESTRICT child; \ +\ + /* Am I a leaf off the tree? */ \ + if((*r)->field.trie_prev) \ + { \ + assert(!(*r)->field.trie_parent); \ + return (*r)->field.trie_prev; \ + } \ + /* Trace up my parents to prev branch */ \ + while(((size_t) (*r)->field.trie_parent & 3)!=3) \ + { \ + node=(*r)->field.trie_parent; \ + /* If I was on child[1] and there is a child[0], go to bottom of child[0] */ \ + if(node->field.trie_child[1]==(*r) && node->field.trie_child[0]) \ + { \ + node=node->field.trie_child[0]; \ + /* Follow child[1] preferentially downwards */ \ + while((child=node->field.trie_child[1] ? node->field.trie_child[1] : node->field.trie_child[0])) \ + { \ + node=child; \ + } \ + } \ + /* If I was already on child[0] or there are no more children, return this node */ \ + /* Now go to end leaf */ \ + while(node->field.trie_next) \ + { \ + node=node->field.trie_next; \ + } \ + return node; \ + } \ + /* I have reached the top of my trie, no more on this branch */ \ + return 0; \ + } \ + proto INLINE struct type * name##_NEDTRIE_PREV(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node=0, *RESTRICT child; \ + unsigned bitidx; \ +\ + if((node=name##_NEDTRIE_BRANCHPREV(&r))) return node; \ + /* I have reached the top of my trie, so on to prev bin */ \ + bitidx=(unsigned)(((size_t) r->field.trie_parent)>>2); \ + assert(head->triebins[bitidx]==r); \ + for(bitidx--; bitidxtriebins[bitidx]); bitidx--); \ + if(bitidx>=NEDTRIE_INDEXBINS) return 0; \ + /* Follow child[1] preferentially downwards */ \ + while((child=node->field.trie_child[1] ? node->field.trie_child[1] : node->field.trie_child[0])) \ + { \ + node=child; \ + } \ + /* Now go to end leaf */ \ + while(node->field.trie_next) \ + { \ + node=node->field.trie_next; \ + } \ + return node; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_PREV(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_PREV(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + return nedtries::trieprev(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *triebranchnext(const type *RESTRICT r, const TrieLink_t *RESTRICT *rlinkaddr) + { + const type *RESTRICT node; + const TrieLink_t *RESTRICT nodelink, *RESTRICT rlink; + + rlink=(const TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + /* Am I a leaf off the tree? */ + if(rlink->trie_next) + return rlink->trie_next; + /* If I am the end leaf off a tree, put me back at my tree node */ + while(!rlink->trie_parent) + { + r=rlink->trie_prev; + rlink=(const TrieLink_t *RESTRICT)((size_t) r + fieldoffset); + } + /* Follow my children, preferring child[0] */ + if((node=rlink->trie_child[0] ? rlink->trie_child[0] : rlink->trie_child[1])) + { + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + assert(nodelink->trie_parent==r); + return (type *) node; + } + /* Trace up my parents to next branch */ + while(((size_t) rlink->trie_parent & 3)!=3) + { + node=rlink->trie_parent; + nodelink=(const TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + if(nodelink->trie_child[0]==r && nodelink->trie_child[1]) + { + return nodelink->trie_child[1]; + } + r=node; + rlink=nodelink; + } + /* I have reached the top of my trie, no more on this branch */ + if(rlinkaddr) *rlinkaddr=rlink; + return 0; + } + + template DEBUGINLINE type *trienext(const trietype *RESTRICT head, const type *RESTRICT r) + { + const type *RESTRICT node; + const TrieLink_t *RESTRICT rlink=0; + unsigned bitidx; + + if((node=triebranchnext(r, &rlink))) return (type *) node; + /* I have reached the top of my trie, so on to next bin */ + bitidx=(unsigned)(((size_t) rlink->trie_parent)>>2); + for(bitidx++; bitidxtriebins[bitidx]); bitidx++); + if(bitidx>=NEDTRIE_INDEXBINS) return 0; + return (type *) node; + } +} +#endif /* __cplusplus */ +#if NEDTRIEUSEMACROS +#define NEDTRIE_GENERATE_NEXT(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_BRANCHNEXT(struct type *RESTRICT *RESTRICT r) \ + { \ + struct type *RESTRICT node; \ +\ + /* Am I a leaf off the tree? */ \ + if((*r)->field.trie_next) \ + return (*r)->field.trie_next; \ + /* If I am the end leaf off a tree, put me back at my tree node */ \ + while(!(*r)->field.trie_parent) \ + { \ + (*r)=(*r)->field.trie_prev; \ + } \ + /* Follow my children, preferring child[0] */ \ + if((node=(*r)->field.trie_child[0] ? (*r)->field.trie_child[0] : (*r)->field.trie_child[1])) \ + { \ + assert(node->field.trie_parent==(*r)); \ + return node; \ + } \ + /* Trace up my parents to next branch */ \ + while(((size_t) (*r)->field.trie_parent & 3)!=3) \ + { \ + node=(*r)->field.trie_parent; \ + if(node->field.trie_child[0]==(*r) && node->field.trie_child[1]) \ + { \ + return node->field.trie_child[1]; \ + } \ + (*r)=node; \ + } \ + return 0; \ + } \ + proto INLINE struct type * name##_NEDTRIE_NEXT(struct name *RESTRICT head, struct type *RESTRICT r) \ + { \ + struct type *RESTRICT node; \ + unsigned bitidx; \ +\ + if((node=name##_NEDTRIE_BRANCHNEXT(&r))) return node; \ + /* I have reached the top of my trie, so on to next bin */ \ + bitidx=(unsigned)(((size_t) r->field.trie_parent)>>2); \ + assert(head->triebins[bitidx]==r); \ + for(bitidx++; bitidxtriebins[bitidx]); bitidx++); \ + if(bitidx>=NEDTRIE_INDEXBINS) return 0; \ + return node; \ + } +#else /* NEDTRIEUSEMACROS */ +#define NEDTRIE_GENERATE_NEXT(proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_NEXT(struct name *RESTRICT head, struct type *RESTRICT r) \ +{ \ + return nedtries::trienext(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + +#ifdef __cplusplus +namespace nedtries { + template DEBUGINLINE type *trieNfind(const trietype *RESTRICT head, const type *RESTRICT r) + { + const type *RESTRICT node=0, *RESTRICT ret=trieCfind(head, r, INT_MAX), *RESTRICT stop; + const TrieLink_t *RESTRICT rlink; + size_t rkey=keyfunct(r), retkey, nodekey; + + if(!ret) return 0; + if(!(retkey=keyfunct(ret)-rkey)) return (type *) ret; + /* Cfind basically does a find but if it doesn't find an exact match it early outs + with the closest result it found during the find. As nodes with children have a key + which is only guaranteed to be correct under its parent's constraints and has nothing + to do with its children, there may be a closer key in any of the children of the node + returned. Hence we iterate the local subbranch, looking for closer fits. */ + rlink=(const TrieLink_t *RESTRICT)((size_t) ret + fieldoffset); + stop=rlink->trie_parent; + for(node=triebranchnext(ret, 0); node && node!=stop; node=triebranchnext(node, 0)) + { + nodekey=keyfunct(node); + /* If nodekey is a closer fit to search key, mark as best result so far */ + if(nodekey>=rkey && nodekey-rkeyfield.trie_parent; \ + for(node=ret, node=name##_NEDTRIE_BRANCHNEXT(&node); node && node!=stop; node=name##_NEDTRIE_BRANCHNEXT(&node)) \ + { \ + nodekey=keyfunct(node); \ + /* If nodekey is a closer fit to search key, mark as best result so far */ \ + if(nodekey>=rkey && nodekey-rkey(head, r); \ +} +#endif /* NEDTRIEUSEMACROS */ + + +/*! \def NEDTRIE_GENERATE +\brief Substitutes a set of nedtrie implementation function definitions specialised according to type. +*/ +#define NEDTRIE_GENERATE(proto, name, type, field, keyfunct, nobblefunct) \ + NEDTRIE_GENERATE_NOBBLES (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_INSERT (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_REMOVE (proto, name, type, field, keyfunct, nobblefunct) \ + NEDTRIE_GENERATE_FIND (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_EXACTFIND(proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_CFIND (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_MINMAX (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_PREV (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_NEXT (proto, name, type, field, keyfunct) \ + NEDTRIE_GENERATE_NFIND (proto, name, type, field, keyfunct) \ + proto INLINE struct type * name##_NEDTRIE_PREVLEAF(struct type *r) { return (r)->field.trie_prev; } \ + proto INLINE struct type * name##_NEDTRIE_NEXTLEAF(struct type *r) { return (r)->field.trie_next; } + +/*! \def NEDTRIE_INSERT +\brief Inserts item y into nedtrie x. +*/ +#define NEDTRIE_INSERT(name, x, y) name##_NEDTRIE_INSERT(x, y) +/*! \def NEDTRIE_REMOVE +\brief Removes item y from nedtrie x. +*/ +#define NEDTRIE_REMOVE(name, x, y) name##_NEDTRIE_REMOVE(x, y) +/*! \def NEDTRIE_FIND +\brief Finds the item with the same key as y in nedtrie x. +*/ +#define NEDTRIE_FIND(name, x, y) name##_NEDTRIE_FIND(x, y) +/*! \def NEDTRIE_EXACTFIND +\brief Returns true if there is an item with the same key and address as y in nedtrie x. +*/ +#define NEDTRIE_EXACTFIND(name, x, y) name##_NEDTRIE_EXACTFIND(x, y) +/*! \def NEDTRIE_CFIND +\brief Performs \em rounds number of attempts to find an item with an equal key to y in nedtrie x, and +if none equal then the closest item with a larger key. Always returns a larger key if there is a larger +key in the trie, if there isn't it returns zero. Think of rounds as how closely you want the find to fit +the requested key, so \c INT_MAX means "as close as possible". Note that Cfind does NOT guarantee that +the item returned is the next largest keyed item, use Nfind for that. +*/ +#define NEDTRIE_CFIND(name, x, y, rounds) name##_NEDTRIE_CFIND(x, y, rounds) +/*! \def NEDTRIE_NFIND +\brief Finds an item with an equal key to y in nedtrie x, and if none equal then the item with the next +largest key. If the key is not equal, the returned item is guaranteed to be the next largest keyed item. +*/ +#define NEDTRIE_NFIND(name, x, y) name##_NEDTRIE_NFIND(x, y) +/*! \def NEDTRIE_PREV +\brief Returns the item preceding y in nedtrie x. +*/ +#define NEDTRIE_PREV(name, x, y) name##_NEDTRIE_PREV(x, y) +/*! \def NEDTRIE_NEXT +\brief Returns the item following y in nedtrie x. +*/ +#define NEDTRIE_NEXT(name, x, y) name##_NEDTRIE_NEXT(x, y) +/*! \def NEDTRIE_PREVLEAF +\brief Returns the item with an identical key preceding y in nedtrie x. +*/ +#define NEDTRIE_PREVLEAF(name, x) name##_NEDTRIE_PREVLEAF(x) +/*! \def NEDTRIE_NEXTLEAF +\brief Returns the item with an identical key following y in nedtrie x. +*/ +#define NEDTRIE_NEXTLEAF(name, x) name##_NEDTRIE_NEXTLEAF(x) +/*! \def NEDTRIE_MIN +\brief Returns the lowest item in nedtrie x. This item will approximately have the smallest key. +*/ +#define NEDTRIE_MIN(name, x) name##_NEDTRIE_MINMAX(x, 0) +/*! \def NEDTRIE_MAX +\brief Returns the highest item in nedtrie x. This item will approximately have the biggest key. +*/ +#define NEDTRIE_MAX(name, x) name##_NEDTRIE_MINMAX(x, 1) + +/*! \def NEDTRIE_FOREACH +\brief Substitutes a for loop which forward iterates into x all items in nedtrie head. Order of +items is mostly in key order (enough that a bubble sort is efficient). +*/ +#define NEDTRIE_FOREACH(x, name, head) \ + for ((x) = NEDTRIE_MIN(name, head); \ + (x) != NULL; \ + (x) = NEDTRIE_NEXT(name, head, x)) + +/*! \def NEDTRIE_FOREACH_SAFE +\brief Substitutes a for loop which forward iterates into x all items in +nedtrie head and is safe against removal of x. Order of items is mostly +in key order (enough that a bubble sort is efficient). +*/ +#define NEDTRIE_FOREACH_SAFE(x, name, head, y) \ + for ((x) = NEDTRIE_MIN(name, head); \ + (x) != NULL && ((y) = NEDTRIE_NEXT(name, head, x), 1); \ + (x) = (y)) + +/*! \def NEDTRIE_FOREACH_REVERSE +\brief Substitutes a for loop which reverse iterates into x all items in nedtrie head. Order of +items is mostly inverse to key order (enough that a bubble sort is efficient). +*/ +#define NEDTRIE_FOREACH_REVERSE(x, name, head) \ + for ((x) = NEDTRIE_MAX(name, head); \ + (x) != NULL; \ + (x) = NEDTRIE_PREV(name, head, x)) + +/*! \def NEDTRIE_FOREACH_REVERSE_SAFE +\brief Substitutes a for loop which reverse iterates into x all items in nedtrie head and is +safe against removal of x. Order of items is mostly inverse to key order (enough that a bubble +sort is efficient). +*/ +#define NEDTRIE_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = NEDTRIE_MAX(name, head); \ + (x) != NULL && ((y) = NEDTRIE_PREV(name, head, x), 1); \ + (x) = (y)) + +/*! \def NEDTRIE_HASNODEHEADER +\brief Returns true if this item's node header is active. Useful as a quick check for whether a node is in some trie. +*/ +#define NEDTRIE_HASNODEHEADER(treevar, node, link) ((node)->link.trie_parent || (node)->link.trie_prev) + +#ifdef __cplusplus +#include +namespace nedtries { + +#ifndef NDEBUG + typedef struct TrieValidityState_t + { + size_t count, smallestkey, largestkey, tops, lefts, rights, leafs; + } TrieValidityState; + + template DEBUGINLINE + void triecheckvaliditybranch(trietype *head, type *RESTRICT node, unsigned bitidx, TrieValidityState &state) + { + type *RESTRICT child; + TrieLink_t *RESTRICT nodelink, *RESTRICT childlink; + size_t nodekey=keyfunct(node); + + if(nodekeystate.largestkey) state.largestkey=nodekey; + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + assert(nodelink->trie_parent); + child=nodelink->trie_parent; + childlink=(TrieLink_t *RESTRICT)((size_t) child + fieldoffset); + assert(childlink->trie_child[0]==node || childlink->trie_child[1]==node); + assert(node==childlink->trie_child[!!(nodekey & ((size_t) 1<trie_prev); + while((child=nodelink->trie_next)) + { + state.leafs++; + childlink=(TrieLink_t *RESTRICT)((size_t) child + fieldoffset); + assert(!childlink->trie_parent); + assert(!childlink->trie_child[0]); + assert(!childlink->trie_child[1]); + assert(childlink->trie_prev); + assert(!childlink->trie_next || child==((TrieLink_t *RESTRICT)((size_t) childlink->trie_next + fieldoffset))->trie_prev); + nodelink=childlink; + state.count++; + } + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + state.count++; + if(nodelink->trie_child[0]) + { + state.lefts++; + triecheckvaliditybranch(head, nodelink->trie_child[0], bitidx-1, state); + } + if(nodelink->trie_child[1]) + { + state.rights++; + triecheckvaliditybranch(head, nodelink->trie_child[1], bitidx-1, state); + } + } +#endif + template DEBUGINLINE void triecheckvalidity(trietype *head) + { +#ifndef NDEBUG + type *RESTRICT node, *RESTRICT child; + TrieLink_t *RESTRICT nodelink, *RESTRICT childlink; + unsigned n, bitidx; + TrieValidityState state={0}; + for(n=0; ntriebins[n])) + { + size_t nodekey=keyfunct(node); + state.tops++; + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + bitidx=(unsigned)(((size_t) nodelink->trie_parent)>>2); + assert(bitidx==n); + assert(head->triebins[bitidx]==node); + assert(((((size_t)-1)<trie_prev); + while((child=nodelink->trie_next)) + { + state.leafs++; + childlink=(TrieLink_t *RESTRICT)((size_t) child + fieldoffset); + assert(!childlink->trie_parent); + assert(!childlink->trie_child[0]); + assert(!childlink->trie_child[1]); + assert(childlink->trie_prev); + assert(!childlink->trie_next || child==((TrieLink_t *RESTRICT)((size_t) childlink->trie_next + fieldoffset))->trie_prev); + nodelink=childlink; + state.count++; + } + nodelink=(TrieLink_t *RESTRICT)((size_t) node + fieldoffset); + state.count++; + if(nodelink->trie_child[0]) + { + state.lefts++; + state.smallestkey=(size_t)-1; + state.largestkey=0; + triecheckvaliditybranch(head, nodelink->trie_child[0], bitidx-1, state); + assert(state.smallestkey>=(size_t)1<trie_child[1]) + { + state.rights++; + state.smallestkey=(size_t)-1; + state.largestkey=0; + triecheckvaliditybranch(head, nodelink->trie_child[1], bitidx-1, state); + assert(state.smallestkey>=(size_t)1<count); + for(state.count=0, node=trieminmax(head, 0); node; (node=trienext(head, node)), state.count++) +#if 0 + printf("%p\n", node) +#endif + ; + if(state.count!=head->count) + { + assert(state.count==head->count); + } +#if 0 + printf("\n"); +#endif + for(state.count=0, node=trieminmax(head, 1); node; (node=trieprev(head, node)), state.count++) +#if 0 + printf("%p\n", node) +#endif + ; + if(state.count!=head->count) + { + assert(state.count==head->count); + } +#if 0 + printf("\n"); +#endif +#if !defined(NDEBUG) && 0 + if(count>50) + printf("Of count %u, tops %.2lf%%, lefts %.2lf%%, rights %.2lf%%, leafs %.2lf%%\n", count, 100.0*tops/count, 100.0*lefts/count, 100.0*rights/count, 100.0*leafs/count); +#endif +#endif /* !NDEBUG */ + } + + /*! \def HAVE_CPP0XRVALUEREFS + \ingroup C++ + \brief Enables rvalue references + + Define to enable the usage of rvalue references which enables move semantics and + other things. Automatically defined if __cplusplus indicates a C++0x compiler, + otherwise you'll need to set it yourself. + */ +#if __cplusplus > 199711L || (defined(_MSC_VER) && _MSC_VER>=1600) || defined(HAVE_CPP0X) /* Do we have C++0x? */ +#undef HAVE_CPP0XRVALUEREFS +#define HAVE_CPP0XRVALUEREFS 1 +#undef HAVE_CPP0XTYPETRAITS +#define HAVE_CPP0XTYPETRAITS 1 +#endif + +/*! \brief The policy namespace in which all nedtries policies live. */ + namespace nedpolicy + { + /*! \class nobblezeros + \brief A policy nobbling zeros + */ + template class nobblezeros + { + protected: + template static int trie_nobblefunction(trietype *) + { + return 0; + } + }; + /*! \class nobbleones + \brief A policy nobbling ones + */ + template class nobbleones + { + protected: + template static int trie_nobblefunction(trietype *) + { + return 1; + } + }; + /*! \class nobbleequally + \brief A policy nobbling zeros and ones equally + */ + template class nobbleequally + { + protected: + template static int trie_nobblefunction(trietype *head) + { + return (head->nobbledir=!head->nobbledir); + } + }; + } // namspace + template NEDTRIE_HEAD2(trie_map_head, type); + template struct trie_maptype; + /*! \struct trie_keyfunct + \ingroup C++ + \brief Calculates the key for a given instance of type + + You only really need to use this if you are using trie_multimap or trie_map without the operator[] + override. If using with trie_map, make sure you force the use of trie_keyfunct in its template + parameters as it defaults to an internal thunk type used to indirect access to an embedded key store. + + Specialise this as follows for your type: + \code + namespace nedtries { + template<> struct trie_keyfunct : public std::unary_function + { + size_t operator()(const yourtype *RESTRICT v) const + { + return v->yourtypekeyvalue; + } + }; + } + \endcode + */ + template struct trie_keyfunct : public std::unary_function + { +#ifdef HAVE_CPP0XRVALUEREFS + keytype operator()(const type &v) const + { + static_assert(false, "trie_keyfunct has not been specialised for this type"); + } +#else + private: + keytype operator()(const type &) const; +#endif + }; + template struct trie_maptype_keyfunct : public std::unary_function + { + template keytype operator()(const maptype &v) const + { + return v.trie_keyvalue; + } + }; + namespace intern { + template struct noconstiteratortype : public type { }; + template size_t to_Ckeyfunct(const mapvaluetype *RESTRICT v) + { + return keyfunct_()(*v); + } + } + template class nobblepolicy, class stlcontainer, + class iteratortype, int dir, class mapvaluetype, class constiteratortype=intern::noconstiteratortype > class trie_iterator; + template, + class allocator=std::allocator::iterator> >, + template class nobblepolicy=nedpolicy::nobblezeros, + class stlcontainer=std::list::iterator>, allocator> > class trie_map; + template, + class allocator=std::allocator::iterator> >, + template class nobblepolicy=nedpolicy::nobblezeros, + class stlcontainer=std::list::iterator>, allocator> > class trie_multimap; + /*! \struct trie_maptype + \ingroup C++ + \brief Encapsulates the nedtrie metadata with the given type + + Note that the nedtrie metadata is kept \em after the typed value - this prevents the nedtrie metadata interfering + with any special data alignment you might be using from a specialised STL allocator. + */ + namespace fake { + template struct trie_maptype + { + template friend struct trie_keyfunct; + template class nobblepolicy, class stlcontainer, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + template class nobblepolicy, class stlcontainer> friend class trie_map; + template class nobblepolicy, class stlcontainer> friend class trie_multimap; + typedef keytype trie_key_type; + typedef type trie_value_type; + typedef keyfunct trie_keyfunct_type; + typedef iteratortype trie_iterator_type; + type trie_value; + iteratortype trie_iterator; + TrieLink_t trie_link; + }; + } + template struct trie_maptype + { + private: // ENSURE the fake type above mirrors this one + template friend struct trie_keyfunct; + template class nobblepolicy, class stlcontainer, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + template class nobblepolicy, class stlcontainer> friend class trie_map; + template class nobblepolicy, class stlcontainer> friend class trie_multimap; + typedef keytype trie_key_type; + typedef type trie_value_type; + typedef keyfunct trie_keyfunct_type; + typedef iteratortype trie_iterator_type; + typedef fake::trie_maptype fakemirrorofme_type; + type trie_value; + iteratortype trie_iterator; + TrieLink_t trie_link; + static const size_t trie_link_offset=NEDTRIEFIELDOFFSET2(fakemirrorofme_type, trie_link); + public: + trie_maptype(const type &v) : trie_value(v) + { // Prevent that memory corruption bug ever happening again + static char ensure_trie_link_offset_is_bounded[trie_link_offset+sizeof(trie_link)<=sizeof(*this)]; + } + template trie_maptype(const trie_maptype &o) : trie_value(o.trie_value) { } +#ifdef HAVE_CPP0XRVALUEREFS + template trie_maptype(trie_maptype &&o) : trie_value(std::move(o.trie_value)) { } +#endif + //! Silent const lvalue converter for type + operator const type &() const { return trie_value; } + }; + namespace fake { + template struct trie_maptype2 + { + template friend struct trie_keyfunct; + template class nobblepolicy, class stlcontainer, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + template class nobblepolicy, class stlcontainer> friend class trie_map; + template class nobblepolicy, class stlcontainer> friend class trie_multimap; + template friend struct trie_maptype_keyfunct; + typedef keytype trie_key_type; + typedef type trie_value_type; + typedef trie_maptype_keyfunct trie_keyfunct_type; + typedef iteratortype trie_iterator_type; + type trie_value; + keytype trie_keyvalue; // For when key is overriden using trie_map::operator[] + iteratortype trie_iterator; + TrieLink_t trie_link; + }; + } + template struct trie_maptype, iteratortype> + { + private: // ENSURE the fake type above mirrors this one + template friend struct trie_keyfunct; + template class nobblepolicy, class stlcontainer, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + template class nobblepolicy, class stlcontainer> friend class trie_map; + template class nobblepolicy, class stlcontainer> friend class trie_multimap; + template friend struct trie_maptype_keyfunct; + typedef keytype trie_key_type; + typedef type trie_value_type; + typedef trie_maptype_keyfunct trie_keyfunct_type; + typedef iteratortype trie_iterator_type; + typedef fake::trie_maptype2 fakemirrorofme_type; + type trie_value; + keytype trie_keyvalue; // For when key is overriden using trie_map::operator[] + iteratortype trie_iterator; + TrieLink_t trie_link; + static const size_t trie_link_offset=NEDTRIEFIELDOFFSET2(fakemirrorofme_type, trie_link); + public: + trie_maptype(const type &v) : trie_value(v) + { // Prevent that memory corruption bug ever happening again + static char ensure_trie_link_offset_is_bounded[trie_link_offset+sizeof(trie_link)<=sizeof(*this)]; + } + template trie_maptype(const trie_maptype, iteratortype_> &o) : trie_value(o.trie_value), trie_keyvalue(o.trie_keyvalue) { } +#ifdef HAVE_CPP0XRVALUEREFS + template trie_maptype(trie_maptype, iteratortype_> &&o) : trie_value(std::move(o.trie_value)), trie_keyvalue(std::move(o.trie_keyvalue)) { } +#endif + //! Silent const lvalue converter for type + operator const type &() const { return trie_value; } + }; + + /*! \class trie_iterator + \ingroup C++ + \brief Iterator for the trie_map and trie_multimap containers + */ + template class nobblepolicy, class stlcontainer, class iteratortype, int dir, class mapvaluetype, class constiteratortype> class trie_iterator : protected iteratortype + { + trie_map *parent; + public: + typedef typename iteratortype::value_type::trie_value_type value_type; + typedef typename iteratortype::difference_type difference_type; + typedef typename iteratortype::pointer pointer; + typedef typename iteratortype::reference reference; + typedef typename iteratortype::iterator_category iterator_category; + + operator constiteratortype () const { return constiteratortype(parent, static_cast(*this)); } + + trie_iterator() : parent(0) { } + trie_iterator(const trie_map *parent_, const iteratortype &o) : iteratortype(o), parent(const_cast *>(parent_)) { } + trie_iterator(const trie_iterator &o) : iteratortype(o), parent(o.parent) { } +#ifdef HAVE_CPP0XRVALUEREFS + trie_iterator(trie_iterator &&o) : iteratortype(std::move(o)), parent(o.parent) { } +#endif + trie_iterator &operator=(const trie_iterator &o) + { + return *new(this) trie_iterator(o); + } +#ifdef HAVE_CPP0XRVALUEREFS + trie_iterator &operator=(trie_iterator &&o) + { + return *new(this) trie_iterator(std::move(o)); + } +#endif + trie_iterator &operator++() + { + mapvaluetype *r=dir>0 ? + trienext, mapvaluetype, mapvaluetype::trie_link_offset, intern::to_Ckeyfunct >(&parent->triehead, (mapvaluetype *)(&**this)) : + trieprev, mapvaluetype, mapvaluetype::trie_link_offset, intern::to_Ckeyfunct >(&parent->triehead, (mapvaluetype *)(&**this)); + if(r) + new(this) iteratortype((iteratortype &) r->trie_iterator); // type pun safe + else + *this=parent->end(); + return *this; + } + trie_iterator &operator++(int) { trie_iterator tmp(*this); operator++(); return tmp; } + trie_iterator &operator--() + { + mapvaluetype *r=dir<0 ? + trienext, mapvaluetype, mapvaluetype::trie_link_offset, intern::to_Ckeyfunct >(&parent->triehead, (mapvaluetype *)(&**this)) : + trieprev, mapvaluetype, mapvaluetype::trie_link_offset, intern::to_Ckeyfunct >(&parent->triehead, (mapvaluetype *)(&**this)); + if(r) + new(this) iteratortype((iteratortype &) r->trie_iterator); + else + *this=parent->end(); + return *this; + } + trie_iterator &operator--(int) { trie_iterator tmp(*this); operator--(); return tmp; } + bool operator==(const trie_iterator &o) const { return static_cast(*this)==static_cast(o); } + bool operator!=(const trie_iterator &o) const { return static_cast(*this)!=static_cast(o); } + const mapvaluetype &operator *() const { return (const mapvaluetype &) iteratortype::operator *(); } + mapvaluetype &operator *() { return (mapvaluetype &) iteratortype::operator *(); } + const mapvaluetype *operator ->() const { return (const mapvaluetype *) iteratortype::operator->(); } + mapvaluetype *operator ->() { return (mapvaluetype *) iteratortype::operator->(); } + }; + + namespace intern + { + template struct keystore_t { size_t magic; const key_type &key; keystore_t(size_t magic_, const key_type &key_) : magic(magic_), key(key_) { } private: keystore_t &operator=(const keystore_t &); }; + template struct findkeyfunct_t : public std::unary_function + { + size_t operator()(const mapvaluetype &v) const + { + keystore_t *r=(keystore_t *)(void *)(&v); + if(r->magic==*(size_t *)"TRIEFINDKEYSTORE") + return r->key; + return keyfunct()(v); + } + }; + } + + /*! \class trie_map + \ingroup C++ + \brief A STL container wrapper using nedtries to map keys to values. + + This class can be used to wrap any arbitrary STL container with nedtrie associativity. For example, if you + had a std::vector<> list of items, you could add nedtrie's fast nearly constant time algorithm for accessing them - + though one would expect that a std::list<> would be the most common combination. There is no strict reason why + one could not wrap std::unordered_map<>, though what one would gain is hard to imagine! + + Usage in the simplest sense is like this as the default template parameters use std::list<> as the underlying + container: + \code + trie_map fooMap; + fooMap[5]=Foo(); + fooMap.erase(fooMap.find(5)); + \endcode + + Unlike a proper STL container implementation, this wrapper is very much a hack in the sense that it's a very quick + and dirty way of implementing lots of nedtrie based STL containers at once. In this sense it does require its user + to not be stupid, and to know what they're doing. STL containers go out of their way to enforce correctness - well, + this wrapper most certainly does not. If you want to blow off your own foot, this implementation won't stop you! + + For example, despite the protected STL container inheritance, all common STL functions are made public so you + can if you want easily corrupt the internal state. Equally, if you know what you are doing you can pass in the + wrapper as a const version of its underlying STL container by reintrpret_cast<>-ing it. Despite this, the wrapper + is fairly typesafe in that its design won't introduce subtle bugs or cause existing code to magically break itself. + + If you would like a more proper bitwise trie STL container class implemented, or would like to be advised on any + algorithmic problems from which your IT project may be suffering, my consulting company ned Productions Consulting Ltd would be happy to advise. In particular + I would love to see a full bitwise trie implementation submitted to the Boost C++ libraries but I don't have the + unpaid time to devote to such an endeavour sadly. + + \warning If you use std::vector<> as the STL container, make SURE you resize() it to its maximum size before use. + Otherwise the iterators trie_map uses to link nedtrie items into the STL items will become invalidated on storage + expansion. + */ + template class nobblepolicy, class stlcontainer> class trie_map : protected stlcontainer, protected nobblepolicy > + { + typedef nobblepolicy > nobblepolicytype; + typedef typename stlcontainer::value_type mapvaluetype; + static const size_t trie_fieldoffset=mapvaluetype::trie_link_offset; + template class nobblepolicy_, class stlcontainer_, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + public: + typedef typename stlcontainer::allocator_type allocator_type; + typedef trie_iterator const_iterator; + typedef typename stlcontainer::const_pointer const_pointer; + typedef typename stlcontainer::const_reference const_reference; + typedef trie_iterator const_reverse_iterator; + typedef typename stlcontainer::difference_type difference_type; + typedef trie_iterator iterator; + typedef keytype key_type; + typedef type mapped_type; + typedef typename stlcontainer::pointer pointer; + typedef typename stlcontainer::reference reference; + typedef trie_iterator reverse_iterator; + typedef typename stlcontainer::size_type size_type; + typedef typename stlcontainer::value_type::trie_value_type value_type; + private: + trie_map_head triehead; + static typename mapvaluetype::trie_iterator_type &from_iterator(iterator &it) + { + void *_it=(void *) ⁢ + return *(typename mapvaluetype::trie_iterator_type *)_it; + } + // Wipes and resets the nedtrie index + void triehead_reindex() + { + NEDTRIE_INIT(&triehead); + for(iterator it=begin(); it!=end(); ++it) + { + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, &(*it)); + it->trie_iterator=it; + } + } + const mapvaluetype *triehead_find(const key_type &key) const + { // Avoid a value_type construction using pure unmitigated evil + char buffer[sizeof(mapvaluetype)]; + new(buffer) intern::keystore_t(*(size_t *)"TRIEFINDKEYSTORE", key); + return triefind, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct > >(&triehead, (mapvaluetype *) buffer); + } + const mapvaluetype *triehead_nfind(const key_type &key) const + { // Avoid a value_type construction using pure unmitigated evil + char buffer[sizeof(mapvaluetype)]; + new(buffer) intern::keystore_t(*(size_t *)"TRIEFINDKEYSTORE", key); + return trieNfind, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct > >(&triehead, (mapvaluetype *) buffer); + } + const mapvaluetype *triehead_cfind(const key_type &key, int rounds) const + { // Avoid a value_type construction using pure unmitigated evil + char buffer[sizeof(mapvaluetype)]; + new(buffer) intern::keystore_t(*(size_t *)"TRIEFINDKEYSTORE", key); + return trieCfind, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct > >(&triehead, (mapvaluetype *) buffer, rounds); + } + iterator triehead_insert(const value_type &val) + { + iterator it=iterator(this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#ifdef HAVE_CPP0XRVALUEREFS + iterator triehead_insert(value_type &&val) + { + iterator it=iterator(this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#endif + iterator triehead_insert(const keytype &key, const value_type &val) + { + iterator it=iterator(this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + it->trie_keyvalue=key; + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#ifdef HAVE_CPP0XRVALUEREFS + iterator triehead_insert(const keytype &key, value_type &&val) + { + iterator it=iterator(this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + it->trie_keyvalue=key; + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#endif + public: + iterator begin() { return iterator(this, stlcontainer::begin()); } + const_iterator begin() const { return const_iterator(this, stlcontainer::begin()); } + using stlcontainer::clear; + //! Returns the number of items with the key \em key + size_type count(const key_type &key) const + { + size_type ret=0; + const mapvaluetype *r=triehead_find(key); + if(r) + { + if(r->trie_link.prev) r=r->trie_link.trie_prev; + for(; r; r=r->trie_link.trie_next) ret++; + } + return ret; + } + using stlcontainer::empty; + iterator end() { return iterator(this, stlcontainer::end()); } + const_iterator end() const { return const_iterator(this, stlcontainer::end()); } + //std::pair equal_range(const key_type &key); + //std::pair equal_range(const key_type &key) const; + //! Removes the item specified by \em it from the container + iterator erase(iterator it) + { + //int (*nobblefunct)(trietype *head) + trieremove, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct, + // Need to give MSVC a little bit of help +#ifdef _MSC_VER + nobblepolicytype::trie_nobblefunction > +#else + nobblepolicytype::trie_nobblefunction +#endif + >(&triehead, &(*it)); + return iterator(this, stlcontainer::erase((typename stlcontainer::iterator &) it)); + } + //! Removes the items between \em first and \em last from the container + iterator erase(iterator first, iterator last) + { + iterator ret(last); ++ret; + for(iterator it=first; it!=last; ++it) + { + trieremove, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct, +#ifdef _MSC_VER + nobblepolicytype::trie_nobblefunction > +#else + nobblepolicytype::trie_nobblefunction +#endif + >(&triehead, &(*it)); + stlcontainer::erase((typename stlcontainer::iterator &) it); + } + return ret; + } + //! Finds the item with key \em key + iterator find(const key_type &key) { const_iterator it=static_cast(this)->find(key); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the item with key \em key + const_iterator find(const key_type &key) const + { + const mapvaluetype *r=triehead_find(key); + return !r ? end() : const_iterator(this, (const typename stlcontainer::const_iterator &) r->trie_iterator); // type pun safe + } + //! Finds the nearest item with key \em key + iterator nfind(const key_type &key) { const_iterator it=static_cast(this)->nfind(key); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the nearest item with key \em key + const_iterator nfind(const key_type &key) const + { + const mapvaluetype *r=triehead_nfind(key); + return !r ? end() : const_iterator(this, (const typename stlcontainer::const_iterator &) r->trie_iterator); + } + //! Finds the closest item with key \em key trying up to \em rounds times + iterator cfind(const key_type &key, int rounds=INT_MAX) { const_iterator it=static_cast(this)->cfind(key, rounds); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the closest item with key \em key trying up to \em rounds times + const_iterator cfind(const key_type &key, int rounds=INT_MAX) const + { + const mapvaluetype *r=triehead_cfind(key, rounds); + return !r ? end() : const_iterator(this, (const typename stlcontainer::const_iterator &) r->trie_iterator); + } + using stlcontainer::get_allocator; + //! Inserts the item \em val + std::pair insert(const value_type &val) + { + mapvaluetype *r=const_cast(triehead_find(keyfunct()(val))); + if(r) + { + r->trie_value=std::move(val); + return std::make_pair(iterator(this, (typename stlcontainer::iterator &) r->trie_iterator), false); + } + return std::make_pair(triehead_insert(std::move(val)), true); + } + //! Inserts the item \em val at position \em at + iterator insert(iterator at, const value_type &val) + { + iterator it=stlcontainer::insert(at, val); + it->trie_iterator=from_iterator(it); + trieinsert >(&triehead, &(*it)); + return it; + } + //! Inserts the items between \em first and \em last + template void insert(inputiterator first, inputiterator last) + { + iterator it=--end(); + stlcontainer::insert(first, last); + for(; it!=end(); ++it) + { + it->trie_iterator=from_iterator(it); + trieinsert >(&triehead, &(*it)); + } + } + //key_compare key_comp() const; + //iterator lower_bound(const key_type &key); + //const_iterator lower_bound(const key_type &key) const; + using stlcontainer::max_size; + reverse_iterator rbegin() { return reverse_iterator(this, stlcontainer::begin()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(this, stlcontainer::begin()); } + reverse_iterator rend() { return reverse_iterator(this, stlcontainer::end()); } + const_reverse_iterator rend() const { return const_reverse_iterator(this, stlcontainer::end()); } + using stlcontainer::size; + using stlcontainer::swap; + //iterator upper_bound(const key_type &key); + //const_iterator upper_bound(const key_type &key) const; + //value_compare value_comp() const; + //! Returns an lvalue reference to the item with key \em key + mapped_type &operator[](const keytype &key) + { + mapvaluetype *r=const_cast(triehead_find(key)); + iterator it; + if(r) + it=iterator(this, (typename stlcontainer::iterator &) r->trie_iterator); // type pun safe + else + { + it=triehead_insert(key, std::move(type())); + } + return it->trie_value; + } + + template class nobblepolicy_, class stlcontainer_> friend bool operator!=(const trie_map &a, const trie_map &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator<(const trie_map &a, const trie_map &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator<=(const trie_map &a, const trie_map &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator==(const trie_map &a, const trie_map &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator>(const trie_map &a, const trie_map &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator>=(const trie_map &a, const trie_map &b); + + //! Constructs a trie_map. Has all the typical STL overloads + trie_map() : stlcontainer() { NEDTRIE_INIT(&triehead); } + explicit trie_map(const allocator &a) : stlcontainer(a) { NEDTRIE_INIT(&triehead); } + template trie_map(const trie_map &o) : stlcontainer(o) { triehead_reindex(); } + template trie_map &operator=(const trie_map &o) { *static_cast(this)=static_cast(o); triehead_reindex(); return *this; } +#ifdef HAVE_CPP0XRVALUEREFS + template trie_map(trie_map &&o) : stlcontainer(std::move(o)) + { + memcpy(&triehead, &o.triehead, sizeof(triehead)); + } + template trie_map &operator=(trie_map &&o) + { + *static_cast(this)=std::move(static_cast(o)); + memcpy(&triehead, &o.triehead, sizeof(triehead)); + return *this; + } +#endif + template trie_map(inputiterator s, inputiterator e) : stlcontainer(s, e) { triehead_reindex(); } + template trie_map(inputiterator s, inputiterator e, const allocator &a) : stlcontainer(s, e, a) { triehead_reindex(); } + }; + template class nobblepolicy, class stlcontainer> bool operator!=(const trie_map &a, const trie_map &b) + { + return static_cast(a)!=static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator<(const trie_map &a, const trie_map &b) + { + return static_cast(a)(b); + } + template class nobblepolicy, class stlcontainer> bool operator<=(const trie_map &a, const trie_map &b) + { + return static_cast(a)<=static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator==(const trie_map &a, const trie_map &b) + { + return static_cast(a)==static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator>(const trie_map &a, const trie_map &b) + { + return static_cast(a)>static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator>=(const trie_map &a, const trie_map &b) + { + return static_cast(a)>=static_cast(b); + } + + /*! \class trie_multimap + \ingroup C++ + \brief A STL container wrapper using nedtries to map keys to values. + + This class can be used to wrap any arbitrary STL container with nedtrie associativity. For example, if you + had a std::vector<> list of items, you could add nedtrie's fast nearly constant time algorithm for accessing them - + though one would expect that a std::list<> would be the most common combination. There is no strict reason why + one could not wrap std::unordered_map<>, though what one would gain is hard to imagine! + + Usage in the simplest sense is like this as the default template parameters use std::list<> as the underlying + container: + \code + trie_multimap fooMap; + fooMap[5]=Foo(); + fooMap.erase(fooMap.find(5)); + \endcode + + Unlike a proper STL container implementation, this wrapper is very much a hack in the sense that it's a very quick + and dirty way of implementing lots of nedtrie based STL containers at once. In this sense it does require its user + to not be stupid, and to know what they're doing. STL containers go out of their way to enforce correctness - well, + this wrapper most certainly does not. If you want to blow off your own foot, this implementation won't stop you! + + For example, despite the protected STL container inheritance, all common STL functions are made public so you + can if you want easily corrupt the internal state. Equally, if you know what you are doing you can pass in the + wrapper as a const version of its underlying STL container by reintrpret_cast<>-ing it. Despite this, the wrapper + is fairly typesafe in that its design won't introduce subtle bugs or cause existing code to magically break itself. + + If you would like a more proper bitwise trie STL container class implemented, or would like to be advised on any + algorithmic problems from which your IT project may be suffering, my consulting company ned Productions Consulting Ltd would be happy to advise. In particular + I would love to see a full bitwise trie implementation submitted to the Boost C++ libraries but I don't have the + unpaid time to devote to such an endeavour sadly. + + \warning If you use std::vector<> as the STL container, make SURE you resize() it to its maximum size before use. + Otherwise the iterators trie_multimap uses to link nedtrie items into the STL items will become invalidated on storage + expansion. + */ + template class nobblepolicy, class stlcontainer> class trie_multimap : protected stlcontainer, protected nobblepolicy > + { + typedef nobblepolicy > nobblepolicytype; + typedef typename stlcontainer::value_type mapvaluetype; + static const size_t trie_fieldoffset=mapvaluetype::trie_link_offset; + template class nobblepolicy_, class stlcontainer_, class iteratortype_, int dir, class mapvaluetype, class constiteratortype> friend class trie_iterator; + public: + typedef typename stlcontainer::allocator_type allocator_type; + typedef trie_iterator const_iterator; + typedef typename stlcontainer::const_pointer const_pointer; + typedef typename stlcontainer::const_reference const_reference; + typedef trie_iterator const_reverse_iterator; + typedef typename stlcontainer::difference_type difference_type; + typedef trie_iterator iterator; + typedef keytype key_type; + typedef type mapped_type; + typedef typename stlcontainer::pointer pointer; + typedef typename stlcontainer::reference reference; + typedef trie_iterator reverse_iterator; + typedef typename stlcontainer::size_type size_type; + typedef typename stlcontainer::value_type::trie_value_type value_type; + private: + trie_map_head triehead; + static typename mapvaluetype::trie_iterator_type &from_iterator(iterator &it) + { + void *_it=(void *) ⁢ + return *(typename mapvaluetype::trie_iterator_type *)_it; + } + // Wipes and resets the nedtrie index + void triehead_reindex() + { + NEDTRIE_INIT(&triehead); + for(iterator it=begin(); it!=end(); ++it) + { + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, &(*it)); + it->trie_iterator=it; + } + } + const mapvaluetype *triehead_find(const key_type &key) const + { // Avoid a value_type construction using pure unmitigated evil + char buffer[sizeof(mapvaluetype)]; + new(buffer) intern::keystore_t(*(size_t *)"TRIEFINDKEYSTORE", key); + return triefind, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct > >(&triehead, (mapvaluetype *) buffer); + } + iterator triehead_insert(const value_type &val) + { + iterator it=iterator((trie_map *) this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#ifdef HAVE_CPP0XRVALUEREFS + iterator triehead_insert(value_type &&val) + { + iterator it=iterator((trie_map *) this, stlcontainer::insert(stlcontainer::end(), std::move(val))); + it->trie_iterator=from_iterator(it); + trieinsert, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct >(&triehead, const_cast(&(*it))); + return it; + } +#endif + public: + iterator begin() { return iterator((trie_map *) this, stlcontainer::begin()); } + const_iterator begin() const { return const_iterator((trie_map *) this, stlcontainer::begin()); } + using stlcontainer::clear; + //! Returns the number of items with the key \em key + size_type count(const key_type &key) const + { + size_type ret=0; + const mapvaluetype *r=triehead_find(key); + if(r) + { + if(r->trie_link.prev) r=r->trie_link.trie_prev; + for(; r; r=r->trie_link.trie_next) ret++; + } + return ret; + } + using stlcontainer::empty; + iterator end() { return iterator((trie_map *) this, stlcontainer::end()); } + const_iterator end() const { return const_iterator((trie_map *) this, stlcontainer::end()); } + //std::pair equal_range(const key_type &key); + //std::pair equal_range(const key_type &key) const; + //! Removes the item specified by \em it from the container + iterator erase(iterator it) + { + //int (*nobblefunct)(trietype *head) + trieremove, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct, + // Need to give MSVC a little bit of help +#ifdef _MSC_VER + nobblepolicytype::trie_nobblefunction > +#else + nobblepolicytype::trie_nobblefunction +#endif + >(&triehead, &(*it)); + return iterator((trie_map *) this, stlcontainer::erase((typename stlcontainer::iterator &) it)); + } + //! Removes the items between \em first and \em last from the container + iterator erase(iterator first, iterator last) + { + iterator ret(last); ++ret; + for(iterator it=first; it!=last; ++it) + { + trieremove, mapvaluetype, trie_fieldoffset, intern::to_Ckeyfunct, +#ifdef _MSC_VER + nobblepolicytype::trie_nobblefunction > +#else + nobblepolicytype::trie_nobblefunction +#endif + >(&triehead, &(*it)); + stlcontainer::erase((typename stlcontainer::iterator &) it); + } + return ret; + } + //! Finds the item with key \em key + iterator find(const key_type &key) { const_iterator it=static_cast(this)->find(key); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the item with key \em key + const_iterator find(const key_type &key) const + { + const mapvaluetype *r=triehead_find(key); + return !r ? end() : const_iterator((trie_map *) this, (const typename stlcontainer::const_iterator &) r->trie_iterator); + } + //! Finds the nearest item with key \em key + iterator nfind(const key_type &key) { const_iterator it=static_cast(this)->nfind(key); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the nearest item with key \em key + const_iterator nfind(const key_type &key) const + { + const mapvaluetype *r=triehead_nfind(key); + return !r ? end() : const_iterator(this, (const typename stlcontainer::const_iterator &) r->trie_iterator); + } + //! Finds the closest item with key \em key trying up to \em rounds times + iterator cfind(const key_type &key, int rounds=INT_MAX) { const_iterator it=static_cast(this)->cfind(key, rounds); void *_it=(void *) ⁢ return *(iterator *)_it; } + //! Finds the closest item with key \em key trying up to \em rounds times + const_iterator cfind(const key_type &key, int rounds=INT_MAX) const + { + const mapvaluetype *r=triehead_cfind(key, rounds); + return !r ? end() : const_iterator(this, (const typename stlcontainer::const_iterator &) r->trie_iterator); + } + using stlcontainer::get_allocator; + //! Inserts the item \em val + iterator insert(const value_type &val) + { + return triehead_insert(std::move(val)); + } + //! Inserts the item \em val at position \em at + iterator insert(iterator at, const value_type &val) + { + iterator it=stlcontainer::insert(at, val); + it->trie_iterator=from_iterator(it); + trieinsert >(&triehead, &(*it)); + return it; + } + //! Inserts the items between \em first and \em last + template void insert(inputiterator first, inputiterator last) + { + iterator it=--end(); + stlcontainer::insert(first, last); + for(; it!=end(); ++it) + { + it->trie_iterator=from_iterator(it); + trieinsert >(&triehead, &(*it)); + } + } + //key_compare key_comp() const; + //iterator lower_bound(const key_type &key); + //const_iterator lower_bound(const key_type &key) const; + using stlcontainer::max_size; + reverse_iterator rbegin() { return reverse_iterator((trie_map *) this, stlcontainer::begin()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator((trie_map *) this, stlcontainer::begin()); } + reverse_iterator rend() { return reverse_iterator((trie_map *) this, stlcontainer::end()); } + const_reverse_iterator rend() const { return const_reverse_iterator((trie_map *) this, stlcontainer::end()); } + using stlcontainer::size; + using stlcontainer::swap; + //iterator upper_bound(const key_type &key); + //const_iterator upper_bound(const key_type &key) const; + //value_compare value_comp() const; + + template class nobblepolicy_, class stlcontainer_> friend bool operator!=(const trie_multimap &a, const trie_multimap &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator<(const trie_multimap &a, const trie_multimap &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator<=(const trie_multimap &a, const trie_multimap &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator==(const trie_multimap &a, const trie_multimap &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator>(const trie_multimap &a, const trie_multimap &b); + template class nobblepolicy_, class stlcontainer_> friend bool operator>=(const trie_multimap &a, const trie_multimap &b); + + //! Constructs a trie_multimap. Has all the typical STL overloads + trie_multimap() : stlcontainer() { NEDTRIE_INIT(&triehead); } + explicit trie_multimap(const allocator &a) : stlcontainer(a) { NEDTRIE_INIT(&triehead); } + template trie_multimap(const trie_multimap &o) : stlcontainer(o) { triehead_reindex(); } + template trie_multimap &operator=(const trie_multimap &o) { *static_cast(this)=static_cast(o); triehead_reindex(); return *this; } +#ifdef HAVE_CPP0XRVALUEREFS + template trie_multimap(trie_multimap &&o) : stlcontainer(std::move(o)) + { + memcpy(&triehead, &o.triehead, sizeof(triehead)); + } + template trie_multimap &operator=(trie_multimap &&o) + { + *static_cast(this)=std::move(static_cast(o)); + memcpy(&triehead, &o.triehead, sizeof(triehead)); + return *this; + } +#endif + template trie_multimap(inputiterator s, inputiterator e) : stlcontainer(s, e) { triehead_reindex(); } + template trie_multimap(inputiterator s, inputiterator e, const allocator &a) : stlcontainer(s, e, a) { triehead_reindex(); } + }; + template class nobblepolicy, class stlcontainer> bool operator!=(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)!=static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator<(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)(b); + } + template class nobblepolicy, class stlcontainer> bool operator<=(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)<=static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator==(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)==static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator>(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)>static_cast(b); + } + template class nobblepolicy, class stlcontainer> bool operator>=(const trie_multimap &a, const trie_multimap &b) + { + return static_cast(a)>=static_cast(b); + } + +} /* namespace */ + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif