diff options
Diffstat (limited to 'common')
38 files changed, 3511 insertions, 1168 deletions
diff --git a/common/Makefile.am b/common/Makefile.am index b583a5c..b3e4eaf 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -12,10 +12,11 @@ inc_HEADERS = \ noinst_LTLIBRARIES = \ libp11-common.la \ libp11-library.la \ - libp11-mock.la \ + libp11-test.la \ $(NULL) libp11_common_la_SOURCES = \ + argv.c argv.h \ attrs.c attrs.h \ array.c array.h \ buffer.c buffer.h \ @@ -35,8 +36,9 @@ libp11_library_la_SOURCES = \ library.c library.h \ $(NULL) -libp11_mock_la_SOURCES = \ +libp11_test_la_SOURCES = \ mock.c mock.h \ + test.c test.h \ $(NULL) if WITH_ASN1 diff --git a/common/argv.c b/common/argv.c new file mode 100644 index 0000000..6d91bfa --- /dev/null +++ b/common/argv.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2012 Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter <stefw@redhat.com> + */ + +#include "config.h" + +#include "argv.h" +#include "debug.h" + +#include <ctype.h> +#include <stdlib.h> +#include <string.h> + +bool +p11_argv_parse (const char *string, + void (*sink) (char *, void *), + void *argument) +{ + char quote = '\0'; + char *src, *dup, *at, *arg; + bool ret = true; + + return_val_if_fail (string != NULL, false); + return_val_if_fail (sink != NULL, false); + + src = dup = strdup (string); + return_val_if_fail (dup != NULL, false); + + arg = at = src; + for (src = dup; *src; src++) { + + /* Matching quote */ + if (quote == *src) { + quote = '\0'; + + /* Inside of quotes */ + } else if (quote != '\0') { + if (*src == '\\') { + *at++ = *src++; + if (!*src) { + ret = false; + goto done; + } + if (*src != quote) + *at++ = '\\'; + } + *at++ = *src; + + /* Space, not inside of quotes */ + } else if (isspace (*src)) { + *at = 0; + sink (arg, argument); + arg = at; + + /* Other character outside of quotes */ + } else { + switch (*src) { + case '\'': + case '"': + quote = *src; + break; + case '\\': + *at++ = *src++; + if (!*src) { + ret = false; + goto done; + } + /* fall through */ + default: + *at++ = *src; + break; + } + } + } + + + if (at != arg) { + *at = 0; + sink (arg, argument); + } + +done: + free (dup); + return ret; +} diff --git a/common/argv.h b/common/argv.h new file mode 100644 index 0000000..8f95490 --- /dev/null +++ b/common/argv.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2012 Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter <stefw@redhat.com> + */ + +#ifndef P11_ARGV_H_ +#define P11_ARGV_H_ + +#include "compat.h" + +bool p11_argv_parse (const char *string, + void (*sink) (char *, void *), + void *argument); + +#endif /* P11_ARGV_H_ */ diff --git a/common/attrs.c b/common/attrs.c index c1e060a..88906f4 100644 --- a/common/attrs.c +++ b/common/attrs.c @@ -808,10 +808,10 @@ format_some_bytes (p11_buffer *buffer, p11_buffer_add (buffer, "\"", 1); } -static void -format_attribute (p11_buffer *buffer, - const CK_ATTRIBUTE *attr, - CK_OBJECT_CLASS klass) +void +p11_attr_format (p11_buffer *buffer, + const CK_ATTRIBUTE *attr, + CK_OBJECT_CLASS klass) { p11_buffer_add (buffer, "{ ", -1); format_attribute_type (buffer, attr->type); @@ -839,10 +839,10 @@ format_attribute (p11_buffer *buffer, p11_buffer_add (buffer, " }", -1); } -static void -format_attributes (p11_buffer *buffer, - const CK_ATTRIBUTE *attrs, - int count) +void +p11_attrs_format (p11_buffer *buffer, + const CK_ATTRIBUTE *attrs, + int count) { CK_BBOOL first = CK_TRUE; CK_OBJECT_CLASS klass; @@ -861,7 +861,7 @@ format_attributes (p11_buffer *buffer, else p11_buffer_add (buffer, ", ", 2); first = CK_FALSE; - format_attribute (buffer, attrs + i, klass); + p11_attr_format (buffer, attrs + i, klass); } p11_buffer_add (buffer, " ]", -1); } @@ -873,7 +873,7 @@ p11_attrs_to_string (const CK_ATTRIBUTE *attrs, p11_buffer buffer; if (!p11_buffer_init_null (&buffer, 128)) return_val_if_reached (NULL); - format_attributes (&buffer, attrs, count); + p11_attrs_format (&buffer, attrs, count); return p11_buffer_steal (&buffer, NULL); } @@ -884,6 +884,6 @@ p11_attr_to_string (const CK_ATTRIBUTE *attr, p11_buffer buffer; if (!p11_buffer_init_null (&buffer, 32)) return_val_if_reached (NULL); - format_attribute (&buffer, attr, klass); + p11_attr_format (&buffer, attr, klass); return p11_buffer_steal (&buffer, NULL); } diff --git a/common/attrs.h b/common/attrs.h index 233ac79..2780013 100644 --- a/common/attrs.h +++ b/common/attrs.h @@ -36,6 +36,7 @@ #ifndef P11_ATTRS_H_ #define P11_ATTRS_H_ +#include "buffer.h" #include "compat.h" #include "pkcs11.h" @@ -112,9 +113,17 @@ bool p11_attrs_matchn (const CK_ATTRIBUTE *attrs, char * p11_attrs_to_string (const CK_ATTRIBUTE *attrs, int count); +void p11_attrs_format (p11_buffer *buffer, + const CK_ATTRIBUTE *attrs, + int count); + char * p11_attr_to_string (const CK_ATTRIBUTE *attr, CK_OBJECT_CLASS klass); +void p11_attr_format (p11_buffer *buffer, + const CK_ATTRIBUTE *attr, + CK_OBJECT_CLASS klass); + bool p11_attr_equal (const void *one, const void *two); diff --git a/common/compat.c b/common/compat.c index 4d8d73c..400e10b 100644 --- a/common/compat.c +++ b/common/compat.c @@ -161,7 +161,7 @@ p11_mutex_init (p11_mutex_t *mutex) int ret; pthread_mutexattr_init (&attr); - pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_DEFAULT); ret = pthread_mutex_init (mutex, &attr); assert (ret == 0); pthread_mutexattr_destroy (&attr); @@ -245,6 +245,12 @@ p11_dl_error (void) return msg_buf; } +void +p11_dl_close (void *dl) +{ + FreeLibrary (dl); +} + int p11_thread_create (p11_thread_t *thread, p11_thread_routine routine, diff --git a/common/compat.h b/common/compat.h index 7435e07..9127f95 100644 --- a/common/compat.h +++ b/common/compat.h @@ -103,6 +103,8 @@ char * strdup_path_mangle (const char *template); #define WIN32_LEAN_AND_MEAN 1 #include <windows.h> +#include <io.h> + /* Oh ... my ... god */ #undef CreateMutex @@ -135,13 +137,13 @@ typedef HMODULE dl_module_t; #define p11_dl_open(f) \ (LoadLibrary (f)) -#define p11_dl_close(d) \ - (FreeLibrary (d)) #define p11_dl_symbol(d, s) \ ((void *)GetProcAddress ((d), (s))) char * p11_dl_error (void); +void p11_dl_close (void * dl); + #define p11_sleep_ms(ms) \ (Sleep (ms)) @@ -164,6 +166,7 @@ void p11_mmap_close (p11_mmap *map); #include <pthread.h> #include <dlfcn.h> #include <time.h> +#include <unistd.h> typedef pthread_mutex_t p11_mutex_t; diff --git a/common/constants.c b/common/constants.c index 918d3e5..3ff93bd 100644 --- a/common/constants.c +++ b/common/constants.c @@ -104,7 +104,7 @@ const p11_constant p11_constant_types[] = { /* CT (CKA_SUBPRIME_BITS) */ CT (CKA_SUB_PRIME_BITS, "subprime-bits") CT (CKA_VALUE_BITS, "value-bits") - CT (CKA_VALUE_LEN, "vaule-len") + CT (CKA_VALUE_LEN, "value-len") CT (CKA_EXTRACTABLE, "extractable") CT (CKA_LOCAL, "local") CT (CKA_NEVER_EXTRACTABLE, "never-extractable") @@ -260,6 +260,338 @@ const p11_constant p11_constant_categories[] = { { CKA_INVALID }, }; +const p11_constant p11_constant_users[] = { + CT (CKU_SO, NULL) + CT (CKU_USER, NULL) + CT (CKU_CONTEXT_SPECIFIC, NULL) + { CKA_INVALID }, +}; + +const p11_constant p11_constant_states[] = { + CT (CKS_RO_PUBLIC_SESSION, NULL) + CT (CKS_RO_USER_FUNCTIONS, NULL) + CT (CKS_RW_PUBLIC_SESSION, NULL) + CT (CKS_RW_USER_FUNCTIONS, NULL) + CT (CKS_RW_SO_FUNCTIONS, NULL) + { CKA_INVALID }, +}; + +const p11_constant p11_constant_returns[] = { + CT (CKR_OK, NULL) + CT (CKR_CANCEL, NULL) + CT (CKR_HOST_MEMORY, NULL) + CT (CKR_SLOT_ID_INVALID, NULL) + CT (CKR_GENERAL_ERROR, NULL) + CT (CKR_FUNCTION_FAILED, NULL) + CT (CKR_ARGUMENTS_BAD, NULL) + CT (CKR_NO_EVENT, NULL) + CT (CKR_NEED_TO_CREATE_THREADS, NULL) + CT (CKR_CANT_LOCK, NULL) + CT (CKR_ATTRIBUTE_READ_ONLY, NULL) + CT (CKR_ATTRIBUTE_SENSITIVE, NULL) + CT (CKR_ATTRIBUTE_TYPE_INVALID, NULL) + CT (CKR_ATTRIBUTE_VALUE_INVALID, NULL) + CT (CKR_DATA_INVALID, NULL) + CT (CKR_DATA_LEN_RANGE, NULL) + CT (CKR_DEVICE_ERROR, NULL) + CT (CKR_DEVICE_MEMORY, NULL) + CT (CKR_DEVICE_REMOVED, NULL) + CT (CKR_ENCRYPTED_DATA_INVALID, NULL) + CT (CKR_ENCRYPTED_DATA_LEN_RANGE, NULL) + CT (CKR_FUNCTION_CANCELED, NULL) + CT (CKR_FUNCTION_NOT_PARALLEL, NULL) + CT (CKR_FUNCTION_NOT_SUPPORTED, NULL) + CT (CKR_KEY_HANDLE_INVALID, NULL) + CT (CKR_KEY_SIZE_RANGE, NULL) + CT (CKR_KEY_TYPE_INCONSISTENT, NULL) + CT (CKR_KEY_NOT_NEEDED, NULL) + CT (CKR_KEY_CHANGED, NULL) + CT (CKR_KEY_NEEDED, NULL) + CT (CKR_KEY_INDIGESTIBLE, NULL) + CT (CKR_KEY_FUNCTION_NOT_PERMITTED, NULL) + CT (CKR_KEY_NOT_WRAPPABLE, NULL) + CT (CKR_KEY_UNEXTRACTABLE, NULL) + CT (CKR_MECHANISM_INVALID, NULL) + CT (CKR_MECHANISM_PARAM_INVALID, NULL) + CT (CKR_OBJECT_HANDLE_INVALID, NULL) + CT (CKR_OPERATION_ACTIVE, NULL) + CT (CKR_OPERATION_NOT_INITIALIZED, NULL) + CT (CKR_PIN_INCORRECT, NULL) + CT (CKR_PIN_INVALID, NULL) + CT (CKR_PIN_LEN_RANGE, NULL) + CT (CKR_PIN_EXPIRED, NULL) + CT (CKR_PIN_LOCKED, NULL) + CT (CKR_SESSION_CLOSED, NULL) + CT (CKR_SESSION_COUNT, NULL) + CT (CKR_SESSION_HANDLE_INVALID, NULL) + CT (CKR_SESSION_PARALLEL_NOT_SUPPORTED, NULL) + CT (CKR_SESSION_READ_ONLY, NULL) + CT (CKR_SESSION_EXISTS, NULL) + CT (CKR_SESSION_READ_ONLY_EXISTS, NULL) + CT (CKR_SESSION_READ_WRITE_SO_EXISTS, NULL) + CT (CKR_SIGNATURE_INVALID, NULL) + CT (CKR_SIGNATURE_LEN_RANGE, NULL) + CT (CKR_TEMPLATE_INCOMPLETE, NULL) + CT (CKR_TEMPLATE_INCONSISTENT, NULL) + CT (CKR_TOKEN_NOT_PRESENT, NULL) + CT (CKR_TOKEN_NOT_RECOGNIZED, NULL) + CT (CKR_TOKEN_WRITE_PROTECTED, NULL) + CT (CKR_UNWRAPPING_KEY_HANDLE_INVALID, NULL) + CT (CKR_UNWRAPPING_KEY_SIZE_RANGE, NULL) + CT (CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT, NULL) + CT (CKR_USER_ALREADY_LOGGED_IN, NULL) + CT (CKR_USER_NOT_LOGGED_IN, NULL) + CT (CKR_USER_PIN_NOT_INITIALIZED, NULL) + CT (CKR_USER_TYPE_INVALID, NULL) + CT (CKR_USER_ANOTHER_ALREADY_LOGGED_IN, NULL) + CT (CKR_USER_TOO_MANY_TYPES, NULL) + CT (CKR_WRAPPED_KEY_INVALID, NULL) + CT (CKR_WRAPPED_KEY_LEN_RANGE, NULL) + CT (CKR_WRAPPING_KEY_HANDLE_INVALID, NULL) + CT (CKR_WRAPPING_KEY_SIZE_RANGE, NULL) + CT (CKR_WRAPPING_KEY_TYPE_INCONSISTENT, NULL) + CT (CKR_RANDOM_SEED_NOT_SUPPORTED, NULL) + CT (CKR_RANDOM_NO_RNG, NULL) + CT (CKR_DOMAIN_PARAMS_INVALID, NULL) + CT (CKR_BUFFER_TOO_SMALL, NULL) + CT (CKR_SAVED_STATE_INVALID, NULL) + CT (CKR_INFORMATION_SENSITIVE, NULL) + CT (CKR_STATE_UNSAVEABLE, NULL) + CT (CKR_CRYPTOKI_NOT_INITIALIZED, NULL) + CT (CKR_CRYPTOKI_ALREADY_INITIALIZED, NULL) + CT (CKR_MUTEX_BAD, NULL) + CT (CKR_MUTEX_NOT_LOCKED, NULL) + CT (CKR_FUNCTION_REJECTED, NULL) + { CKA_INVALID }, +}; + +const p11_constant p11_constant_mechanisms[] = { + CT (CKM_RSA_PKCS_KEY_PAIR_GEN, "rsa-pkcs-key-pair-gen") + CT (CKM_RSA_PKCS, "rsa-pkcs") + CT (CKM_RSA_9796, "rsa-9796") + CT (CKM_RSA_X_509, "rsa-x-509") + CT (CKM_MD2_RSA_PKCS, "md2-rsa-pkcs") + CT (CKM_MD5_RSA_PKCS, "md5-rsa-pkcs") + CT (CKM_SHA1_RSA_PKCS, "sha1-rsa-pkcs") + CT (CKM_RIPEMD128_RSA_PKCS, "ripemd128-rsa-pkcs") + CT (CKM_RIPEMD160_RSA_PKCS, "ripemd160-rsa-pkcs") + CT (CKM_RSA_PKCS_OAEP, "rsa-pkcs-oaep") + CT (CKM_RSA_X9_31_KEY_PAIR_GEN, "rsa-x9-31-key-pair-gen") + CT (CKM_RSA_X9_31, "rsa-x9-31") + CT (CKM_SHA1_RSA_X9_31, "sha1-rsa-x9-31") + CT (CKM_RSA_PKCS_PSS, "rsa-pkcs-pss") + CT (CKM_SHA1_RSA_PKCS_PSS, "sha1-rsa-pkcs-pss") + CT (CKM_DSA_KEY_PAIR_GEN, "dsa-key-pair-gen") + CT (CKM_DSA, NULL) /* "dsa" */ + CT (CKM_DSA_SHA1, "dsa-sha1") + CT (CKM_DH_PKCS_KEY_PAIR_GEN, "dh-pkcs-key-pair-gen") + CT (CKM_DH_PKCS_DERIVE, "dh-pkcs-derive") + CT (CKM_X9_42_DH_KEY_PAIR_GEN, "x9-42-dh-key-pair-gen") + CT (CKM_X9_42_DH_DERIVE, "x9-42-dh-derive") + CT (CKM_X9_42_DH_HYBRID_DERIVE, "x9-42-dh-hybrid-derive") + CT (CKM_X9_42_MQV_DERIVE, "x9-42-mqv-derive") + CT (CKM_SHA256_RSA_PKCS, "sha256-rsa-pkcs") + CT (CKM_SHA384_RSA_PKCS, "sha384-rsa-pkcs") + CT (CKM_SHA512_RSA_PKCS, "sha512-rsa-pkcs") + CT (CKM_SHA256_RSA_PKCS_PSS, "sha256-rsa-pkcs-pss") + CT (CKM_SHA384_RSA_PKCS_PSS, "sha384-rsa-pkcs-pss") + CT (CKM_SHA512_RSA_PKCS_PSS, "sha512-rsa-pkcs-pss") + CT (CKM_RC2_KEY_GEN, "rc2-key-gen") + CT (CKM_RC2_ECB, "rc2-ecb") + CT (CKM_RC2_CBC, "rc2-cbc") + CT (CKM_RC2_MAC, "rc2-mac") + CT (CKM_RC2_MAC_GENERAL, "rc2-mac-general") + CT (CKM_RC2_CBC_PAD, "rc2-cbc-pad") + CT (CKM_RC4_KEY_GEN, "rc4-key-gen") + CT (CKM_RC4, NULL) /* "rc4" */ + CT (CKM_DES_KEY_GEN, "des-key-gen") + CT (CKM_DES_ECB, "des-ecb") + CT (CKM_DES_CBC, "des-cbc") + CT (CKM_DES_MAC, "des-mac") + CT (CKM_DES_MAC_GENERAL, "des-mac-general") + CT (CKM_DES_CBC_PAD, "des-cbc-pad") + CT (CKM_DES2_KEY_GEN, "des2-key-gen") + CT (CKM_DES3_KEY_GEN, "des3-key-gen") + CT (CKM_DES3_ECB, "des3-ecb") + CT (CKM_DES3_CBC, "des3-cbc") + CT (CKM_DES3_MAC, "des3-mac") + CT (CKM_DES3_MAC_GENERAL, "des3-mac-general") + CT (CKM_DES3_CBC_PAD, "des3-cbc-pad") + CT (CKM_CDMF_KEY_GEN, "cdmf-key-gen") + CT (CKM_CDMF_ECB, "cdmf-ecb") + CT (CKM_CDMF_CBC, "cdmf-cbc") + CT (CKM_CDMF_MAC, "cdmf-mac") + CT (CKM_CDMF_MAC_GENERAL, "cdmf-mac-general") + CT (CKM_CDMF_CBC_PAD, "cdmf-cbc-pad") + CT (CKM_DES_OFB64, "des-ofb64") + CT (CKM_DES_OFB8, "des-ofb8") + CT (CKM_DES_CFB64, "des-cfb64") + CT (CKM_DES_CFB8, "des-cfb8") + CT (CKM_MD2, "md2") + CT (CKM_MD2_HMAC, "md2-hmac") + CT (CKM_MD2_HMAC_GENERAL, "md2-hmac-general") + CT (CKM_MD5, "md5") + CT (CKM_MD5_HMAC, "md5-hmac") + CT (CKM_MD5_HMAC_GENERAL, "md5-hmac-general") + CT (CKM_SHA_1, "sha-1") + CT (CKM_SHA_1_HMAC, "sha-1-hmac") + CT (CKM_SHA_1_HMAC_GENERAL, "sha-1-hmac-general") + CT (CKM_RIPEMD128, "ripemd128") + CT (CKM_RIPEMD128_HMAC, "ripemd128-hmac") + CT (CKM_RIPEMD128_HMAC_GENERAL, "ripemd128-hmac-general") + CT (CKM_RIPEMD160, "ripemd160") + CT (CKM_RIPEMD160_HMAC, "ripemd160-hmac") + CT (CKM_RIPEMD160_HMAC_GENERAL, "ripemd160-hmac-general") + CT (CKM_SHA256, "sha256") + CT (CKM_SHA256_HMAC, "sha256-hmac") + CT (CKM_SHA256_HMAC_GENERAL, "sha256-hmac-general") + CT (CKM_SHA384, "sha384") + CT (CKM_SHA384_HMAC, "sha384-hmac") + CT (CKM_SHA384_HMAC_GENERAL, "sha384-hmac-general") + CT (CKM_SHA512, "sha512") + CT (CKM_SHA512_HMAC, "sha512-hmac") + CT (CKM_SHA512_HMAC_GENERAL, "sha512-hmac-general") + CT (CKM_CAST_KEY_GEN, "cast-key-gen") + CT (CKM_CAST_ECB, "cast-ecb") + CT (CKM_CAST_CBC, "cast-cbc") + CT (CKM_CAST_MAC, "cast-mac") + CT (CKM_CAST_MAC_GENERAL, "cast-mac-general") + CT (CKM_CAST_CBC_PAD, "cast-cbc-pad") + CT (CKM_CAST3_KEY_GEN, "cast3-key-gen") + CT (CKM_CAST3_ECB, "cast3-ecb") + CT (CKM_CAST3_CBC, "cast3-cbc") + CT (CKM_CAST3_MAC, "cast3-mac") + CT (CKM_CAST3_MAC_GENERAL, "cast3-mac-general") + CT (CKM_CAST3_CBC_PAD, "cast3-cbc-pad") + CT (CKM_CAST5_KEY_GEN, "cast5-key-gen") + /* CT (CKM_CAST128_KEY_GEN) */ + CT (CKM_CAST5_ECB, "cast5-ecb") + /* CT (CKM_CAST128_ECB) */ + CT (CKM_CAST5_CBC, "cast5-cbc") + /* CT (CKM_CAST128_CBC) */ + CT (CKM_CAST5_MAC, "cast5-mac") + /* CT (CKM_CAST128_MAC) */ + CT (CKM_CAST5_MAC_GENERAL, "cast5-mac-general") + /* CT (CKM_CAST128_MAC_GENERAL) */ + CT (CKM_CAST5_CBC_PAD, "cast5-cbc-pad") + /* CT (CKM_CAST128_CBC_PAD) */ + CT (CKM_RC5_KEY_GEN, "rc5-key-gen") + CT (CKM_RC5_ECB, "rc5-ecb") + CT (CKM_RC5_CBC, "rc5-cbc") + CT (CKM_RC5_MAC, "rc5-mac") + CT (CKM_RC5_MAC_GENERAL, "rc5-mac-general") + CT (CKM_RC5_CBC_PAD, "rc5-cbc-pad") + CT (CKM_IDEA_KEY_GEN, "idea-key-gen") + CT (CKM_IDEA_ECB, "idea-ecb") + CT (CKM_IDEA_CBC, "idea-cbc") + CT (CKM_IDEA_MAC, "idea-mac") + CT (CKM_IDEA_MAC_GENERAL, "idea-mac-general") + CT (CKM_IDEA_CBC_PAD, "idea-cbc-pad") + CT (CKM_GENERIC_SECRET_KEY_GEN, "generic-secret-key-gen") + CT (CKM_CONCATENATE_BASE_AND_KEY, "concatenate-base-and-key") + CT (CKM_CONCATENATE_BASE_AND_DATA, "concatenate-base-and-data") + CT (CKM_CONCATENATE_DATA_AND_BASE, "concatenate-data-and-base") + CT (CKM_XOR_BASE_AND_DATA, "xor-base-and-data") + CT (CKM_EXTRACT_KEY_FROM_KEY, "extract-key-from-key") + CT (CKM_SSL3_PRE_MASTER_KEY_GEN, "ssl3-pre-master-key-gen") + CT (CKM_SSL3_MASTER_KEY_DERIVE, "ssl3-master-key-derive") + CT (CKM_SSL3_KEY_AND_MAC_DERIVE, "ssl3-key-and-mac-derive") + CT (CKM_SSL3_MASTER_KEY_DERIVE_DH, "ssl3-master-key-derive-dh") + CT (CKM_TLS_PRE_MASTER_KEY_GEN, "tls-pre-master-key-gen") + CT (CKM_TLS_MASTER_KEY_DERIVE, "tls-master-key-derive") + CT (CKM_TLS_KEY_AND_MAC_DERIVE, "tls-key-and-mac-derive") + CT (CKM_TLS_MASTER_KEY_DERIVE_DH, "tls-master-key-derive-dh") + /* CT (CKM_TLS_PRF) */ + CT (CKM_SSL3_MD5_MAC, "ssl3-md5-mac") + CT (CKM_SSL3_SHA1_MAC, "ssl3-sha1-mac") + CT (CKM_MD5_KEY_DERIVATION, "md5-key-derivation") + CT (CKM_MD2_KEY_DERIVATION, "md2-key-derivation") + CT (CKM_SHA1_KEY_DERIVATION, "sha1-key-derivation") + CT (CKM_SHA256_KEY_DERIVATION, "sha256-key-derivation") + CT (CKM_SHA384_KEY_DERIVATION, "sha384-key-derivation") + CT (CKM_SHA512_KEY_DERIVATION, "sha512-key-derivation") + CT (CKM_PBE_MD2_DES_CBC, "pbe-md2-des-cbc") + CT (CKM_PBE_MD5_DES_CBC, "pbe-md5-des-cbc") + CT (CKM_PBE_MD5_CAST_CBC, "pbe-md5-cast-cbc") + CT (CKM_PBE_MD5_CAST3_CBC, "pbe-md5-cast3-cbc") + CT (CKM_PBE_MD5_CAST5_CBC, "pbe-md5-cast5-cbc") + /* CT (CKM_PBE_MD5_CAST128_CBC) */ + CT (CKM_PBE_SHA1_CAST5_CBC, "pbe-sha1-cast5-cbc") + /* CT (CKM_PBE_SHA1_CAST128_CBC) */ + CT (CKM_PBE_SHA1_RC4_128, "pbe-sha1-rc4-128") + CT (CKM_PBE_SHA1_RC4_40, "pbe-sha1-rc4-40") + CT (CKM_PBE_SHA1_DES3_EDE_CBC, "pbe-sha1-des3-ede-cbc") + CT (CKM_PBE_SHA1_DES2_EDE_CBC, "pbe-sha1-des2-ede-cbc") + CT (CKM_PBE_SHA1_RC2_128_CBC, "pbe-sha1-rc2-128-cbc") + CT (CKM_PBE_SHA1_RC2_40_CBC, "pbe-sha1-rc2-40-cbc") + CT (CKM_PKCS5_PBKD2, "pkcs5-pbkd2") + CT (CKM_PBA_SHA1_WITH_SHA1_HMAC, "pba-sha1-with-sha1-hmac") + CT (CKM_WTLS_PRE_MASTER_KEY_GEN, "wtls-pre-master-key-gen") + CT (CKM_WTLS_MASTER_KEY_DERIVE, "wtls-master-key-derive") + CT (CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC, "wtls-master-key-derive-dh-ecc") + CT (CKM_WTLS_PRF, "wtls-prf") + CT (CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE, "wtls-server-key-and-mac-derive") + CT (CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE, "wtls-client-key-and-mac-derive") + CT (CKM_KEY_WRAP_LYNKS, "key-wrap-lynks") + CT (CKM_KEY_WRAP_SET_OAEP, "key-wrap-set-oaep") + CT (CKM_CMS_SIG, "cms-sig") + CT (CKM_SKIPJACK_KEY_GEN, "skipjack-key-gen") + CT (CKM_SKIPJACK_ECB64, "skipjack-ecb64") + CT (CKM_SKIPJACK_CBC64, "skipjack-cbc64") + CT (CKM_SKIPJACK_OFB64, "skipjack-ofb64") + CT (CKM_SKIPJACK_CFB64, "skipjack-cfb64") + CT (CKM_SKIPJACK_CFB32, "skipjack-cfb32") + CT (CKM_SKIPJACK_CFB16, "skipjack-cfb16") + CT (CKM_SKIPJACK_CFB8, "skipjack-cfb8") + CT (CKM_SKIPJACK_WRAP, "skipjack-wrap") + CT (CKM_SKIPJACK_PRIVATE_WRAP, "skipjack-private-wrap") + CT (CKM_SKIPJACK_RELAYX, "skipjack-relayx") + CT (CKM_KEA_KEY_PAIR_GEN, "kea-key-pair-gen") + CT (CKM_KEA_KEY_DERIVE, "kea-key-derive") + CT (CKM_FORTEZZA_TIMESTAMP, "fortezza-timestamp") + CT (CKM_BATON_KEY_GEN, "baton-key-gen") + CT (CKM_BATON_ECB128, "baton-ecb128") + CT (CKM_BATON_ECB96, "baton-ecb96") + CT (CKM_BATON_CBC128, "baton-cbc128") + CT (CKM_BATON_COUNTER, "baton-counter") + CT (CKM_BATON_SHUFFLE, "baton-shuffle") + CT (CKM_BATON_WRAP, "baton-wrap") + CT (CKM_ECDSA_KEY_PAIR_GEN, "ecdsa-key-pair-gen") + /* CT (CKM_EC_KEY_PAIR_GEN) */ + CT (CKM_ECDSA, "ecdsa") + CT (CKM_ECDSA_SHA1, "ecdsa-sha1") + CT (CKM_ECDH1_DERIVE, "ecdh1-derive") + CT (CKM_ECDH1_COFACTOR_DERIVE, "ecdh1-cofactor-derive") + CT (CKM_ECMQV_DERIVE, "ecmqv-derive") + CT (CKM_JUNIPER_KEY_GEN, "juniper-key-gen") + CT (CKM_JUNIPER_ECB128, "juniper-ecb128") + CT (CKM_JUNIPER_CBC128, "juniper-cbc128") + CT (CKM_JUNIPER_COUNTER, "juniper-counter") + CT (CKM_JUNIPER_SHUFFLE, "juniper-shuffle") + CT (CKM_JUNIPER_WRAP, "juniper-wrap") + CT (CKM_FASTHASH, "fasthash") + CT (CKM_AES_KEY_GEN, "aes-key-gen") + CT (CKM_AES_ECB, "aes-ecb") + CT (CKM_AES_CBC, "aes-cbc") + CT (CKM_AES_MAC, "aes-mac") + CT (CKM_AES_MAC_GENERAL, "aes-mac-general") + CT (CKM_AES_CBC_PAD, "aes-cbc-pad") + CT (CKM_BLOWFISH_KEY_GEN, "blowfish-key-gen") + CT (CKM_BLOWFISH_CBC, "blowfish-cbc") + CT (CKM_TWOFISH_KEY_GEN, "twofish-key-gen") + CT (CKM_TWOFISH_CBC, "twofish-cbc") + CT (CKM_DES_ECB_ENCRYPT_DATA, "des-ecb-encrypt-data") + CT (CKM_DES_CBC_ENCRYPT_DATA, "des-cbc-encrypt-data") + CT (CKM_DES3_ECB_ENCRYPT_DATA, "des3-ecb-encrypt-data") + CT (CKM_DES3_CBC_ENCRYPT_DATA, "des3-cbc-encrypt-data") + CT (CKM_AES_ECB_ENCRYPT_DATA, "aes-ecb-encrypt-data") + CT (CKM_AES_CBC_ENCRYPT_DATA, "aes-cbc-encrypt-data") + CT (CKM_DSA_PARAMETER_GEN, "dsa-parameter-gen") + CT (CKM_DH_PKCS_PARAMETER_GEN, "dh-pkcs-parameter-gen") + CT (CKM_X9_42_DH_PARAMETER_GEN, "x9-42-dh-parameter-gen") + { CKA_INVALID }, +}; + #undef CT struct { @@ -272,7 +604,11 @@ struct { { p11_constant_certs, ELEMS (p11_constant_certs) - 1 }, { p11_constant_keys, ELEMS (p11_constant_keys) - 1 }, { p11_constant_asserts, ELEMS (p11_constant_asserts) - 1 }, - { p11_constant_categories, ELEMS (p11_constant_categories) - 1 } + { p11_constant_categories, ELEMS (p11_constant_categories) - 1 }, + { p11_constant_mechanisms, ELEMS (p11_constant_mechanisms) - 1 }, + { p11_constant_states, ELEMS (p11_constant_states) - 1 }, + { p11_constant_users, ELEMS (p11_constant_users) - 1 }, + { p11_constant_returns, ELEMS (p11_constant_returns) - 1 }, }; static int @@ -328,6 +664,7 @@ p11_constant_reverse (bool nick) { const p11_constant *table; p11_dict *lookups; + void *string; int length = -1; int i, j; @@ -339,9 +676,14 @@ p11_constant_reverse (bool nick) length = tables[i].length; for (j = 0; j < length; j++) { - if (!p11_dict_set (lookups, - nick ? (void *)table[j].nick : (void *)table[j].name, - (void *)&table[j].value)) + if (nick) { + if (!table[j].nick) + continue; + string = (void *)table[j].nick; + } else { + string = (void *)table[j].name; + } + if (!p11_dict_set (lookups, string, (void *)&table[j].value)) return_val_if_reached (NULL); } } diff --git a/common/constants.h b/common/constants.h index 82a0879..5b0f3a5 100644 --- a/common/constants.h +++ b/common/constants.h @@ -71,4 +71,12 @@ extern const p11_constant p11_constant_asserts[]; extern const p11_constant p11_constant_categories[]; +extern const p11_constant p11_constant_mechanisms[]; + +extern const p11_constant p11_constant_states[]; + +extern const p11_constant p11_constant_users[]; + +extern const p11_constant p11_constant_returns[]; + #endif /* P11_CONSTANTS_H_ */ diff --git a/common/debug.h b/common/debug.h index f8b2cf4..0dcfeae 100644 --- a/common/debug.h +++ b/common/debug.h @@ -59,8 +59,10 @@ void p11_debug_precond (const char *format, ...) GNUC_PRINTF (1, 2) CLANG_ANALYZER_NORETURN; +#ifndef assert_not_reached #define assert_not_reached() \ (assert (false && "this code should not be reached")) +#endif #define return_val_if_fail(x, v) \ do { if (!(x)) { \ diff --git a/common/mock.c b/common/mock.c index 1a283b9..f1d1c03 100644 --- a/common/mock.c +++ b/common/mock.c @@ -183,8 +183,8 @@ mock_module_take_object (CK_SLOT_ID slot_id, return_if_reached (); } -void -mock_module_reset_objects (CK_SLOT_ID slot_id) +static void +module_reset_objects (CK_SLOT_ID slot_id) { return_if_fail (slot_id == MOCK_SLOT_ONE_ID); @@ -291,6 +291,44 @@ mock_module_reset_objects (CK_SLOT_ID slot_id) p11_dict_set (the_objects, handle_to_pointer (MOCK_PUBLIC_KEY_PREFIX), p11_attrs_dup (attrs)); } +} + +static void +module_finalize (void) +{ + p11_mutex_lock (&init_mutex); + + /* This should stop all other calls in */ + pkcs11_initialized = false; + pkcs11_initialized_pid = 0; + + if (the_objects) + p11_dict_free (the_objects); + the_objects = NULL; + + if (the_sessions) + p11_dict_free (the_sessions); + the_sessions = NULL; + logged_in = false; + the_user_type = 0; + + free (the_pin); + the_pin = NULL; + n_the_pin = 0; + + p11_mutex_unlock (&init_mutex); +} + +bool +mock_module_initialized (void) +{ + return pkcs11_initialized; +} +void +mock_module_reset (void) +{ + module_finalize (); + module_reset_objects (MOCK_SLOT_ONE_ID); } @@ -389,7 +427,7 @@ mock_C_Initialize (CK_VOID_PTR init_args) p11_dict_direct_equal, NULL, free_session); - mock_module_reset_objects (MOCK_SLOT_ONE_ID); + module_reset_objects (MOCK_SLOT_ONE_ID); done: /* Mark us as officially initialized */ @@ -407,6 +445,13 @@ done: } CK_RV +mock_X_Initialize (CK_X_FUNCTION_LIST *self, + CK_VOID_PTR init_args) +{ + return mock_C_Initialize (init_args); +} + +CK_RV mock_C_Initialize__fails (CK_VOID_PTR init_args) { return CKR_FUNCTION_FAILED; @@ -418,35 +463,16 @@ mock_C_Finalize (CK_VOID_PTR reserved) return_val_if_fail (pkcs11_initialized, CKR_CRYPTOKI_NOT_INITIALIZED); return_val_if_fail (reserved == NULL, CKR_ARGUMENTS_BAD); - p11_mutex_lock (&init_mutex); - - /* This should stop all other calls in */ - pkcs11_initialized = false; - pkcs11_initialized_pid = 0; - - p11_dict_free (the_objects); - the_objects = NULL; - - p11_dict_free (the_sessions); - the_sessions = NULL; - logged_in = false; - the_user_type = 0; - - free (the_pin); - - p11_mutex_unlock (&init_mutex); - + module_finalize (); return CKR_OK; } -static const CK_INFO MOCK_INFO = { - { CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, - "MOCK MANUFACTURER ", - 0, - "MOCK LIBRARY ", - { 45, 145 } -}; - +CK_RV +mock_X_Finalize (CK_X_FUNCTION_LIST *self, + CK_VOID_PTR reserved) +{ + return mock_C_Finalize (reserved); +} CK_RV mock_C_GetInfo (CK_INFO_PTR info) @@ -458,6 +484,13 @@ mock_C_GetInfo (CK_INFO_PTR info) } CK_RV +mock_X_GetInfo (CK_X_FUNCTION_LIST *self, + CK_INFO_PTR info) +{ + return mock_C_GetInfo (info); +} + +CK_RV mock_C_GetFunctionList_not_supported (CK_FUNCTION_LIST_PTR_PTR list) { /* This would be a strange call to receive, should be overridden */ @@ -505,6 +538,18 @@ mock_C_GetSlotList__no_tokens (CK_BBOOL token_present, return CKR_OK; } +CK_RV +mock_X_GetSlotList__no_tokens (CK_X_FUNCTION_LIST *self, + CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count) +{ + return mock_C_GetSlotList__no_tokens (token_present, + slot_list, + count); +; +} + /* Update mock-module.h URIs when updating this */ static const CK_SLOT_INFO MOCK_INFO_ONE = { @@ -569,6 +614,16 @@ mock_C_GetSlotInfo__invalid_slotid (CK_SLOT_ID id, return CKR_SLOT_ID_INVALID; } +CK_RV +mock_X_GetSlotInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID id, + CK_SLOT_INFO_PTR info) +{ + return_val_if_fail (info, CKR_ARGUMENTS_BAD); + + return CKR_SLOT_ID_INVALID; +} + /* Update gck-mock.h URIs when updating this */ static const CK_TOKEN_INFO MOCK_TOKEN_ONE = { @@ -617,6 +672,16 @@ mock_C_GetTokenInfo__invalid_slotid (CK_SLOT_ID slot_id, return CKR_SLOT_ID_INVALID; } +CK_RV +mock_X_GetTokenInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_TOKEN_INFO_PTR info) +{ + return_val_if_fail (info, CKR_ARGUMENTS_BAD); + + return CKR_SLOT_ID_INVALID; +} + /* * TWO mechanisms: * CKM_MOCK_CAPITALIZE @@ -651,8 +716,8 @@ mock_C_GetMechanismList (CK_SLOT_ID slot_id, } CK_RV -mock_C_GetTokenInfo_not_initialized (CK_SLOT_ID slot_id, - CK_TOKEN_INFO_PTR info) +mock_C_GetTokenInfo__not_initialized (CK_SLOT_ID slot_id, + CK_TOKEN_INFO_PTR info) { CK_RV rv; @@ -679,6 +744,17 @@ mock_C_GetMechanismList__invalid_slotid (CK_SLOT_ID id, return CKR_SLOT_ID_INVALID; } +CK_RV +mock_X_GetMechanismList__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID id, + CK_MECHANISM_TYPE_PTR mechanism_list, + CK_ULONG_PTR count) +{ + return_val_if_fail (count, CKR_ARGUMENTS_BAD); + + return CKR_SLOT_ID_INVALID; +} + static const CK_MECHANISM_INFO MOCK_MECH_CAPITALIZE = { 512, 4096, CKF_ENCRYPT | CKF_DECRYPT }; @@ -721,6 +797,17 @@ mock_C_GetMechanismInfo__invalid_slotid (CK_SLOT_ID slot_id, } CK_RV +mock_X_GetMechanismInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_MECHANISM_TYPE type, + CK_MECHANISM_INFO_PTR info) +{ + return_val_if_fail (info, CKR_ARGUMENTS_BAD); + + return CKR_SLOT_ID_INVALID; +} + +CK_RV mock_C_InitToken__specific_args (CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, CK_ULONG pin_len, @@ -757,6 +844,16 @@ mock_C_InitToken__invalid_slotid (CK_SLOT_ID slot_id, } CK_RV +mock_X_InitToken__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len, + CK_UTF8CHAR_PTR label) +{ + return CKR_SLOT_ID_INVALID; +} + +CK_RV mock_C_WaitForSlotEvent (CK_FLAGS flags, CK_SLOT_ID_PTR slot, CK_VOID_PTR reserved) @@ -781,6 +878,17 @@ mock_C_WaitForSlotEvent__no_event (CK_FLAGS flags, } CK_RV +mock_X_WaitForSlotEvent__no_event (CK_X_FUNCTION_LIST *self, + CK_FLAGS flags, + CK_SLOT_ID_PTR slot, + CK_VOID_PTR reserved) +{ + return_val_if_fail (slot, CKR_ARGUMENTS_BAD); + + return CKR_NO_EVENT; +} + +CK_RV mock_C_OpenSession (CK_SLOT_ID slot_id, CK_FLAGS flags, CK_VOID_PTR user_data, @@ -828,6 +936,19 @@ mock_C_OpenSession__invalid_slotid (CK_SLOT_ID slot_id, } CK_RV +mock_X_OpenSession__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_FLAGS flags, + CK_VOID_PTR user_data, + CK_NOTIFY callback, + CK_SESSION_HANDLE_PTR session) +{ + return_val_if_fail (session, CKR_ARGUMENTS_BAD); + + return CKR_SLOT_ID_INVALID; +} + +CK_RV mock_C_OpenSession__fails (CK_SLOT_ID slot_id, CK_FLAGS flags, CK_VOID_PTR user_data, @@ -859,6 +980,13 @@ mock_C_CloseSession__invalid_handle (CK_SESSION_HANDLE session) } CK_RV +mock_X_CloseSession__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_CloseAllSessions (CK_SLOT_ID slot_id) { if (slot_id == MOCK_SLOT_TWO_ID) @@ -877,6 +1005,13 @@ mock_C_CloseAllSessions__invalid_slotid (CK_SLOT_ID slot_id) } CK_RV +mock_X_CloseAllSessions__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id) +{ + return CKR_SLOT_ID_INVALID; +} + +CK_RV mock_C_GetFunctionStatus (CK_SESSION_HANDLE session) { if (!p11_dict_get (the_sessions, handle_to_pointer (session))) @@ -913,7 +1048,7 @@ mock_C_GetSessionInfo (CK_SESSION_HANDLE session, return_val_if_fail (info != NULL, CKR_ARGUMENTS_BAD); sess = p11_dict_get (the_sessions, handle_to_pointer (session)); - if (!session) + if (!sess) return CKR_SESSION_HANDLE_INVALID; if (logged_in) { @@ -942,6 +1077,16 @@ mock_C_GetSessionInfo__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GetSessionInfo__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_SESSION_INFO_PTR info) +{ + return_val_if_fail (info, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_InitPIN__specific_args (CK_SESSION_HANDLE session, CK_UTF8CHAR_PTR pin, CK_ULONG pin_len) @@ -972,6 +1117,15 @@ mock_C_InitPIN__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_InitPIN__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SetPIN__specific_args (CK_SESSION_HANDLE session, CK_UTF8CHAR_PTR old_pin, CK_ULONG old_pin_len, @@ -1011,6 +1165,17 @@ mock_C_SetPIN__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SetPIN__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_UTF8CHAR_PTR old_pin, + CK_ULONG old_pin_len, + CK_UTF8CHAR_PTR new_pin, + CK_ULONG new_pin_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GetOperationState (CK_SESSION_HANDLE session, CK_BYTE_PTR operation_state, CK_ULONG_PTR operation_state_len) @@ -1045,6 +1210,15 @@ mock_C_GetOperationState__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GetOperationState__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR operation_state, + CK_ULONG_PTR operation_state_len) +{ + return CKR_FUNCTION_NOT_SUPPORTED; +} + +CK_RV mock_C_SetOperationState (CK_SESSION_HANDLE session, CK_BYTE_PTR operation_state, CK_ULONG operation_state_len, @@ -1079,6 +1253,17 @@ mock_C_SetOperationState__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SetOperationState__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR operation_state, + CK_ULONG operation_state_len, + CK_OBJECT_HANDLE encryption_key, + CK_OBJECT_HANDLE authentication_key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Login (CK_SESSION_HANDLE session, CK_USER_TYPE user_type, CK_UTF8CHAR_PTR pin, @@ -1127,6 +1312,16 @@ mock_C_Login__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Login__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_USER_TYPE user_type, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Logout (CK_SESSION_HANDLE session) { Session *sess; @@ -1150,6 +1345,13 @@ mock_C_Logout__invalid_handle (CK_SESSION_HANDLE session) } CK_RV +mock_X_Logout__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_CreateObject (CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR template, CK_ULONG count, @@ -1195,6 +1397,18 @@ mock_C_CreateObject__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_CreateObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR new_object) +{ + return_val_if_fail (new_object, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_CopyObject (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -1246,6 +1460,19 @@ mock_C_CopyObject__invalid_handle (CK_SESSION_HANDLE session, CK_RV +mock_X_CopyObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR new_object) +{ + return_val_if_fail (new_object, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DestroyObject (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object) { @@ -1274,6 +1501,14 @@ mock_C_DestroyObject__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DestroyObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GetObjectSize (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ULONG_PTR size) @@ -1313,6 +1548,17 @@ mock_C_GetObjectSize__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GetObjectSize__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ULONG_PTR size) +{ + return_val_if_fail (size, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GetAttributeValue (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -1371,6 +1617,16 @@ mock_C_GetAttributeValue__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GetAttributeValue__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GetAttributeValue__fail_first (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -1428,6 +1684,16 @@ mock_C_SetAttributeValue__invalid_handle (CK_SESSION_HANDLE session, return CKR_SESSION_HANDLE_INVALID; } +CK_RV +mock_X_SetAttributeValue__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + return CKR_SESSION_HANDLE_INVALID; +} + typedef struct _FindObjects { CK_ATTRIBUTE *template; CK_ULONG count; @@ -1512,6 +1778,15 @@ mock_C_FindObjectsInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_FindObjectsInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_FindObjectsInit__fails (CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR template, CK_ULONG count) @@ -1563,6 +1838,18 @@ mock_C_FindObjects__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_FindObjects__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE_PTR objects, + CK_ULONG max_count, + CK_ULONG_PTR count) +{ + return_val_if_fail (count, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_FindObjects__fails (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE_PTR objects, CK_ULONG max_count, @@ -1599,6 +1886,13 @@ mock_C_FindObjectsFinal__invalid_handle (CK_SESSION_HANDLE session) } CK_RV +mock_X_FindObjectsFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_EncryptInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key) @@ -1634,6 +1928,15 @@ mock_C_EncryptInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_EncryptInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Encrypt (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -1661,6 +1964,19 @@ mock_C_Encrypt__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Encrypt__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR encrypted_data, + CK_ULONG_PTR encrypted_data_len) +{ + return_val_if_fail (encrypted_data_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_EncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -1713,6 +2029,19 @@ mock_C_EncryptUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_EncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR encrypted_part, + CK_ULONG_PTR encrypted_part_len) +{ + return_val_if_fail (encrypted_part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_EncryptFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR last_encrypted_part, CK_ULONG_PTR last_encrypted_part_len) @@ -1749,6 +2078,17 @@ mock_C_EncryptFinal__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_EncryptFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR last_part, + CK_ULONG_PTR last_part_len) +{ + return_val_if_fail (last_part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DecryptInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key) @@ -1784,6 +2124,15 @@ mock_C_DecryptInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DecryptInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Decrypt (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_data, CK_ULONG encrypted_data_len, @@ -1811,6 +2160,19 @@ mock_C_Decrypt__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Decrypt__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_data, + CK_ULONG enc_data_len, + CK_BYTE_PTR data, + CK_ULONG_PTR data_len) +{ + return_val_if_fail (data_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DecryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -1863,6 +2225,19 @@ mock_C_DecryptUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DecryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len) +{ + return_val_if_fail (part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DecryptFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR last_part, CK_ULONG_PTR last_part_len) @@ -1900,6 +2275,17 @@ mock_C_DecryptFinal__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DecryptFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR last_part, + CK_ULONG_PTR last_part_len) +{ + return_val_if_fail (last_part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DigestInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism) { @@ -1932,6 +2318,14 @@ mock_C_DigestInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DigestInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Digest (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -1961,6 +2355,19 @@ mock_C_Digest__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Digest__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR digest, + CK_ULONG_PTR digest_len) +{ + return_val_if_fail (digest_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DigestUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len) @@ -1990,6 +2397,15 @@ mock_C_DigestUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DigestUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DigestKey (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key) { @@ -2017,6 +2433,14 @@ mock_C_DigestKey__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DigestKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DigestFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR digest, CK_ULONG_PTR digest_len) @@ -2068,6 +2492,17 @@ mock_C_DigestFinal__invalid_handle (CK_SESSION_HANDLE session, return CKR_SESSION_HANDLE_INVALID; } +CK_RV +mock_X_DigestFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR digest, + CK_ULONG_PTR digest_len) +{ + return_val_if_fail (digest_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + static CK_RV prefix_mechanism_init (CK_SESSION_HANDLE session, CK_ATTRIBUTE_TYPE method, @@ -2156,6 +2591,15 @@ mock_C_SignInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Sign (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -2184,6 +2628,19 @@ mock_C_Sign__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Sign__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len) +{ + return_val_if_fail (signature_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SignUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len) @@ -2214,6 +2671,17 @@ mock_C_SignUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len) +{ + return_val_if_fail (part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SignFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG_PTR signature_len) @@ -2270,6 +2738,17 @@ mock_C_SignFinal__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len) +{ + return_val_if_fail (signature_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SignRecoverInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key) @@ -2287,6 +2766,15 @@ mock_C_SignRecoverInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignRecoverInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SignRecover (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -2345,6 +2833,19 @@ mock_C_SignRecover__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignRecover__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len) +{ + return_val_if_fail (signature_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_VerifyInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key) @@ -2362,6 +2863,15 @@ mock_C_VerifyInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_VerifyInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_Verify (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -2388,6 +2898,17 @@ mock_C_Verify__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_Verify__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG signature_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_VerifyUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len) @@ -2416,6 +2937,15 @@ mock_C_VerifyUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_VerifyUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_VerifyFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG signature_len) @@ -2463,6 +2993,15 @@ mock_C_VerifyFinal__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_VerifyFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG signature_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_VerifyRecoverInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key) @@ -2480,6 +3019,15 @@ mock_C_VerifyRecoverInit__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_VerifyRecoverInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_VerifyRecover (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG signature_len, @@ -2534,6 +3082,19 @@ mock_C_VerifyRecover__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_VerifyRecover__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG signature_len, + CK_BYTE_PTR data, + CK_ULONG_PTR data_len) +{ + return_val_if_fail (data_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DigestEncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -2562,6 +3123,19 @@ mock_C_DigestEncryptUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DigestEncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR enc_part, + CK_ULONG_PTR enc_part_len) +{ + return_val_if_fail (enc_part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DecryptDigestUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -2590,6 +3164,19 @@ mock_C_DecryptDigestUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DecryptDigestUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len) +{ + return_val_if_fail (part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SignEncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -2618,6 +3205,19 @@ mock_C_SignEncryptUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SignEncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR enc_part, + CK_ULONG_PTR enc_part_len) +{ + return_val_if_fail (enc_part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DecryptVerifyUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -2646,6 +3246,19 @@ mock_C_DecryptVerifyUpdate__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DecryptVerifyUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len) +{ + return_val_if_fail (part_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GenerateKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR template, @@ -2700,6 +3313,17 @@ mock_C_GenerateKey__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GenerateKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GenerateKeyPair (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR public_key_template, @@ -2772,6 +3396,20 @@ mock_C_GenerateKeyPair__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_GenerateKeyPair__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_ATTRIBUTE_PTR pub_template, + CK_ULONG pub_count, + CK_ATTRIBUTE_PTR priv_template, + CK_ULONG priv_count, + CK_OBJECT_HANDLE_PTR pub_key, + CK_OBJECT_HANDLE_PTR priv_key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_WrapKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE wrapping_key, @@ -2848,6 +3486,20 @@ mock_C_WrapKey__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_WrapKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE wrapping_key, + CK_OBJECT_HANDLE key, + CK_BYTE_PTR wrapped_key, + CK_ULONG_PTR wrapped_key_len) +{ + return_val_if_fail (wrapped_key_len, CKR_ARGUMENTS_BAD); + + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_UnwrapKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE unwrapping_key, @@ -2920,6 +3572,20 @@ mock_C_UnwrapKey__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_UnwrapKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE unwrapping_key, + CK_BYTE_PTR wrapped_key, + CK_ULONG wrapped_key_len, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_DeriveKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE base_key, @@ -2985,6 +3651,18 @@ mock_C_DeriveKey__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_DeriveKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE base_key, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_SeedRandom (CK_SESSION_HANDLE session, CK_BYTE_PTR seed, CK_ULONG seed_len) @@ -3012,6 +3690,15 @@ mock_C_SeedRandom__invalid_handle (CK_SESSION_HANDLE session, } CK_RV +mock_X_SeedRandom__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR seed, + CK_ULONG seed_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + +CK_RV mock_C_GenerateRandom (CK_SESSION_HANDLE session, CK_BYTE_PTR random_data, CK_ULONG random_len) @@ -3043,6 +3730,15 @@ mock_C_GenerateRandom__invalid_handle (CK_SESSION_HANDLE session, return CKR_SESSION_HANDLE_INVALID; } +CK_RV +mock_X_GenerateRandom__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR random_data, + CK_ULONG random_len) +{ + return CKR_SESSION_HANDLE_INVALID; +} + CK_FUNCTION_LIST mock_module_no_slots = { { CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, /* version */ mock_C_Initialize, @@ -3115,6 +3811,75 @@ CK_FUNCTION_LIST mock_module_no_slots = { mock_C_WaitForSlotEvent__no_event, }; +CK_X_FUNCTION_LIST mock_x_module_no_slots = { + { CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, /* version */ + mock_X_Initialize, + mock_X_Finalize, + mock_X_GetInfo, + mock_X_GetSlotList__no_tokens, + mock_X_GetSlotInfo__invalid_slotid, + mock_X_GetTokenInfo__invalid_slotid, + mock_X_GetMechanismList__invalid_slotid, + mock_X_GetMechanismInfo__invalid_slotid, + mock_X_InitToken__invalid_slotid, + mock_X_InitPIN__invalid_handle, + mock_X_SetPIN__invalid_handle, + mock_X_OpenSession__invalid_slotid, + mock_X_CloseSession__invalid_handle, + mock_X_CloseAllSessions__invalid_slotid, + mock_X_GetSessionInfo__invalid_handle, + mock_X_GetOperationState__invalid_handle, + mock_X_SetOperationState__invalid_handle, + mock_X_Login__invalid_handle, + mock_X_Logout__invalid_handle, + mock_X_CreateObject__invalid_handle, + mock_X_CopyObject__invalid_handle, + mock_X_DestroyObject__invalid_handle, + mock_X_GetObjectSize__invalid_handle, + mock_X_GetAttributeValue__invalid_handle, + mock_X_SetAttributeValue__invalid_handle, + mock_X_FindObjectsInit__invalid_handle, + mock_X_FindObjects__invalid_handle, + mock_X_FindObjectsFinal__invalid_handle, + mock_X_EncryptInit__invalid_handle, + mock_X_Encrypt__invalid_handle, + mock_X_EncryptUpdate__invalid_handle, + mock_X_EncryptFinal__invalid_handle, + mock_X_DecryptInit__invalid_handle, + mock_X_Decrypt__invalid_handle, + mock_X_DecryptUpdate__invalid_handle, + mock_X_DecryptFinal__invalid_handle, + mock_X_DigestInit__invalid_handle, + mock_X_Digest__invalid_handle, + mock_X_DigestUpdate__invalid_handle, + mock_X_DigestKey__invalid_handle, + mock_X_DigestFinal__invalid_handle, + mock_X_SignInit__invalid_handle, + mock_X_Sign__invalid_handle, + mock_X_SignUpdate__invalid_handle, + mock_X_SignFinal__invalid_handle, + mock_X_SignRecoverInit__invalid_handle, + mock_X_SignRecover__invalid_handle, + mock_X_VerifyInit__invalid_handle, + mock_X_Verify__invalid_handle, + mock_X_VerifyUpdate__invalid_handle, + mock_X_VerifyFinal__invalid_handle, + mock_X_VerifyRecoverInit__invalid_handle, + mock_X_VerifyRecover__invalid_handle, + mock_X_DigestEncryptUpdate__invalid_handle, + mock_X_DecryptDigestUpdate__invalid_handle, + mock_X_SignEncryptUpdate__invalid_handle, + mock_X_DecryptVerifyUpdate__invalid_handle, + mock_X_GenerateKey__invalid_handle, + mock_X_GenerateKeyPair__invalid_handle, + mock_X_WrapKey__invalid_handle, + mock_X_UnwrapKey__invalid_handle, + mock_X_DeriveKey__invalid_handle, + mock_X_SeedRandom__invalid_handle, + mock_X_GenerateRandom__invalid_handle, + mock_X_WaitForSlotEvent__no_event, +}; + CK_FUNCTION_LIST mock_module = { { CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, /* version */ mock_C_Initialize, diff --git a/common/mock.h b/common/mock.h index d09c8be..9128a63 100644 --- a/common/mock.h +++ b/common/mock.h @@ -37,6 +37,7 @@ #include "compat.h" #include "pkcs11.h" +#include "pkcs11x.h" enum { MOCK_DATA_OBJECT = 2, @@ -86,13 +87,25 @@ enum { MOCK_SLOT_ONE_ID = 52, MOCK_SLOT_TWO_ID = 134, + + MOCK_SLOTS_PRESENT = 1, + MOCK_SLOTS_ALL = 2, }; +static const CK_INFO MOCK_INFO = { + { CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR }, + "MOCK MANUFACTURER ", + 0, + "MOCK LIBRARY ", + { 45, 145 } +}; extern CK_FUNCTION_LIST mock_module; extern CK_FUNCTION_LIST mock_module_no_slots; +extern CK_X_FUNCTION_LIST mock_x_module_no_slots; + void mock_module_init (void); typedef bool (* mock_enumerator) (CK_OBJECT_HANDLE handle, @@ -106,19 +119,30 @@ void mock_module_enumerate_objects (CK_SESSION_HANDLE sess void mock_module_add_object (CK_SLOT_ID slot_id, const CK_ATTRIBUTE *attrs); +void mock_module_reset (void); + +bool mock_module_initialized (void); + void mock_module_take_object (CK_SLOT_ID slot_id, CK_ATTRIBUTE *attrs); -void mock_module_reset_objects (CK_SLOT_ID slot_id); - CK_RV mock_C_Initialize (CK_VOID_PTR init_args); CK_RV mock_C_Initialize__fails (CK_VOID_PTR init_args); +CK_RV mock_X_Initialize (CK_X_FUNCTION_LIST *self, + CK_VOID_PTR init_args); + CK_RV mock_C_Finalize (CK_VOID_PTR reserved); +CK_RV mock_X_Finalize (CK_X_FUNCTION_LIST *self, + CK_VOID_PTR reserved); + CK_RV mock_C_GetInfo (CK_INFO_PTR info); +CK_RV mock_X_GetInfo (CK_X_FUNCTION_LIST *self, + CK_INFO_PTR info); + CK_RV mock_C_GetFunctionList_not_supported (CK_FUNCTION_LIST_PTR_PTR list); CK_RV mock_C_GetSlotList (CK_BBOOL token_present, @@ -140,16 +164,29 @@ CK_RV mock_C_GetSlotList__fail_late (CK_BBOOL token_present CK_RV mock_C_GetSlotInfo (CK_SLOT_ID slot_id, CK_SLOT_INFO_PTR info); +CK_RV mock_X_GetSlotList__no_tokens (CK_X_FUNCTION_LIST *self, + CK_BBOOL token_present, + CK_SLOT_ID_PTR slot_list, + CK_ULONG_PTR count); + CK_RV mock_C_GetSlotInfo__invalid_slotid (CK_SLOT_ID slot_id, CK_SLOT_INFO_PTR info); +CK_RV mock_X_GetSlotInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_SLOT_INFO_PTR info); + CK_RV mock_C_GetTokenInfo (CK_SLOT_ID slot_id, CK_TOKEN_INFO_PTR info); CK_RV mock_C_GetTokenInfo__invalid_slotid (CK_SLOT_ID slot_id, CK_TOKEN_INFO_PTR info); -CK_RV mock_C_GetTokenInfo_not_initialized (CK_SLOT_ID slot_id, +CK_RV mock_X_GetTokenInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_TOKEN_INFO_PTR info); + +CK_RV mock_C_GetTokenInfo__not_initialized (CK_SLOT_ID slot_id, CK_TOKEN_INFO_PTR info); CK_RV mock_C_GetMechanismList (CK_SLOT_ID slot_id, @@ -160,6 +197,11 @@ CK_RV mock_C_GetMechanismList__invalid_slotid (CK_SLOT_ID slot_id, CK_MECHANISM_TYPE_PTR mechanism_list, CK_ULONG_PTR count); +CK_RV mock_X_GetMechanismList__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_MECHANISM_TYPE_PTR mechanism_list, + CK_ULONG_PTR count); + CK_RV mock_C_GetMechanismInfo (CK_SLOT_ID slot_id, CK_MECHANISM_TYPE type, CK_MECHANISM_INFO_PTR info); @@ -168,6 +210,11 @@ CK_RV mock_C_GetMechanismInfo__invalid_slotid (CK_SLOT_ID slot_id, CK_MECHANISM_TYPE type, CK_MECHANISM_INFO_PTR info); +CK_RV mock_X_GetMechanismInfo__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_MECHANISM_TYPE type, + CK_MECHANISM_INFO_PTR info); + CK_RV mock_C_InitToken__specific_args (CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, CK_ULONG pin_len, @@ -178,6 +225,13 @@ CK_RV mock_C_InitToken__invalid_slotid (CK_SLOT_ID slot_id, CK_ULONG pin_len, CK_UTF8CHAR_PTR label); +CK_RV mock_X_InitToken__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len, + CK_UTF8CHAR_PTR label); + + CK_RV mock_C_WaitForSlotEvent (CK_FLAGS flags, CK_SLOT_ID_PTR slot, CK_VOID_PTR reserved); @@ -186,12 +240,24 @@ CK_RV mock_C_WaitForSlotEvent__no_event (CK_FLAGS flags, CK_SLOT_ID_PTR slot, CK_VOID_PTR reserved); +CK_RV mock_X_WaitForSlotEvent__no_event (CK_X_FUNCTION_LIST *self, + CK_FLAGS flags, + CK_SLOT_ID_PTR slot, + CK_VOID_PTR reserved); + CK_RV mock_C_OpenSession__invalid_slotid (CK_SLOT_ID slot_id, CK_FLAGS flags, CK_VOID_PTR user_data, CK_NOTIFY callback, CK_SESSION_HANDLE_PTR session); +CK_RV mock_X_OpenSession__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id, + CK_FLAGS flags, + CK_VOID_PTR user_data, + CK_NOTIFY callback, + CK_SESSION_HANDLE_PTR session); + CK_RV mock_C_OpenSession__fails (CK_SLOT_ID slot_id, CK_FLAGS flags, CK_VOID_PTR user_data, @@ -208,10 +274,16 @@ CK_RV mock_C_CloseSession (CK_SESSION_HANDLE sess CK_RV mock_C_CloseSession__invalid_handle (CK_SESSION_HANDLE session); +CK_RV mock_X_CloseSession__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session); + CK_RV mock_C_CloseAllSessions (CK_SLOT_ID slot_id); CK_RV mock_C_CloseAllSessions__invalid_slotid (CK_SLOT_ID slot_id); +CK_RV mock_X_CloseAllSessions__invalid_slotid (CK_X_FUNCTION_LIST *self, + CK_SLOT_ID slot_id); + CK_RV mock_C_GetFunctionStatus (CK_SESSION_HANDLE session); CK_RV mock_C_GetFunctionStatus__not_parallel (CK_SESSION_HANDLE session); @@ -226,6 +298,10 @@ CK_RV mock_C_GetSessionInfo (CK_SESSION_HANDLE sess CK_RV mock_C_GetSessionInfo__invalid_handle (CK_SESSION_HANDLE session, CK_SESSION_INFO_PTR info); +CK_RV mock_X_GetSessionInfo__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_SESSION_INFO_PTR info); + CK_RV mock_C_InitPIN__specific_args (CK_SESSION_HANDLE session, CK_UTF8CHAR_PTR pin, CK_ULONG pin_len); @@ -234,6 +310,11 @@ CK_RV mock_C_InitPIN__invalid_handle (CK_SESSION_HANDLE sess CK_UTF8CHAR_PTR pin, CK_ULONG pin_len); +CK_RV mock_X_InitPIN__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len); + CK_RV mock_C_SetPIN__specific_args (CK_SESSION_HANDLE session, CK_UTF8CHAR_PTR old_pin, CK_ULONG old_pin_len, @@ -246,6 +327,13 @@ CK_RV mock_C_SetPIN__invalid_handle (CK_SESSION_HANDLE sess CK_UTF8CHAR_PTR new_pin, CK_ULONG new_pin_len); +CK_RV mock_X_SetPIN__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_UTF8CHAR_PTR old_pin, + CK_ULONG old_pin_len, + CK_UTF8CHAR_PTR new_pin, + CK_ULONG new_pin_len); + CK_RV mock_C_GetOperationState (CK_SESSION_HANDLE session, CK_BYTE_PTR operation_state, CK_ULONG_PTR operation_state_len); @@ -254,6 +342,11 @@ CK_RV mock_C_GetOperationState__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR operation_state, CK_ULONG_PTR operation_state_len); +CK_RV mock_X_GetOperationState__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR operation_state, + CK_ULONG_PTR operation_state_len); + CK_RV mock_C_SetOperationState (CK_SESSION_HANDLE session, CK_BYTE_PTR operation_state, CK_ULONG operation_state_len, @@ -266,6 +359,13 @@ CK_RV mock_C_SetOperationState__invalid_handle (CK_SESSION_HANDLE sess CK_OBJECT_HANDLE encryption_key, CK_OBJECT_HANDLE authentication_key); +CK_RV mock_X_SetOperationState__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR operation_state, + CK_ULONG operation_state_len, + CK_OBJECT_HANDLE encryption_key, + CK_OBJECT_HANDLE authentication_key); + CK_RV mock_C_Login (CK_SESSION_HANDLE session, CK_USER_TYPE user_type, CK_UTF8CHAR_PTR pin, @@ -276,10 +376,19 @@ CK_RV mock_C_Login__invalid_handle (CK_SESSION_HANDLE sess CK_UTF8CHAR_PTR pin, CK_ULONG pin_len); +CK_RV mock_X_Login__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_USER_TYPE user_type, + CK_UTF8CHAR_PTR pin, + CK_ULONG pin_len); + CK_RV mock_C_Logout (CK_SESSION_HANDLE session); CK_RV mock_C_Logout__invalid_handle (CK_SESSION_HANDLE session); +CK_RV mock_X_Logout__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session); + CK_RV mock_C_CreateObject (CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR template, CK_ULONG count, @@ -290,6 +399,12 @@ CK_RV mock_C_CreateObject__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG count, CK_OBJECT_HANDLE_PTR new_object); +CK_RV mock_X_CreateObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR new_object); + CK_RV mock_C_CopyObject (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -302,12 +417,23 @@ CK_RV mock_C_CopyObject__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG count, CK_OBJECT_HANDLE_PTR new_object); +CK_RV mock_X_CopyObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR new_object); + CK_RV mock_C_DestroyObject (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object); CK_RV mock_C_DestroyObject__invalid_handle (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object); +CK_RV mock_X_DestroyObject__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object); + CK_RV mock_C_GetObjectSize (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ULONG_PTR size); @@ -316,6 +442,11 @@ CK_RV mock_C_GetObjectSize__invalid_handle (CK_SESSION_HANDLE sess CK_OBJECT_HANDLE object, CK_ULONG_PTR size); +CK_RV mock_X_GetObjectSize__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ULONG_PTR size); + CK_RV mock_C_GetAttributeValue (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -326,6 +457,12 @@ CK_RV mock_C_GetAttributeValue__invalid_handle (CK_SESSION_HANDLE sess CK_ATTRIBUTE_PTR template, CK_ULONG count); +CK_RV mock_X_GetAttributeValue__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + CK_RV mock_C_GetAttributeValue__fail_first (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR template, @@ -346,6 +483,12 @@ CK_RV mock_C_SetAttributeValue__invalid_handle (CK_SESSION_HANDLE sess CK_ATTRIBUTE_PTR template, CK_ULONG count); +CK_RV mock_X_SetAttributeValue__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE object, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + CK_RV mock_C_FindObjectsInit (CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR template, CK_ULONG count); @@ -354,6 +497,11 @@ CK_RV mock_C_FindObjectsInit__invalid_handle (CK_SESSION_HANDLE sess CK_ATTRIBUTE_PTR template, CK_ULONG count); +CK_RV mock_X_FindObjectsInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_ATTRIBUTE_PTR template, + CK_ULONG count); + CK_RV mock_C_FindObjectsInit__fails (CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR template, CK_ULONG count); @@ -368,6 +516,12 @@ CK_RV mock_C_FindObjects__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG max_count, CK_ULONG_PTR count); +CK_RV mock_X_FindObjects__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE_PTR objects, + CK_ULONG max_count, + CK_ULONG_PTR count); + CK_RV mock_C_FindObjects__fails (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE_PTR objects, CK_ULONG max_count, @@ -377,6 +531,9 @@ CK_RV mock_C_FindObjectsFinal (CK_SESSION_HANDLE sess CK_RV mock_C_FindObjectsFinal__invalid_handle (CK_SESSION_HANDLE session); +CK_RV mock_X_FindObjectsFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session); + CK_RV mock_C_EncryptInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -385,6 +542,11 @@ CK_RV mock_C_EncryptInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_EncryptInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_Encrypt (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -397,6 +559,13 @@ CK_RV mock_C_Encrypt__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR encrypted_data, CK_ULONG_PTR encrypted_data_len); +CK_RV mock_X_Encrypt__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR encrypted_data, + CK_ULONG_PTR encrypted_data_len); + CK_RV mock_C_EncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -409,6 +578,13 @@ CK_RV mock_C_EncryptUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR encrypted_part, CK_ULONG_PTR encrypted_part_len); +CK_RV mock_X_EncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR encrypted_part, + CK_ULONG_PTR encrypted_part_len); + CK_RV mock_C_EncryptFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR last_encrypted_part, CK_ULONG_PTR last_encrypted_part_len); @@ -417,6 +593,11 @@ CK_RV mock_C_EncryptFinal__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR last_part, CK_ULONG_PTR last_part_len); +CK_RV mock_X_EncryptFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR last_part, + CK_ULONG_PTR last_part_len); + CK_RV mock_C_DecryptInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -425,6 +606,11 @@ CK_RV mock_C_DecryptInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_DecryptInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_Decrypt (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_data, CK_ULONG encrypted_data_len, @@ -437,6 +623,13 @@ CK_RV mock_C_Decrypt__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR data, CK_ULONG_PTR data_len); +CK_RV mock_X_Decrypt__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_data, + CK_ULONG enc_data_len, + CK_BYTE_PTR data, + CK_ULONG_PTR data_len); + CK_RV mock_C_DecryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -449,6 +642,13 @@ CK_RV mock_C_DecryptUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG_PTR part_len); +CK_RV mock_X_DecryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len); + CK_RV mock_C_DecryptFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR last_part, CK_ULONG_PTR last_part_len); @@ -457,12 +657,21 @@ CK_RV mock_C_DecryptFinal__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR last_part, CK_ULONG_PTR last_part_len); +CK_RV mock_X_DecryptFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR last_part, + CK_ULONG_PTR last_part_len); + CK_RV mock_C_DigestInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism); CK_RV mock_C_DigestInit__invalid_handle (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism); +CK_RV mock_X_DigestInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism); + CK_RV mock_C_Digest (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -475,6 +684,13 @@ CK_RV mock_C_Digest__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR digest, CK_ULONG_PTR digest_len); +CK_RV mock_X_Digest__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR digest, + CK_ULONG_PTR digest_len); + CK_RV mock_C_DigestUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len); @@ -483,12 +699,21 @@ CK_RV mock_C_DigestUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG part_len); +CK_RV mock_X_DigestUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len); + CK_RV mock_C_DigestKey (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key); CK_RV mock_C_DigestKey__invalid_handle (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key); +CK_RV mock_X_DigestKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_OBJECT_HANDLE key); + CK_RV mock_C_DigestFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR digest, CK_ULONG_PTR digest_len); @@ -497,6 +722,11 @@ CK_RV mock_C_DigestFinal__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR digest, CK_ULONG_PTR digest_len); +CK_RV mock_X_DigestFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR digest, + CK_ULONG_PTR digest_len); + CK_RV mock_C_SignInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -505,6 +735,11 @@ CK_RV mock_C_SignInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_SignInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_Sign (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -517,6 +752,13 @@ CK_RV mock_C_Sign__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR signature, CK_ULONG_PTR signature_len); +CK_RV mock_X_Sign__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len); + CK_RV mock_C_SignUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len); @@ -525,6 +767,11 @@ CK_RV mock_C_SignUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG part_len); +CK_RV mock_X_SignUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len); + CK_RV mock_C_SignFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG_PTR signature_len); @@ -533,6 +780,11 @@ CK_RV mock_C_SignFinal__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR signature, CK_ULONG_PTR signature_len); +CK_RV mock_X_SignFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len); + CK_RV mock_C_SignRecoverInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -541,6 +793,11 @@ CK_RV mock_C_SignRecoverInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_SignRecoverInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_SignRecover (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -553,6 +810,13 @@ CK_RV mock_C_SignRecover__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR signature, CK_ULONG_PTR signature_len); +CK_RV mock_X_SignRecover__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG_PTR signature_len); + CK_RV mock_C_VerifyInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -561,6 +825,11 @@ CK_RV mock_C_VerifyInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_VerifyInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_Verify (CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len, @@ -573,6 +842,13 @@ CK_RV mock_C_Verify__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR signature, CK_ULONG signature_len); +CK_RV mock_X_Verify__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR data, + CK_ULONG data_len, + CK_BYTE_PTR signature, + CK_ULONG signature_len); + CK_RV mock_C_VerifyUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len); @@ -581,6 +857,11 @@ CK_RV mock_C_VerifyUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG part_len); +CK_RV mock_X_VerifyUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len); + CK_RV mock_C_VerifyFinal (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG signature_len); @@ -589,6 +870,11 @@ CK_RV mock_C_VerifyFinal__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR signature, CK_ULONG signature_len); +CK_RV mock_X_VerifyFinal__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG signature_len); + CK_RV mock_C_VerifyRecoverInit (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); @@ -597,6 +883,11 @@ CK_RV mock_C_VerifyRecoverInit__invalid_handle (CK_SESSION_HANDLE sess CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key); +CK_RV mock_X_VerifyRecoverInit__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE key); + CK_RV mock_C_VerifyRecover (CK_SESSION_HANDLE session, CK_BYTE_PTR signature, CK_ULONG signature_len, @@ -609,6 +900,13 @@ CK_RV mock_C_VerifyRecover__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR data, CK_ULONG_PTR data_len); +CK_RV mock_X_VerifyRecover__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR signature, + CK_ULONG signature_len, + CK_BYTE_PTR data, + CK_ULONG_PTR data_len); + CK_RV mock_C_DigestEncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -621,6 +919,13 @@ CK_RV mock_C_DigestEncryptUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR enc_part, CK_ULONG_PTR enc_part_len); +CK_RV mock_X_DigestEncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR enc_part, + CK_ULONG_PTR enc_part_len); + CK_RV mock_C_DecryptDigestUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -633,6 +938,13 @@ CK_RV mock_C_DecryptDigestUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG_PTR part_len); +CK_RV mock_X_DecryptDigestUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len); + CK_RV mock_C_SignEncryptUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len, @@ -645,6 +957,13 @@ CK_RV mock_C_SignEncryptUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR enc_part, CK_ULONG_PTR enc_part_len); +CK_RV mock_X_SignEncryptUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR part, + CK_ULONG part_len, + CK_BYTE_PTR enc_part, + CK_ULONG_PTR enc_part_len); + CK_RV mock_C_DecryptVerifyUpdate (CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part, CK_ULONG encrypted_part_len, @@ -657,6 +976,13 @@ CK_RV mock_C_DecryptVerifyUpdate__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR part, CK_ULONG_PTR part_len); +CK_RV mock_X_DecryptVerifyUpdate__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR enc_part, + CK_ULONG enc_part_len, + CK_BYTE_PTR part, + CK_ULONG_PTR part_len); + CK_RV mock_C_GenerateKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR template, @@ -669,6 +995,13 @@ CK_RV mock_C_GenerateKey__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG count, CK_OBJECT_HANDLE_PTR key); +CK_RV mock_X_GenerateKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key); + CK_RV mock_C_GenerateKeyPair (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR public_key_template, @@ -687,6 +1020,16 @@ CK_RV mock_C_GenerateKeyPair__invalid_handle (CK_SESSION_HANDLE sess CK_OBJECT_HANDLE_PTR pub_key, CK_OBJECT_HANDLE_PTR priv_key); +CK_RV mock_X_GenerateKeyPair__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_ATTRIBUTE_PTR pub_template, + CK_ULONG pub_count, + CK_ATTRIBUTE_PTR priv_template, + CK_ULONG priv_count, + CK_OBJECT_HANDLE_PTR pub_key, + CK_OBJECT_HANDLE_PTR priv_key); + CK_RV mock_C_WrapKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE wrapping_key, @@ -701,6 +1044,14 @@ CK_RV mock_C_WrapKey__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR wrapped_key, CK_ULONG_PTR wrapped_key_len); +CK_RV mock_X_WrapKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE wrapping_key, + CK_OBJECT_HANDLE key, + CK_BYTE_PTR wrapped_key, + CK_ULONG_PTR wrapped_key_len); + CK_RV mock_C_UnwrapKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE unwrapping_key, @@ -719,6 +1070,16 @@ CK_RV mock_C_UnwrapKey__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG count, CK_OBJECT_HANDLE_PTR key); +CK_RV mock_X_UnwrapKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE unwrapping_key, + CK_BYTE_PTR wrapped_key, + CK_ULONG wrapped_key_len, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key); + CK_RV mock_C_DeriveKey (CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE base_key, @@ -733,6 +1094,14 @@ CK_RV mock_C_DeriveKey__invalid_handle (CK_SESSION_HANDLE sess CK_ULONG count, CK_OBJECT_HANDLE_PTR key); +CK_RV mock_X_DeriveKey__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_MECHANISM_PTR mechanism, + CK_OBJECT_HANDLE base_key, + CK_ATTRIBUTE_PTR template, + CK_ULONG count, + CK_OBJECT_HANDLE_PTR key); + CK_RV mock_C_SeedRandom (CK_SESSION_HANDLE session, CK_BYTE_PTR seed, CK_ULONG seed_len); @@ -741,6 +1110,11 @@ CK_RV mock_C_SeedRandom__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR seed, CK_ULONG seed_len); +CK_RV mock_X_SeedRandom__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR seed, + CK_ULONG seed_len); + CK_RV mock_C_GenerateRandom (CK_SESSION_HANDLE session, CK_BYTE_PTR random_data, CK_ULONG random_len); @@ -749,4 +1123,9 @@ CK_RV mock_C_GenerateRandom__invalid_handle (CK_SESSION_HANDLE sess CK_BYTE_PTR random_data, CK_ULONG random_len); +CK_RV mock_X_GenerateRandom__invalid_handle (CK_X_FUNCTION_LIST *self, + CK_SESSION_HANDLE session, + CK_BYTE_PTR random_data, + CK_ULONG random_len); + #endif /* __MOCK_H__ */ diff --git a/common/path.c b/common/path.c index bba2c23..a2ba6ec 100644 --- a/common/path.c +++ b/common/path.c @@ -97,6 +97,9 @@ expand_homedir (const char *remainder) { const char *env; + if (remainder[0] == '\0') + remainder = NULL; + env = getenv ("HOME"); if (env && env[0]) { return p11_path_build (env, remainder, NULL); @@ -137,6 +140,9 @@ expand_tempdir (const char *remainder) { const char *env; + if (remainder[0] == '\0') + remainder = NULL; + env = getenv ("TEMP"); if (env && env[0]) { return p11_path_build (env, remainder, NULL); @@ -164,10 +170,10 @@ expand_tempdir (const char *remainder) } } -static bool +static inline bool is_path_component_or_null (char ch) { - return (ch == '0' || ch == '/' + return (ch == '\0' || ch == '/' #ifdef OS_WIN32 || ch == '\\' #endif @@ -181,15 +187,15 @@ p11_path_expand (const char *path) if (strncmp (path, "~", 1) == 0 && is_path_component_or_null (path[1])) { - return expand_homedir (path + 2); + return expand_homedir (path + 1); } else if (strncmp (path, "$HOME", 5) == 0 && is_path_component_or_null (path[5])) { - return expand_homedir (path + 6); + return expand_homedir (path + 5); } else if (strncmp (path, "$TEMP", 5) == 0 && is_path_component_or_null (path[5])) { - return expand_tempdir (path + 6); + return expand_tempdir (path + 5); } else { return strdup (path); @@ -201,11 +207,11 @@ p11_path_absolute (const char *path) { return_val_if_fail (path != NULL, false); -#ifdef OS_UNIX - return (path[0] == '/'); -#else - return (path[0] != '\0' && path[1] == ':' && path[2] == '\\'); + return (path[0] == '/') +#ifdef OS_WIN32 + || (path[0] != '\0' && path[1] == ':' && path[2] == '\\') #endif + ; } char * @@ -256,3 +262,39 @@ p11_path_build (const char *path, built[at] = '\0'; return built; } + +char * +p11_path_parent (const char *path) +{ + const char *e; + char *parent; + bool had = false; + + return_val_if_fail (path != NULL, NULL); + + /* Find the end of the last component */ + e = path + strlen (path); + while (e != path && is_path_component_or_null (*e)) + e--; + + /* Find the beginning of the last component */ + while (e != path && !is_path_component_or_null (*e)) { + had = true; + e--; + } + + /* Find the end of the last component */ + while (e != path && is_path_component_or_null (*e)) + e--; + + if (e == path) { + if (!had) + return NULL; + parent = strdup ("/"); + } else { + parent = strndup (path, (e - path) + 1); + } + + return_val_if_fail (parent != NULL, NULL); + return parent; +} diff --git a/common/path.h b/common/path.h index a518008..1fce607 100644 --- a/common/path.h +++ b/common/path.h @@ -59,4 +59,6 @@ char * p11_path_build (const char *path, bool p11_path_absolute (const char *path); +char * p11_path_parent (const char *path); + #endif /* P11_PATH_H__ */ diff --git a/common/pem.c b/common/pem.c index b0625ef..7fe0076 100644 --- a/common/pem.c +++ b/common/pem.c @@ -242,35 +242,31 @@ p11_pem_parse (const char *data, return nfound; } -char * +bool p11_pem_write (const unsigned char *contents, size_t length, const char *type, - size_t *pem_len) + p11_buffer *buf) { - p11_buffer buffer; size_t estimate; size_t prefix; char *target; int len; - return_val_if_fail (contents || !length, NULL); - return_val_if_fail (type, NULL); - return_val_if_fail (pem_len, NULL); + return_val_if_fail (contents || !length, false); + return_val_if_fail (type, false); + return_val_if_fail (buf, false); /* Estimate from base64 data. Algorithm from Glib reference */ estimate = length * 4 / 3 + 7; estimate += estimate / 64 + 1; - if (!p11_buffer_init_null (&buffer, estimate + 128)) - return_val_if_reached (NULL); + p11_buffer_add (buf, ARMOR_PREF_BEGIN, ARMOR_PREF_BEGIN_L); + p11_buffer_add (buf, type, -1); + p11_buffer_add (buf, ARMOR_SUFF, ARMOR_SUFF_L); - p11_buffer_add (&buffer, ARMOR_PREF_BEGIN, ARMOR_PREF_BEGIN_L); - p11_buffer_add (&buffer, type, -1); - p11_buffer_add (&buffer, ARMOR_SUFF, ARMOR_SUFF_L); - - prefix = buffer.len; - target = p11_buffer_append (&buffer, estimate); + prefix = buf->len; + target = p11_buffer_append (buf, estimate); return_val_if_fail (target != NULL, NULL); /* @@ -282,13 +278,13 @@ p11_pem_write (const unsigned char *contents, assert (len > 0); assert (len <= estimate); - buffer.len = prefix + len; + buf->len = prefix + len; - p11_buffer_add (&buffer, "\n", 1); - p11_buffer_add (&buffer, ARMOR_PREF_END, ARMOR_PREF_END_L); - p11_buffer_add (&buffer, type, -1); - p11_buffer_add (&buffer, ARMOR_SUFF, ARMOR_SUFF_L); - p11_buffer_add (&buffer, "\n", 1); + p11_buffer_add (buf, "\n", 1); + p11_buffer_add (buf, ARMOR_PREF_END, ARMOR_PREF_END_L); + p11_buffer_add (buf, type, -1); + p11_buffer_add (buf, ARMOR_SUFF, ARMOR_SUFF_L); + p11_buffer_add (buf, "\n", 1); - return p11_buffer_steal (&buffer, pem_len); + return p11_buffer_ok (buf); } diff --git a/common/pem.h b/common/pem.h index d84f418..7e4ce63 100644 --- a/common/pem.h +++ b/common/pem.h @@ -35,6 +35,9 @@ #ifndef P11_PEM_H_ #define P11_PEM_H_ +#include "buffer.h" +#include "compat.h" + #include <sys/types.h> typedef void (*p11_pem_sink) (const char *type, @@ -47,9 +50,9 @@ unsigned int p11_pem_parse (const char *input, p11_pem_sink sink, void *user_data); -char * p11_pem_write (const unsigned char *contents, +bool p11_pem_write (const unsigned char *contents, size_t length, const char *type, - size_t *pem_len); + p11_buffer *buf); #endif /* P11_PEM_H_ */ diff --git a/common/pkcs11x.h b/common/pkcs11x.h index 58be460..dfb2a6c 100644 --- a/common/pkcs11x.h +++ b/common/pkcs11x.h @@ -149,6 +149,444 @@ typedef CK_ULONG CK_X_ASSERTION_TYPE; #endif /* CRYPTOKI_X_VENDOR_DEFINED */ +/* ------------------------------------------------------------------- + * SUBCLASSABLE PKCS#11 FUNCTIONS + */ + +typedef struct _CK_X_FUNCTION_LIST CK_X_FUNCTION_LIST; + +typedef CK_RV (* CK_X_Initialize) (CK_X_FUNCTION_LIST *, + CK_VOID_PTR); + +typedef CK_RV (* CK_X_Finalize) (CK_X_FUNCTION_LIST *, + CK_VOID_PTR); + +typedef CK_RV (* CK_X_GetInfo) (CK_X_FUNCTION_LIST *, + CK_INFO_PTR); + +typedef CK_RV (* CK_X_GetSlotList) (CK_X_FUNCTION_LIST *, + CK_BBOOL, + CK_SLOT_ID_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_GetSlotInfo) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_SLOT_INFO_PTR); + +typedef CK_RV (* CK_X_GetTokenInfo) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_TOKEN_INFO_PTR); + +typedef CK_RV (* CK_X_GetMechanismList) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_MECHANISM_TYPE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_GetMechanismInfo) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_MECHANISM_TYPE, + CK_MECHANISM_INFO_PTR); + +typedef CK_RV (* CK_X_InitToken) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR); + +typedef CK_RV (* CK_X_InitPIN) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_SetPIN) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_OpenSession) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID, + CK_FLAGS, + CK_VOID_PTR, + CK_NOTIFY, + CK_SESSION_HANDLE_PTR); + +typedef CK_RV (* CK_X_CloseSession) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE); + +typedef CK_RV (* CK_X_CloseAllSessions) (CK_X_FUNCTION_LIST *, + CK_SLOT_ID); + +typedef CK_RV (* CK_X_GetSessionInfo) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_SESSION_INFO_PTR); + +typedef CK_RV (* CK_X_GetOperationState) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_SetOperationState) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_Login) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_USER_TYPE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_Logout) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE); + +typedef CK_RV (* CK_X_CreateObject) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_CopyObject) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_DestroyObject) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_GetObjectSize) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_GetAttributeValue) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_SetAttributeValue) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_FindObjectsInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_FindObjects) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE_PTR, + CK_ULONG, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_FindObjectsFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE); + +typedef CK_RV (* CK_X_EncryptInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_Encrypt) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_EncryptUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_EncryptFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DecryptInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_Decrypt) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DecryptUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DecryptFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DigestInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR); + +typedef CK_RV (* CK_X_Digest) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DigestUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_DigestKey) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_DigestFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_SignInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_Sign) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_SignUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_SignFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_SignRecoverInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_SignRecover) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_VerifyInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_Verify) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_VerifyUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_VerifyFinal) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_VerifyRecoverInit) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE); + +typedef CK_RV (* CK_X_VerifyRecover) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DigestEncryptUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DecryptDigestUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_SignEncryptUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_DecryptVerifyUpdate) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_GenerateKey) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_GenerateKeyPair) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_WrapKey) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE, + CK_OBJECT_HANDLE, + CK_BYTE_PTR, + CK_ULONG_PTR); + +typedef CK_RV (* CK_X_UnwrapKey) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE, + CK_BYTE_PTR, + CK_ULONG, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_DeriveKey) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_MECHANISM_PTR, + CK_OBJECT_HANDLE, + CK_ATTRIBUTE_PTR, + CK_ULONG, + CK_OBJECT_HANDLE_PTR); + +typedef CK_RV (* CK_X_SeedRandom) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_GenerateRandom) (CK_X_FUNCTION_LIST *, + CK_SESSION_HANDLE, + CK_BYTE_PTR, + CK_ULONG); + +typedef CK_RV (* CK_X_WaitForSlotEvent) (CK_X_FUNCTION_LIST *, + CK_FLAGS, + CK_SLOT_ID_PTR, + CK_VOID_PTR); + +struct _CK_X_FUNCTION_LIST { + CK_VERSION version; + CK_X_Initialize C_Initialize; + CK_X_Finalize C_Finalize; + CK_X_GetInfo C_GetInfo; + CK_X_GetSlotList C_GetSlotList; + CK_X_GetSlotInfo C_GetSlotInfo; + CK_X_GetTokenInfo C_GetTokenInfo; + CK_X_GetMechanismList C_GetMechanismList; + CK_X_GetMechanismInfo C_GetMechanismInfo; + CK_X_InitToken C_InitToken; + CK_X_InitPIN C_InitPIN; + CK_X_SetPIN C_SetPIN; + CK_X_OpenSession C_OpenSession; + CK_X_CloseSession C_CloseSession; + CK_X_CloseAllSessions C_CloseAllSessions; + CK_X_GetSessionInfo C_GetSessionInfo; + CK_X_GetOperationState C_GetOperationState; + CK_X_SetOperationState C_SetOperationState; + CK_X_Login C_Login; + CK_X_Logout C_Logout; + CK_X_CreateObject C_CreateObject; + CK_X_CopyObject C_CopyObject; + CK_X_DestroyObject C_DestroyObject; + CK_X_GetObjectSize C_GetObjectSize; + CK_X_GetAttributeValue C_GetAttributeValue; + CK_X_SetAttributeValue C_SetAttributeValue; + CK_X_FindObjectsInit C_FindObjectsInit; + CK_X_FindObjects C_FindObjects; + CK_X_FindObjectsFinal C_FindObjectsFinal; + CK_X_EncryptInit C_EncryptInit; + CK_X_Encrypt C_Encrypt; + CK_X_EncryptUpdate C_EncryptUpdate; + CK_X_EncryptFinal C_EncryptFinal; + CK_X_DecryptInit C_DecryptInit; + CK_X_Decrypt C_Decrypt; + CK_X_DecryptUpdate C_DecryptUpdate; + CK_X_DecryptFinal C_DecryptFinal; + CK_X_DigestInit C_DigestInit; + CK_X_Digest C_Digest; + CK_X_DigestUpdate C_DigestUpdate; + CK_X_DigestKey C_DigestKey; + CK_X_DigestFinal C_DigestFinal; + CK_X_SignInit C_SignInit; + CK_X_Sign C_Sign; + CK_X_SignUpdate C_SignUpdate; + CK_X_SignFinal C_SignFinal; + CK_X_SignRecoverInit C_SignRecoverInit; + CK_X_SignRecover C_SignRecover; + CK_X_VerifyInit C_VerifyInit; + CK_X_Verify C_Verify; + CK_X_VerifyUpdate C_VerifyUpdate; + CK_X_VerifyFinal C_VerifyFinal; + CK_X_VerifyRecoverInit C_VerifyRecoverInit; + CK_X_VerifyRecover C_VerifyRecover; + CK_X_DigestEncryptUpdate C_DigestEncryptUpdate; + CK_X_DecryptDigestUpdate C_DecryptDigestUpdate; + CK_X_SignEncryptUpdate C_SignEncryptUpdate; + CK_X_DecryptVerifyUpdate C_DecryptVerifyUpdate; + CK_X_GenerateKey C_GenerateKey; + CK_X_GenerateKeyPair C_GenerateKeyPair; + CK_X_WrapKey C_WrapKey; + CK_X_UnwrapKey C_UnwrapKey; + CK_X_DeriveKey C_DeriveKey; + CK_X_SeedRandom C_SeedRandom; + CK_X_GenerateRandom C_GenerateRandom; + CK_X_WaitForSlotEvent C_WaitForSlotEvent; +}; + #if defined(__cplusplus) } #endif diff --git a/common/test.c b/common/test.c new file mode 100644 index 0000000..b6ad012 --- /dev/null +++ b/common/test.c @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2013, Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter <stefw@redhat.com> + */ + +#include "config.h" + +#define P11_TEST_SOURCE 1 + +#include "test.h" +#include "debug.h" + +#include <assert.h> +#include <setjmp.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +enum { + FIXTURE, + TEST, +}; + +typedef void (*func_with_arg) (void *); + +typedef struct _test_item { + int type; + + union { + struct { + char name[1024]; + func_with_arg func; + void *argument; + int failed; + } test; + struct { + func_with_arg setup; + func_with_arg teardown; + } fix; + } x; + + struct _test_item *next; +} test_item; + +struct { + test_item *suite; + test_item *last; + int number; + jmp_buf jump; +} gl = { NULL, NULL, 0, }; + +void +p11_test_fail (const char *filename, + int line, + const char *function, + const char *message, + ...) +{ + const char *pos; + char *output; + char *from; + char *next; + va_list va; + + assert (gl.last != NULL); + assert (gl.last->type == TEST); + gl.last->x.test.failed = 1; + + printf ("not ok %d %s\n", gl.number, gl.last->x.test.name); + + va_start (va, message); + if (vasprintf (&output, message, va) < 0) + assert (0 && "vasprintf() failed"); + va_end (va); + + for (from = output; from != NULL; ) { + next = strchr (from, '\n'); + if (next) { + next[0] = '\0'; + next += 1; + } + + printf ("# %s\n", from); + from = next; + } + + pos = strrchr (filename, '/'); + if (pos != NULL && pos[1] != '\0') + filename = pos + 1; + + printf ("# in %s() at %s:%d\n", function, filename, line); + + free (output); + + longjmp (gl.jump, 1); +} + +static void +test_push (test_item *it) +{ + test_item *item; + + item = calloc (1, sizeof (test_item)); + assert (item != NULL); + memcpy (item, it, sizeof (test_item)); + + if (!gl.suite) + gl.suite = item; + if (gl.last) + gl.last->next = item; + gl.last = item; +} + +void +p11_test (void (* function) (void), + const char *name, + ...) +{ + test_item item = { TEST, }; + va_list va; + + item.x.test.func = (func_with_arg)function; + + va_start (va, name); + vsnprintf (item.x.test.name, sizeof (item.x.test.name), name, va); + va_end (va); + + test_push (&item); +} + +void +p11_testx (void (* function) (void *), + void *argument, + const char *name, + ...) +{ + test_item item = { TEST, }; + va_list va; + + item.type = TEST; + item.x.test.func = function; + item.x.test.argument = argument; + + va_start (va, name); + vsnprintf (item.x.test.name, sizeof (item.x.test.name), name, va); + va_end (va); + + test_push (&item); +} + +void +p11_fixture (void (* setup) (void *), + void (* teardown) (void *)) +{ + test_item item; + + item.type = FIXTURE; + item.x.fix.setup = setup; + item.x.fix.teardown = teardown; + + test_push (&item); +} + +int +p11_test_run (int argc, + char **argv) +{ + test_item *fixture = NULL; + test_item *item; + test_item *next; + int count; + int ret = 0; + int setup; + + /* p11-kit specific stuff */ + putenv ("P11_KIT_STRICT=1"); + p11_debug_init (); + + assert (gl.number == 0); + gl.last = NULL; + + for (item = gl.suite, count = 0; item != NULL; item = item->next) { + if (item->type == TEST) + count++; + } + + if (count == 0) { + printf ("1..0 # No tests\n"); + return 0; + } + + printf ("1..%d\n", count); + + for (item = gl.suite, gl.number = 0; item != NULL; item = item->next) { + if (item->type == FIXTURE) { + fixture = item; + continue; + } + + assert (item->type == TEST); + gl.last = item; + gl.number++; + setup = 0; + + if (setjmp (gl.jump) == 0) { + if (fixture && fixture->x.fix.setup) + (fixture->x.fix.setup) (item->x.test.argument); + + setup = 1; + + assert (item->x.test.func); + (item->x.test.func)(item->x.test.argument); + + printf ("ok %d %s\n", gl.number, item->x.test.name); + } + + if (setup) { + if (setjmp (gl.jump) == 0) { + if (fixture && fixture->x.fix.teardown) + (fixture->x.fix.teardown) (item->x.test.argument); + } + } + + gl.last = NULL; + } + + for (item = gl.suite; item != NULL; item = next) { + if (item->type == TEST) { + if (item->x.test.failed) + ret++; + } + + next = item->next; + free (item); + } + + gl.suite = NULL; + gl.last = 0; + gl.number = 0; + return ret; +} diff --git a/common/test.h b/common/test.h new file mode 100644 index 0000000..1da3608 --- /dev/null +++ b/common/test.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2013, Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter <stefw@redhat.com> + */ + +#include "compat.h" + +#ifndef P11_TEST_H_ +#define P11_TEST_H_ + +#ifndef P11_TEST_SOURCE + +#include <string.h> + +#ifdef assert_not_reached +#undef assert_not_reached +#endif + +#ifdef assert +#undef assert +#endif + +#define assert(expr) \ + assert_true(expr) +#define assert_true(expr) \ + do { if (expr) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s)", #expr); \ + } while (0) +#define assert_false(expr) \ + do { if (expr) \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (!(%s))", #expr); \ + } while (0) +#define assert_fail(msg, detail) \ + do { const char *__s = (detail); \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "%s%s%s", (msg), __s ? ": ": "", __s ? __s : ""); \ + } while (0) +#define assert_not_reached(msg) \ + do { \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "code should not be reached"); \ + } while (0) +#define assert_ptr_not_null(ptr) \ + do { if ((ptr) != NULL) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s != NULL)", #ptr); \ + } while (0) +#define assert_num_cmp(a1, cmp, a2) \ + do { unsigned long __n1 = (a1); \ + unsigned long __n2 = (a2); \ + if (__n1 cmp __n2) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s %s %s): (%lu %s %lu)", \ + #a1, #cmp, #a2, __n1, #cmp, __n2); \ + } while (0) +#define assert_num_eq(a1, a2) \ + assert_num_cmp(a1, ==, a2) +#define assert_str_cmp(a1, cmp, a2) \ + do { const char *__s1 = (a1); \ + const char *__s2 = (a2); \ + if (__s1 && __s2 && strcmp (__s1, __s2) cmp 0) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s %s %s): (%s %s %s)", \ + #a1, #cmp, #a2, __s1 ? __s1 : "(null)", #cmp, __s2 ? __s2 : "(null)"); \ + } while (0) +#define assert_str_eq(a1, a2) \ + assert_str_cmp(a1, ==, a2) +#define assert_ptr_eq(a1, a2) \ + do { const void *__p1 = (a1); \ + const void *__p2 = (a2); \ + if (__p1 == __p2) ; else \ + p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s == %s): (0x%08lx == 0x%08lx)", \ + #a1, #a2, (unsigned long)(size_t)__p1, (unsigned long)(size_t)__p2); \ + } while (0) + +#define assert_str_contains(expr, needle) \ + do { const char *__str = (expr); \ + if (__str && strstr (__str, needle)) ; else \ + p1_test_fail (__FILE__, __LINE__, __FUNCTION__, "assertion failed (%s): '%s' does not contain '%s'", \ + #expr, __str, needle); \ + } while (0) + +#endif /* !P11_TEST_SOURCE */ + + +void p11_test_fail (const char *filename, + int line, + const char *function, + const char *message, + ...) GNUC_PRINTF(4, 5); + +void p11_test (void (* function) (void), + const char *name, + ...) GNUC_PRINTF(2, 3); + +void p11_testx (void (* function) (void *), + void *argument, + const char *name, + ...) GNUC_PRINTF(3, 4); + +void p11_fixture (void (* setup) (void *), + void (* teardown) (void *)); + +int p11_test_run (int argc, + char **argv); + +#endif /* P11_TEST_H_ */ diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am index 6959c4f..942bc12 100644 --- a/common/tests/Makefile.am +++ b/common/tests/Makefile.am @@ -3,11 +3,11 @@ include $(top_srcdir)/build/Makefile.tests COMMON = $(top_srcdir)/common -INCLUDES = \ +AM_CPPFLAGS = \ -I$(top_srcdir) \ -I$(srcdir)/.. \ -I$(COMMON) \ - $(CUTEST_CFLAGS) + $(TEST_CFLAGS) LDADD = \ $(NULL) @@ -34,7 +34,7 @@ LDADD += \ $(LIBTASN1_LIBS) \ $(NULL) -INCLUDES += \ +AM_CPPFLAGS += \ $(LIBTASN1_CFLAGS) \ $(NULL) @@ -61,5 +61,6 @@ endif # WITH_ASN1 TESTS = $(CHECK_PROGS) LDADD += \ + $(top_builddir)/common/libp11-test.la \ $(top_builddir)/common/libp11-common.la \ $(CUTEST_LIBS) diff --git a/common/tests/test-array.c b/common/tests/test-array.c index a796365..8e8f996 100644 --- a/common/tests/test-array.c +++ b/common/tests/test-array.c @@ -33,26 +33,26 @@ */ #include "config.h" -#include "CuTest.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include "array.h" +#include "test.h" static void -test_p11_array_create (CuTest *tc) +test_create (void) { p11_array *array; array = p11_array_new (NULL); - CuAssertPtrNotNull (tc, array); + assert_ptr_not_null (array); p11_array_free (array); } static void -test_p11_array_free_null (CuTest *tc) +test_free_null (void) { p11_array_free (NULL); } @@ -65,81 +65,81 @@ destroy_value (void *data) } static void -test_p11_array_free_destroys (CuTest *tc) +test_free_destroys (void) { p11_array *array; int value = 0; array = p11_array_new (destroy_value); - CuAssertPtrNotNull (tc, array); + assert_ptr_not_null (array); if (!p11_array_push (array, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_array_free (array); - CuAssertIntEquals (tc, 2, value); + assert_num_eq (2, value); } static void -test_p11_array_add (CuTest *tc) +test_add (void) { char *value = "VALUE"; p11_array *array; array = p11_array_new (NULL); if (!p11_array_push (array, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); - CuAssertIntEquals (tc, 1, array->num); - CuAssertPtrEquals (tc, array->elem[0], value); + assert_num_eq (1, array->num); + assert_ptr_eq (array->elem[0], value); p11_array_free (array); } static void -test_p11_array_add_remove (CuTest *tc) +test_add_remove (void) { char *value = "VALUE"; p11_array *array; array = p11_array_new (NULL); if (!p11_array_push (array, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); - CuAssertIntEquals (tc, 1, array->num); + assert_num_eq (1, array->num); - CuAssertPtrEquals (tc, array->elem[0], value); + assert_ptr_eq (array->elem[0], value); p11_array_remove (array, 0); - CuAssertIntEquals (tc, 0, array->num); + assert_num_eq (0, array->num); p11_array_free (array); } static void -test_p11_array_remove_destroys (CuTest *tc) +test_remove_destroys (void) { p11_array *array; int value = 0; array = p11_array_new (destroy_value); if (!p11_array_push (array, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_array_remove (array, 0); - CuAssertIntEquals (tc, 2, value); + assert_num_eq (2, value); /* should not be destroyed again */ value = 0; p11_array_free (array); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (0, value); } static void -test_p11_array_remove_and_count (CuTest *tc) +test_remove_and_count (void) { p11_array *array; int *value; @@ -147,75 +147,62 @@ test_p11_array_remove_and_count (CuTest *tc) array = p11_array_new (free); - CuAssertIntEquals (tc, 0, array->num); + assert_num_eq (0, array->num); for (i = 0; i < 20000; ++i) { value = malloc (sizeof (int)); *value = i; if (!p11_array_push (array, value)) - CuFail (tc, "should not be reached"); - CuAssertIntEquals (tc, i + 1, array->num); + assert_not_reached (); + assert_num_eq (i + 1, array->num); } for (i = 10; i < 20000; ++i) { p11_array_remove (array, 10); - CuAssertIntEquals (tc, 20010 - (i + 1), array->num); + assert_num_eq (20010 - (i + 1), array->num); } - CuAssertIntEquals (tc, 10, array->num); + assert_num_eq (10, array->num); p11_array_free (array); } static void -test_p11_array_clear_destroys (CuTest *tc) +test_clear_destroys (void) { p11_array *array; int value = 0; array = p11_array_new (destroy_value); if (!p11_array_push (array, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); - CuAssertIntEquals (tc, 1, array->num); + assert_num_eq (1, array->num); p11_array_clear (array); - CuAssertIntEquals (tc, 2, value); - CuAssertIntEquals (tc, 0, array->num); + assert_num_eq (2, value); + assert_num_eq (0, array->num); /* should not be destroyed again */ value = 0; p11_array_free (array); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (0, value); } - int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_p11_array_create); - SUITE_ADD_TEST (suite, test_p11_array_add); - SUITE_ADD_TEST (suite, test_p11_array_add_remove); - SUITE_ADD_TEST (suite, test_p11_array_remove_destroys); - SUITE_ADD_TEST (suite, test_p11_array_remove_and_count); - SUITE_ADD_TEST (suite, test_p11_array_free_null); - SUITE_ADD_TEST (suite, test_p11_array_free_destroys); - SUITE_ADD_TEST (suite, test_p11_array_clear_destroys); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_create, "/array/create"); + p11_test (test_add, "/array/add"); + p11_test (test_add_remove, "/array/add-remove"); + p11_test (test_remove_destroys, "/array/remove-destroys"); + p11_test (test_remove_and_count, "/array/remove-and-count"); + p11_test (test_free_null, "/array/free-null"); + p11_test (test_free_destroys, "/array/free-destroys"); + p11_test (test_clear_destroys, "/array/clear-destroys"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-asn1.c b/common/tests/test-asn1.c index 0335fa6..710928c 100644 --- a/common/tests/test-asn1.c +++ b/common/tests/test-asn1.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include "asn1.h" #include "debug.h" @@ -49,21 +49,21 @@ struct { } test; static void -setup (CuTest *cu) +setup (void *unused) { test.asn1_defs = p11_asn1_defs_load (); - CuAssertPtrNotNull (cu, test.asn1_defs); + assert_ptr_not_null (test.asn1_defs); } static void -teardown (CuTest *cu) +teardown (void *unused) { p11_dict_free (test.asn1_defs); memset (&test, 0, sizeof (test)); } static void -test_tlv_length (CuTest *cu) +test_tlv_length (void) { struct { const char *der; @@ -79,14 +79,10 @@ test_tlv_length (CuTest *cu) int length; int i; - setup (cu); - for (i = 0; tlv_lengths[i].der != NULL; i++) { length = p11_asn1_tlv_length ((const unsigned char *)tlv_lengths[i].der, tlv_lengths[i].der_len); - CuAssertIntEquals (cu, tlv_lengths[i].expected, length); + assert_num_eq (tlv_lengths[i].expected, length); } - - teardown (cu); } static const unsigned char test_eku_server_and_client[] = { @@ -95,7 +91,7 @@ static const unsigned char test_eku_server_and_client[] = { }; static void -test_asn1_cache (CuTest *cu) +test_asn1_cache (void) { p11_asn1_cache *cache; p11_dict *defs; @@ -103,15 +99,15 @@ test_asn1_cache (CuTest *cu) node_asn *check; cache = p11_asn1_cache_new (); - CuAssertPtrNotNull (cu, cache); + assert_ptr_not_null (cache); defs = p11_asn1_cache_defs (cache); - CuAssertPtrNotNull (cu, defs); + assert_ptr_not_null (defs); asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax", test_eku_server_and_client, sizeof (test_eku_server_and_client), NULL); - CuAssertPtrNotNull (cu, defs); + assert_ptr_not_null (defs); /* Place the parsed data in the cache */ p11_asn1_cache_take (cache, asn, "PKIX1.ExtKeyUsageSyntax", @@ -122,38 +118,27 @@ test_asn1_cache (CuTest *cu) check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax", test_eku_server_and_client, sizeof (test_eku_server_and_client)); - CuAssertPtrEquals (cu, asn, check); + assert_ptr_eq (asn, check); /* Flush should remove it */ p11_asn1_cache_flush (cache); check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax", test_eku_server_and_client, sizeof (test_eku_server_and_client)); - CuAssertPtrEquals (cu, NULL, check); + assert_ptr_eq (NULL, check); p11_asn1_cache_free (cache); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_tlv_length); - SUITE_ADD_TEST (suite, test_asn1_cache); + p11_fixture (setup, teardown); + p11_test (test_tlv_length, "/asn1/tlv_length"); - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); + p11_fixture (NULL, NULL); + p11_test (test_asn1_cache, "/asn1/asn1_cache"); - return ret; + return p11_test_run (argc, argv); } diff --git a/common/tests/test-attrs.c b/common/tests/test-attrs.c index 324ed90..6087191 100644 --- a/common/tests/test-attrs.c +++ b/common/tests/test-attrs.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -43,7 +43,7 @@ #include "debug.h" static void -test_terminator (CuTest *tc) +test_terminator (void) { CK_ATTRIBUTE attrs[] = { { CKA_LABEL, "label", 5 }, @@ -51,14 +51,14 @@ test_terminator (CuTest *tc) { CKA_INVALID }, }; - CuAssertIntEquals (tc, true, p11_attrs_terminator (attrs + 2)); - CuAssertIntEquals (tc, true, p11_attrs_terminator (NULL)); - CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs)); - CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs + 1)); + assert_num_eq (true, p11_attrs_terminator (attrs + 2)); + assert_num_eq (true, p11_attrs_terminator (NULL)); + assert_num_eq (false, p11_attrs_terminator (attrs)); + assert_num_eq (false, p11_attrs_terminator (attrs + 1)); } static void -test_count (CuTest *tc) +test_count (void) { CK_BBOOL vtrue = CK_TRUE; @@ -72,13 +72,13 @@ test_count (CuTest *tc) { CKA_INVALID }, }; - CuAssertIntEquals (tc, 2, p11_attrs_count (attrs)); - CuAssertIntEquals (tc, 0, p11_attrs_count (NULL)); - CuAssertIntEquals (tc, 0, p11_attrs_count (empty)); + assert_num_eq (2, p11_attrs_count (attrs)); + assert_num_eq (0, p11_attrs_count (NULL)); + assert_num_eq (0, p11_attrs_count (empty)); } static void -test_build_one (CuTest *tc) +test_build_one (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE add = { CKA_LABEL, "yay", 3 }; @@ -86,18 +86,18 @@ test_build_one (CuTest *tc) attrs = p11_attrs_build (NULL, &add, NULL); /* Test the first attribute */ - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs->type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs->ulValueLen); - CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs->type == CKA_LABEL); + assert_num_eq (3, attrs->ulValueLen); + assert (memcmp (attrs->pValue, "yay", 3) == 0); - CuAssertTrue (tc, attrs[1].type == CKA_INVALID); + assert (attrs[1].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_build_two (CuTest *tc) +test_build_two (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 }; @@ -105,23 +105,23 @@ test_build_two (CuTest *tc) attrs = p11_attrs_build (NULL, &one, &two, NULL); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (3, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "yay", 3) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 5, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (5, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "eight", 5) == 0); - CuAssertTrue (tc, attrs[2].type == CKA_INVALID); + assert (attrs[2].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_build_invalid (CuTest *tc) +test_build_invalid (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 }; @@ -130,23 +130,23 @@ test_build_invalid (CuTest *tc) attrs = p11_attrs_build (NULL, &one, &invalid, &two, NULL); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (3, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "yay", 3) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 5, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (5, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "eight", 5) == 0); - CuAssertTrue (tc, attrs[2].type == CKA_INVALID); + assert (attrs[2].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_buildn_two (CuTest *tc) +test_buildn_two (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE add[] = { @@ -157,23 +157,23 @@ test_buildn_two (CuTest *tc) attrs = p11_attrs_buildn (NULL, add, 2); /* Test the first attribute */ - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs->type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs->ulValueLen); - CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs->type == CKA_LABEL); + assert_num_eq (3, attrs->ulValueLen); + assert (memcmp (attrs->pValue, "yay", 3) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 5, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (5, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "eight", 5) == 0); - CuAssertTrue (tc, attrs[2].type == CKA_INVALID); + assert (attrs[2].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_buildn_one (CuTest *tc) +test_buildn_one (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE add = { CKA_LABEL, "yay", 3 }; @@ -181,18 +181,18 @@ test_buildn_one (CuTest *tc) attrs = p11_attrs_buildn (NULL, &add, 1); /* Test the first attribute */ - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs->type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs->ulValueLen); - CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs->type == CKA_LABEL); + assert_num_eq (3, attrs->ulValueLen); + assert (memcmp (attrs->pValue, "yay", 3) == 0); - CuAssertTrue (tc, attrs[1].type == CKA_INVALID); + assert (attrs[1].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_build_add (CuTest *tc) +test_build_add (void) { CK_ATTRIBUTE initial[] = { { CKA_LABEL, "label", 5 }, @@ -206,28 +206,28 @@ test_build_add (CuTest *tc) attrs = p11_attrs_buildn (NULL, initial, 2); attrs = p11_attrs_build (attrs, &one, &two, NULL); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (3, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "yay", 3) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 4, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (4, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "nine", 4) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[2].type == CKA_TOKEN); - CuAssertIntEquals (tc, 1, attrs[2].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[2].pValue, "\x01", 1) == 0); + assert_ptr_not_null (attrs); + assert (attrs[2].type == CKA_TOKEN); + assert_num_eq (1, attrs[2].ulValueLen); + assert (memcmp (attrs[2].pValue, "\x01", 1) == 0); - CuAssertTrue (tc, attrs[3].type == CKA_INVALID); + assert (attrs[3].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_build_null (CuTest *tc) +test_build_null (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE add = { CKA_LABEL, NULL, (CK_ULONG)-1 }; @@ -235,16 +235,16 @@ test_build_null (CuTest *tc) attrs = p11_attrs_build (NULL, &add, NULL); /* Test the first attribute */ - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs->type == CKA_LABEL); - CuAssertTrue (tc, attrs->ulValueLen == (CK_ULONG)-1); - CuAssertPtrEquals (tc, NULL, attrs->pValue); + assert_ptr_not_null (attrs); + assert (attrs->type == CKA_LABEL); + assert (attrs->ulValueLen == (CK_ULONG)-1); + assert_ptr_eq (NULL, attrs->pValue); p11_attrs_free (attrs); } static void -test_dup (CuTest *tc) +test_dup (void) { CK_ATTRIBUTE *attrs; CK_ATTRIBUTE original[] = { @@ -256,23 +256,23 @@ test_dup (CuTest *tc) attrs = p11_attrs_dup (original); /* Test the first attribute */ - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs->type == CKA_LABEL); - CuAssertIntEquals (tc, 3, attrs->ulValueLen); - CuAssertTrue (tc, memcmp (attrs->pValue, "yay", 3) == 0); + assert_ptr_not_null (attrs); + assert (attrs->type == CKA_LABEL); + assert_num_eq (3, attrs->ulValueLen); + assert (memcmp (attrs->pValue, "yay", 3) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 5, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "eight", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (5, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "eight", 5) == 0); - CuAssertTrue (tc, attrs[2].type == CKA_INVALID); + assert (attrs[2].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_take (CuTest *tc) +test_take (void) { CK_ATTRIBUTE initial[] = { { CKA_LABEL, "label", 5 }, @@ -284,30 +284,30 @@ test_take (CuTest *tc) attrs = p11_attrs_buildn (NULL, initial, 2); attrs = p11_attrs_take (attrs, CKA_LABEL, strdup ("boooyah"), 7); attrs = p11_attrs_take (attrs, CKA_TOKEN, strdup ("\x01"), 1); - CuAssertPtrNotNull (tc, attrs); + assert_ptr_not_null (attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 7, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "boooyah", 7) == 0); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (7, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "boooyah", 7) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 4, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (4, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "nine", 4) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[2].type == CKA_TOKEN); - CuAssertIntEquals (tc, 1, attrs[2].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[2].pValue, "\x01", 1) == 0); + assert_ptr_not_null (attrs); + assert (attrs[2].type == CKA_TOKEN); + assert_num_eq (1, attrs[2].ulValueLen); + assert (memcmp (attrs[2].pValue, "\x01", 1) == 0); - CuAssertTrue (tc, attrs[3].type == CKA_INVALID); + assert (attrs[3].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_merge_replace (CuTest *tc) +test_merge_replace (void) { CK_ATTRIBUTE initial[] = { { CKA_LABEL, "label", 5 }, @@ -325,29 +325,29 @@ test_merge_replace (CuTest *tc) attrs = p11_attrs_buildn (NULL, initial, 2); merge = p11_attrs_buildn (NULL, extra, 2); attrs = p11_attrs_merge (attrs, merge, true); - CuAssertPtrNotNull (tc, attrs); + assert_ptr_not_null (attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 7, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "boooyah", 7) == 0); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (7, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "boooyah", 7) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 4, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (4, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "nine", 4) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[2].type == CKA_APPLICATION); - CuAssertIntEquals (tc, 5, attrs[2].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[2].pValue, "disco", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[2].type == CKA_APPLICATION); + assert_num_eq (5, attrs[2].ulValueLen); + assert (memcmp (attrs[2].pValue, "disco", 5) == 0); - CuAssertTrue (tc, attrs[3].type == CKA_INVALID); + assert (attrs[3].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_merge_empty (CuTest *tc) +test_merge_empty (void) { CK_ATTRIBUTE extra[] = { { CKA_LABEL, "boooyah", 7 }, @@ -359,14 +359,14 @@ test_merge_empty (CuTest *tc) merge = p11_attrs_buildn (NULL, extra, 2); attrs = p11_attrs_merge (attrs, merge, true); - CuAssertPtrNotNull (tc, attrs); - CuAssertPtrEquals (tc, merge, attrs); + assert_ptr_not_null (attrs); + assert_ptr_eq (merge, attrs); p11_attrs_free (attrs); } static void -test_merge_augment (CuTest *tc) +test_merge_augment (void) { CK_ATTRIBUTE initial[] = { { CKA_LABEL, "label", 5 }, @@ -384,35 +384,35 @@ test_merge_augment (CuTest *tc) attrs = p11_attrs_buildn (NULL, initial, 2); merge = p11_attrs_buildn (NULL, extra, 2); attrs = p11_attrs_merge (attrs, merge, false); - CuAssertPtrNotNull (tc, attrs); + assert_ptr_not_null (attrs); - CuAssertTrue (tc, attrs[0].type == CKA_LABEL); - CuAssertIntEquals (tc, 5, attrs[0].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[0].pValue, "label", 5) == 0); + assert (attrs[0].type == CKA_LABEL); + assert_num_eq (5, attrs[0].ulValueLen); + assert (memcmp (attrs[0].pValue, "label", 5) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[1].type == CKA_VALUE); - CuAssertIntEquals (tc, 4, attrs[1].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[1].pValue, "nine", 4) == 0); + assert_ptr_not_null (attrs); + assert (attrs[1].type == CKA_VALUE); + assert_num_eq (4, attrs[1].ulValueLen); + assert (memcmp (attrs[1].pValue, "nine", 4) == 0); - CuAssertPtrNotNull (tc, attrs); - CuAssertTrue (tc, attrs[2].type == CKA_APPLICATION); - CuAssertIntEquals (tc, 5, attrs[2].ulValueLen); - CuAssertTrue (tc, memcmp (attrs[2].pValue, "disco", 5) == 0); + assert_ptr_not_null (attrs); + assert (attrs[2].type == CKA_APPLICATION); + assert_num_eq (5, attrs[2].ulValueLen); + assert (memcmp (attrs[2].pValue, "disco", 5) == 0); - CuAssertTrue (tc, attrs[3].type == CKA_INVALID); + assert (attrs[3].type == CKA_INVALID); p11_attrs_free (attrs); } static void -test_free_null (CuTest *tc) +test_free_null (void) { p11_attrs_free (NULL); } static void -test_equal (CuTest *tc) +test_equal (void) { char *data = "extra attribute"; CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 }; @@ -422,19 +422,19 @@ test_equal (CuTest *tc) CK_ATTRIBUTE overflow = { CKA_VALUE, data, 5 }; CK_ATTRIBUTE content = { CKA_VALUE, "conte", 5 }; - CuAssertTrue (tc, p11_attr_equal (&one, &one)); - CuAssertTrue (tc, !p11_attr_equal (&one, NULL)); - CuAssertTrue (tc, !p11_attr_equal (NULL, &one)); - CuAssertTrue (tc, !p11_attr_equal (&one, &two)); - CuAssertTrue (tc, !p11_attr_equal (&two, &other)); - CuAssertTrue (tc, p11_attr_equal (&other, &overflow)); - CuAssertTrue (tc, !p11_attr_equal (&one, &null)); - CuAssertTrue (tc, !p11_attr_equal (&one, &null)); - CuAssertTrue (tc, !p11_attr_equal (&other, &content)); + assert (p11_attr_equal (&one, &one)); + assert (!p11_attr_equal (&one, NULL)); + assert (!p11_attr_equal (NULL, &one)); + assert (!p11_attr_equal (&one, &two)); + assert (!p11_attr_equal (&two, &other)); + assert (p11_attr_equal (&other, &overflow)); + assert (!p11_attr_equal (&one, &null)); + assert (!p11_attr_equal (&one, &null)); + assert (!p11_attr_equal (&other, &content)); } static void -test_hash (CuTest *tc) +test_hash (void) { char *data = "extra attribute"; CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 }; @@ -446,18 +446,18 @@ test_hash (CuTest *tc) unsigned int hash; hash = p11_attr_hash (&one); - CuAssertTrue (tc, hash != 0); - - CuAssertTrue (tc, p11_attr_hash (&one) == hash); - CuAssertTrue (tc, p11_attr_hash (&two) != hash); - CuAssertTrue (tc, p11_attr_hash (&other) != hash); - CuAssertTrue (tc, p11_attr_hash (&overflow) != hash); - CuAssertTrue (tc, p11_attr_hash (&null) != hash); - CuAssertTrue (tc, p11_attr_hash (&content) != hash); + assert (hash != 0); + + assert (p11_attr_hash (&one) == hash); + assert (p11_attr_hash (&two) != hash); + assert (p11_attr_hash (&other) != hash); + assert (p11_attr_hash (&overflow) != hash); + assert (p11_attr_hash (&null) != hash); + assert (p11_attr_hash (&content) != hash); } static void -test_to_string (CuTest *tc) +test_to_string (void) { char *data = "extra attribute"; CK_ATTRIBUTE one = { CKA_LABEL, "yay", 3 }; @@ -471,20 +471,20 @@ test_to_string (CuTest *tc) string = p11_attr_to_string (&one, CKA_INVALID); - CuAssertStrEquals (tc, "{ CKA_LABEL = (3) \"yay\" }", string); + assert_str_eq ("{ CKA_LABEL = (3) \"yay\" }", string); free (string); string = p11_attrs_to_string (attrs, -1); - CuAssertStrEquals (tc, "(2) [ { CKA_LABEL = (3) \"yay\" }, { CKA_VALUE = (5) NOT-PRINTED } ]", string); + assert_str_eq ("(2) [ { CKA_LABEL = (3) \"yay\" }, { CKA_VALUE = (5) NOT-PRINTED } ]", string); free (string); string = p11_attrs_to_string (attrs, 1); - CuAssertStrEquals (tc, "(1) [ { CKA_LABEL = (3) \"yay\" } ]", string); + assert_str_eq ("(1) [ { CKA_LABEL = (3) \"yay\" } ]", string); free (string); } static void -test_find (CuTest *tc) +test_find (void) { CK_BBOOL vtrue = CK_TRUE; CK_ATTRIBUTE *attr; @@ -496,17 +496,17 @@ test_find (CuTest *tc) }; attr = p11_attrs_find (attrs, CKA_LABEL); - CuAssertPtrEquals (tc, attrs + 0, attr); + assert_ptr_eq (attrs + 0, attr); attr = p11_attrs_find (attrs, CKA_TOKEN); - CuAssertPtrEquals (tc, attrs + 1, attr); + assert_ptr_eq (attrs + 1, attr); attr = p11_attrs_find (attrs, CKA_VALUE); - CuAssertPtrEquals (tc, NULL, attr); + assert_ptr_eq (NULL, attr); } static void -test_findn (CuTest *tc) +test_findn (void) { CK_BBOOL vtrue = CK_TRUE; CK_ATTRIBUTE *attr; @@ -517,20 +517,20 @@ test_findn (CuTest *tc) }; attr = p11_attrs_findn (attrs, 2, CKA_LABEL); - CuAssertPtrEquals (tc, attrs + 0, attr); + assert_ptr_eq (attrs + 0, attr); attr = p11_attrs_findn (attrs, 2, CKA_TOKEN); - CuAssertPtrEquals (tc, attrs + 1, attr); + assert_ptr_eq (attrs + 1, attr); attr = p11_attrs_findn (attrs, 2, CKA_VALUE); - CuAssertPtrEquals (tc, NULL, attr); + assert_ptr_eq (NULL, attr); attr = p11_attrs_findn (attrs, 1, CKA_TOKEN); - CuAssertPtrEquals (tc, NULL, attr); + assert_ptr_eq (NULL, attr); } static void -test_remove (CuTest *tc) +test_remove (void) { CK_BBOOL vtrue = CK_TRUE; CK_ATTRIBUTE *attr; @@ -543,25 +543,25 @@ test_remove (CuTest *tc) }; attrs = p11_attrs_buildn (NULL, initial, 2); - CuAssertPtrNotNull (tc, attrs); + assert_ptr_not_null (attrs); attr = p11_attrs_find (attrs, CKA_LABEL); - CuAssertPtrEquals (tc, attrs + 0, attr); + assert_ptr_eq (attrs + 0, attr); ret = p11_attrs_remove (attrs, CKA_LABEL); - CuAssertIntEquals (tc, CK_TRUE, ret); + assert_num_eq (CK_TRUE, ret); attr = p11_attrs_find (attrs, CKA_LABEL); - CuAssertPtrEquals (tc, NULL, attr); + assert_ptr_eq (NULL, attr); ret = p11_attrs_remove (attrs, CKA_LABEL); - CuAssertIntEquals (tc, CK_FALSE, ret); + assert_num_eq (CK_FALSE, ret); p11_attrs_free (attrs); } static void -test_match (CuTest *tc) +test_match (void) { CK_BBOOL vtrue = CK_TRUE; @@ -588,14 +588,14 @@ test_match (CuTest *tc) { CKA_INVALID }, }; - CuAssertTrue (tc, p11_attrs_match (attrs, attrs)); - CuAssertTrue (tc, p11_attrs_match (attrs, subset)); - CuAssertTrue (tc, !p11_attrs_match (attrs, different)); - CuAssertTrue (tc, !p11_attrs_match (attrs, extra)); + assert (p11_attrs_match (attrs, attrs)); + assert (p11_attrs_match (attrs, subset)); + assert (!p11_attrs_match (attrs, different)); + assert (!p11_attrs_match (attrs, extra)); } static void -test_matchn (CuTest *tc) +test_matchn (void) { CK_BBOOL vtrue = CK_TRUE; @@ -620,13 +620,13 @@ test_matchn (CuTest *tc) { CKA_TOKEN, &vtrue, sizeof (vtrue) }, }; - CuAssertTrue (tc, p11_attrs_matchn (attrs, subset, 1)); - CuAssertTrue (tc, !p11_attrs_matchn (attrs, different, 2)); - CuAssertTrue (tc, !p11_attrs_matchn (attrs, extra, 3)); + assert (p11_attrs_matchn (attrs, subset, 1)); + assert (!p11_attrs_matchn (attrs, different, 2)); + assert (!p11_attrs_matchn (attrs, extra, 3)); } static void -test_find_bool (CuTest *tc) +test_find_bool (void) { CK_BBOOL vtrue = CK_TRUE; CK_BBOOL vfalse = CK_FALSE; @@ -640,13 +640,13 @@ test_find_bool (CuTest *tc) { CKA_INVALID }, }; - CuAssertTrue (tc, p11_attrs_find_bool (attrs, CKA_TOKEN, &value) && value == CK_TRUE); - CuAssertTrue (tc, !p11_attrs_find_bool (attrs, CKA_LABEL, &value)); - CuAssertTrue (tc, !p11_attrs_find_bool (attrs, CKA_VALUE, &value)); + assert (p11_attrs_find_bool (attrs, CKA_TOKEN, &value) && value == CK_TRUE); + assert (!p11_attrs_find_bool (attrs, CKA_LABEL, &value)); + assert (!p11_attrs_find_bool (attrs, CKA_VALUE, &value)); } static void -test_find_ulong (CuTest *tc) +test_find_ulong (void) { CK_ULONG v33 = 33UL; CK_ULONG v45 = 45UL; @@ -660,13 +660,13 @@ test_find_ulong (CuTest *tc) { CKA_INVALID }, }; - CuAssertTrue (tc, p11_attrs_find_ulong (attrs, CKA_BITS_PER_PIXEL, &value) && value == v33); - CuAssertTrue (tc, !p11_attrs_find_ulong (attrs, CKA_LABEL, &value)); - CuAssertTrue (tc, !p11_attrs_find_ulong (attrs, CKA_VALUE, &value)); + assert (p11_attrs_find_ulong (attrs, CKA_BITS_PER_PIXEL, &value) && value == v33); + assert (!p11_attrs_find_ulong (attrs, CKA_LABEL, &value)); + assert (!p11_attrs_find_ulong (attrs, CKA_VALUE, &value)); } static void -test_find_value (CuTest *tc) +test_find_value (void) { void *value; size_t length; @@ -681,21 +681,21 @@ test_find_value (CuTest *tc) }; value = p11_attrs_find_value (attrs, CKA_LABEL, &length); - CuAssertPtrEquals (tc, attrs[3].pValue, value); - CuAssertIntEquals (tc, 4, length); + assert_ptr_eq (attrs[3].pValue, value); + assert_num_eq (4, length); value = p11_attrs_find_value (attrs, CKA_LABEL, NULL); - CuAssertPtrEquals (tc, attrs[3].pValue, value); + assert_ptr_eq (attrs[3].pValue, value); value = p11_attrs_find_value (attrs, CKA_VALUE, &length); - CuAssertPtrEquals (tc, NULL, value); + assert_ptr_eq (NULL, value); value = p11_attrs_find_value (attrs, CKA_TOKEN, &length); - CuAssertPtrEquals (tc, NULL, value); + assert_ptr_eq (NULL, value); } static void -test_find_valid (CuTest *tc) +test_find_valid (void) { CK_ATTRIBUTE *attr; @@ -709,61 +709,46 @@ test_find_valid (CuTest *tc) }; attr = p11_attrs_find_valid (attrs, CKA_LABEL); - CuAssertPtrEquals (tc, attrs + 3, attr); + assert_ptr_eq (attrs + 3, attr); attr = p11_attrs_find_valid (attrs, CKA_VALUE); - CuAssertPtrEquals (tc, attrs + 4, attr); + assert_ptr_eq (attrs + 4, attr); attr = p11_attrs_find_valid (attrs, CKA_TOKEN); - CuAssertPtrEquals (tc, NULL, attr); + assert_ptr_eq (NULL, attr); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_equal); - SUITE_ADD_TEST (suite, test_hash); - SUITE_ADD_TEST (suite, test_to_string); - - SUITE_ADD_TEST (suite, test_terminator); - SUITE_ADD_TEST (suite, test_count); - SUITE_ADD_TEST (suite, test_build_one); - SUITE_ADD_TEST (suite, test_build_two); - SUITE_ADD_TEST (suite, test_build_invalid); - SUITE_ADD_TEST (suite, test_buildn_one); - SUITE_ADD_TEST (suite, test_buildn_two); - SUITE_ADD_TEST (suite, test_build_add); - SUITE_ADD_TEST (suite, test_build_null); - SUITE_ADD_TEST (suite, test_dup); - SUITE_ADD_TEST (suite, test_take); - SUITE_ADD_TEST (suite, test_merge_replace); - SUITE_ADD_TEST (suite, test_merge_augment); - SUITE_ADD_TEST (suite, test_merge_empty); - SUITE_ADD_TEST (suite, test_free_null); - SUITE_ADD_TEST (suite, test_match); - SUITE_ADD_TEST (suite, test_matchn); - SUITE_ADD_TEST (suite, test_find); - SUITE_ADD_TEST (suite, test_findn); - SUITE_ADD_TEST (suite, test_find_bool); - SUITE_ADD_TEST (suite, test_find_ulong); - SUITE_ADD_TEST (suite, test_find_value); - SUITE_ADD_TEST (suite, test_find_valid); - SUITE_ADD_TEST (suite, test_remove); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_equal, "/attrs/equal"); + p11_test (test_hash, "/attrs/hash"); + p11_test (test_to_string, "/attrs/to-string"); + + p11_test (test_terminator, "/attrs/terminator"); + p11_test (test_count, "/attrs/count"); + p11_test (test_build_one, "/attrs/build-one"); + p11_test (test_build_two, "/attrs/build-two"); + p11_test (test_build_invalid, "/attrs/build-invalid"); + p11_test (test_buildn_one, "/attrs/buildn-one"); + p11_test (test_buildn_two, "/attrs/buildn-two"); + p11_test (test_build_add, "/attrs/build-add"); + p11_test (test_build_null, "/attrs/build-null"); + p11_test (test_dup, "/attrs/dup"); + p11_test (test_take, "/attrs/take"); + p11_test (test_merge_replace, "/attrs/merge-replace"); + p11_test (test_merge_augment, "/attrs/merge-augment"); + p11_test (test_merge_empty, "/attrs/merge-empty"); + p11_test (test_free_null, "/attrs/free-null"); + p11_test (test_match, "/attrs/match"); + p11_test (test_matchn, "/attrs/matchn"); + p11_test (test_find, "/attrs/find"); + p11_test (test_findn, "/attrs/findn"); + p11_test (test_find_bool, "/attrs/find-bool"); + p11_test (test_find_ulong, "/attrs/find-ulong"); + p11_test (test_find_value, "/attrs/find-value"); + p11_test (test_find_valid, "/attrs/find-valid"); + p11_test (test_remove, "/attrs/remove"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-base64.c b/common/tests/test-base64.c index 90c1f49..ce303e8 100644 --- a/common/tests/test-base64.c +++ b/common/tests/test-base64.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include "base64.h" #include "debug.h" @@ -45,9 +45,9 @@ #include <stdlib.h> static void -check_decode_msg (CuTest *tc, - const char *file, +check_decode_msg (const char *file, int line, + const char *function, const char *input, ssize_t input_len, const unsigned char *expected, @@ -63,33 +63,38 @@ check_decode_msg (CuTest *tc, length = p11_b64_pton (input, input_len, decoded, sizeof (decoded)); if (expected == NULL) { - CuAssert_Line (tc, file, line, "decoding should have failed", length < 0); + if (length >= 0) + p11_test_fail (file, line, function, "decoding should have failed"); } else { - CuAssert_Line (tc, file, line, "decoding failed", length >= 0); - CuAssertIntEquals_LineMsg (tc, file, line, "wrong length", expected_len, length); - CuAssert_Line (tc, file, line, "decoded wrong", memcmp (decoded, expected, length) == 0); + if (length < 0) + p11_test_fail (file, line, function, "decoding failed"); + if (expected_len != length) + p11_test_fail (file, line, function, "wrong length: (%lu != %lu)", + (unsigned long)expected_len, (unsigned long)length); + if (memcmp (decoded, expected, length) != 0) + p11_test_fail (file, line, function, "decoded wrong"); } } -#define check_decode_success(tc, input, input_len, expected, expected_len) \ - check_decode_msg (tc, __FILE__, __LINE__, input, input_len, expected, expected_len) +#define check_decode_success(input, input_len, expected, expected_len) \ + check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, expected, expected_len) -#define check_decode_failure(tc, input, input_len) \ - check_decode_msg (tc, __FILE__, __LINE__, input, input_len, NULL, 0) +#define check_decode_failure(input, input_len) \ + check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, NULL, 0) static void -test_decode_simple (CuTest *tc) +test_decode_simple (void) { - check_decode_success (tc, "", 0, (unsigned char *)"", 0); - check_decode_success (tc, "MQ==", 0, (unsigned char *)"1", 0); - check_decode_success (tc, "YmxhaAo=", -1, (unsigned char *)"blah\n", -1); - check_decode_success (tc, "bGVlbGEK", -1, (unsigned char *)"leela\n", -1); - check_decode_success (tc, "bGVlbG9vCg==", -1, (unsigned char *)"leeloo\n", -1); + check_decode_success ("", 0, (unsigned char *)"", 0); + check_decode_success ("MQ==", 0, (unsigned char *)"1", 0); + check_decode_success ("YmxhaAo=", -1, (unsigned char *)"blah\n", -1); + check_decode_success ("bGVlbGEK", -1, (unsigned char *)"leela\n", -1); + check_decode_success ("bGVlbG9vCg==", -1, (unsigned char *)"leeloo\n", -1); } static void -test_decode_thawte (CuTest *tc) +test_decode_thawte (void) { const char *input = "MIIEKjCCAxKgAwIBAgIQYAGXt0an6rS0mtZLL/eQ+zANBgkqhkiG9w0BAQsFADCB" @@ -186,28 +191,14 @@ test_decode_thawte (CuTest *tc) 0x31, 0xd4, 0x40, 0x1a, 0x62, 0x34, 0x36, 0x3f, 0x35, 0x01, 0xae, 0xac, 0x63, 0xa0, }; - check_decode_success (tc, input, -1, output, sizeof (output)); + check_decode_success (input, -1, output, sizeof (output)); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_decode_simple); - SUITE_ADD_TEST (suite, test_decode_thawte); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - return ret; + p11_test (test_decode_simple, "/base64/decode-simple"); + p11_test (test_decode_thawte, "/base64/decode-thawte"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-buffer.c b/common/tests/test-buffer.c index baf7b73..4fd060d 100644 --- a/common/tests/test-buffer.c +++ b/common/tests/test-buffer.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -43,41 +43,41 @@ #include "buffer.h" static void -test_init_uninit (CuTest *tc) +test_init_uninit (void) { p11_buffer buffer; p11_buffer_init (&buffer, 10); - CuAssertPtrNotNull (tc, buffer.data); - CuAssertIntEquals (tc, 0, buffer.len); - CuAssertIntEquals (tc, 0, buffer.flags); - CuAssertTrue (tc, buffer.size >= 10); - CuAssertPtrNotNull (tc, buffer.ffree); - CuAssertPtrNotNull (tc, buffer.frealloc); + assert_ptr_not_null (buffer.data); + assert_num_eq (0, buffer.len); + assert_num_eq (0, buffer.flags); + assert (buffer.size >= 10); + assert_ptr_not_null (buffer.ffree); + assert_ptr_not_null (buffer.frealloc); p11_buffer_uninit (&buffer); } static void -test_append (CuTest *tc) +test_append (void) { p11_buffer buffer; p11_buffer_init (&buffer, 10); buffer.len = 5; p11_buffer_append (&buffer, 35); - CuAssertIntEquals (tc, 5 + 35, buffer.len); - CuAssertTrue (tc, buffer.size >= 35 + 5); + assert_num_eq (5 + 35, buffer.len); + assert (buffer.size >= 35 + 5); p11_buffer_append (&buffer, 15); - CuAssertIntEquals (tc, 5 + 35 + 15, buffer.len); - CuAssertTrue (tc, buffer.size >= 5 + 35 + 15); + assert_num_eq (5 + 35 + 15, buffer.len); + assert (buffer.size >= 5 + 35 + 15); p11_buffer_uninit (&buffer); } static void -test_null (CuTest *tc) +test_null (void) { p11_buffer buffer; @@ -85,7 +85,7 @@ test_null (CuTest *tc) p11_buffer_add (&buffer, "Blah", -1); p11_buffer_add (&buffer, " blah", -1); - CuAssertStrEquals (tc, "Blah blah", buffer.data); + assert_str_eq ("Blah blah", buffer.data); p11_buffer_uninit (&buffer); } @@ -109,7 +109,7 @@ mock_free (void *data) } static void -test_init_for_data (CuTest *tc) +test_init_for_data (void) { p11_buffer buffer; unsigned char *ret; @@ -121,29 +121,29 @@ test_init_for_data (CuTest *tc) p11_buffer_init_full (&buffer, (unsigned char *)strdup ("blah"), 4, 0, mock_realloc, mock_free); - CuAssertPtrNotNull (tc, buffer.data); - CuAssertStrEquals (tc, "blah", (char *)buffer.data); - CuAssertIntEquals (tc, 4, buffer.len); - CuAssertIntEquals (tc, 0, buffer.flags); - CuAssertIntEquals (tc, 4, buffer.size); - CuAssertPtrEquals (tc, mock_free, buffer.ffree); - CuAssertPtrEquals (tc, mock_realloc, buffer.frealloc); + assert_ptr_not_null (buffer.data); + assert_str_eq ("blah", (char *)buffer.data); + assert_num_eq (4, buffer.len); + assert_num_eq (0, buffer.flags); + assert_num_eq (4, buffer.size); + assert_ptr_eq (mock_free, buffer.ffree); + assert_ptr_eq (mock_realloc, buffer.frealloc); - CuAssertIntEquals (tc, 0, mock_realloced); - CuAssertIntEquals (tc, 0, mock_freed); + assert_num_eq (0, mock_realloced); + assert_num_eq (0, mock_freed); len = buffer.len; ret = p11_buffer_append (&buffer, 1024); - CuAssertPtrEquals (tc, (char *)buffer.data + len, ret); - CuAssertIntEquals (tc, 1, mock_realloced); + assert_ptr_eq ((char *)buffer.data + len, ret); + assert_num_eq (1, mock_realloced); p11_buffer_uninit (&buffer); - CuAssertIntEquals (tc, 1, mock_realloced); - CuAssertIntEquals (tc, 1, mock_freed); + assert_num_eq (1, mock_realloced); + assert_num_eq (1, mock_freed); } static void -test_steal (CuTest *tc) +test_steal (void) { p11_buffer buffer; char *string; @@ -154,61 +154,46 @@ test_steal (CuTest *tc) p11_buffer_init_full (&buffer, (unsigned char *)strdup ("blah"), 4, P11_BUFFER_NULL, mock_realloc, mock_free); - CuAssertPtrNotNull (tc, buffer.data); - CuAssertStrEquals (tc, "blah", buffer.data); + assert_ptr_not_null (buffer.data); + assert_str_eq ("blah", buffer.data); p11_buffer_add (&buffer, " yada", -1); - CuAssertStrEquals (tc, "blah yada", buffer.data); + assert_str_eq ("blah yada", buffer.data); string = p11_buffer_steal (&buffer, &length); p11_buffer_uninit (&buffer); - CuAssertStrEquals (tc, "blah yada", string); - CuAssertIntEquals (tc, 9, length); - CuAssertIntEquals (tc, 0, mock_freed); + assert_str_eq ("blah yada", string); + assert_num_eq (9, length); + assert_num_eq (0, mock_freed); free (string); } static void -test_add (CuTest *tc) +test_add (void) { p11_buffer buffer; p11_buffer_init (&buffer, 10); p11_buffer_add (&buffer, (unsigned char *)"Planet Express", 15); - CuAssertIntEquals (tc, 15, buffer.len); - CuAssertStrEquals (tc, "Planet Express", (char *)buffer.data); - CuAssertTrue (tc, p11_buffer_ok (&buffer)); + assert_num_eq (15, buffer.len); + assert_str_eq ("Planet Express", (char *)buffer.data); + assert (p11_buffer_ok (&buffer)); p11_buffer_uninit (&buffer); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_init_uninit); - SUITE_ADD_TEST (suite, test_init_for_data); - SUITE_ADD_TEST (suite, test_append); - SUITE_ADD_TEST (suite, test_null); - SUITE_ADD_TEST (suite, test_add); - SUITE_ADD_TEST (suite, test_steal); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_init_uninit, "/buffer/init-uninit"); + p11_test (test_init_for_data, "/buffer/init-for-data"); + p11_test (test_append, "/buffer/append"); + p11_test (test_null, "/buffer/null"); + p11_test (test_add, "/buffer/add"); + p11_test (test_steal, "/buffer/steal"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-compat.c b/common/tests/test-compat.c index 066e723..f1960ce 100644 --- a/common/tests/test-compat.c +++ b/common/tests/test-compat.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -42,36 +42,24 @@ #include "compat.h" static void -test_strndup (CuTest *tc) +test_strndup (void) { char unterminated[] = { 't', 'e', 's', 't', 'e', 'r', 'o', 'n', 'i', 'o' }; char *res; res = strndup (unterminated, 6); - CuAssertStrEquals (tc, res, "tester"); + assert_str_eq (res, "tester"); free (res); res = strndup ("test", 6); - CuAssertStrEquals (tc, res, "test"); + assert_str_eq (res, "test"); free (res); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_strndup); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_strndup, "/test/strndup"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-constants.c b/common/tests/test-constants.c index 4cd4472..9adc81a 100644 --- a/common/tests/test-constants.c +++ b/common/tests/test-constants.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -44,50 +44,38 @@ #include "debug.h" static void -test_constants (CuTest *tc) +test_constants (void *arg) { - const p11_constant *constant; + const p11_constant *constant = arg; p11_dict *nicks, *names; CK_ULONG check; - int i, j; - - static const p11_constant *constants[] = { - p11_constant_types, - p11_constant_classes, - p11_constant_trusts, - p11_constant_certs, - p11_constant_keys, - p11_constant_asserts, - p11_constant_categories, - NULL - }; + int i; nicks = p11_constant_reverse (true); names = p11_constant_reverse (false); - for (j = 0; constants[j] != NULL; j++) { - constant = constants[j]; - for (i = 1; constant[i].value != CKA_INVALID; i++) { - if (constant[i].value < constant[i - 1].value) { - CuFail_Line (tc, __FILE__, __LINE__, - "attr constant out of order", constant[i].name); - } + for (i = 1; constant[i].value != CKA_INVALID; i++) { + if (constant[i].value < constant[i - 1].value) + assert_fail ("attr constant out of order", constant[i].name); + } + for (i = 0; constant[i].value != CKA_INVALID; i++) { + assert_ptr_not_null (constant[i].name); + + if (constant[i].nick) { + assert_str_eq (constant[i].nick, + p11_constant_nick (constant, constant[i].value)); } - for (i = 0; constant[i].value != CKA_INVALID; i++) { - CuAssertPtrNotNull (tc, constant[i].nick); - CuAssertPtrNotNull (tc, constant[i].name); - CuAssertStrEquals (tc, constant[i].nick, - p11_constant_nick (constant, constant[i].value)); - CuAssertStrEquals (tc, constant[i].name, - p11_constant_name (constant, constant[i].value)); + assert_str_eq (constant[i].name, + p11_constant_name (constant, constant[i].value)); + if (constant[i].nick) { check = p11_constant_resolve (nicks, constant[i].nick); - CuAssertIntEquals (tc, constant[i].value, check); - - check = p11_constant_resolve (names, constant[i].name); - CuAssertIntEquals (tc, constant[i].value, check); + assert_num_eq (constant[i].value, check); } + + check = p11_constant_resolve (names, constant[i].name); + assert_num_eq (constant[i].value, check); } p11_dict_free (names); @@ -95,23 +83,20 @@ test_constants (CuTest *tc) } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - SUITE_ADD_TEST (suite, test_constants); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); + p11_testx (test_constants, (void *)p11_constant_types, "/constants/types"); + p11_testx (test_constants, (void *)p11_constant_classes, "/constants/classes"); + p11_testx (test_constants, (void *)p11_constant_trusts, "/constants/trusts"); + p11_testx (test_constants, (void *)p11_constant_certs, "/constants/certs"); + p11_testx (test_constants, (void *)p11_constant_keys, "/constants/keys"); + p11_testx (test_constants, (void *)p11_constant_asserts, "/constants/asserts"); + p11_testx (test_constants, (void *)p11_constant_categories, "/constants/categories"); + p11_testx (test_constants, (void *)p11_constant_mechanisms, "/constants/mechanisms"); + p11_testx (test_constants, (void *)p11_constant_users, "/constants/users"); + p11_testx (test_constants, (void *)p11_constant_states, "/constants/states"); + p11_testx (test_constants, (void *)p11_constant_returns, "/constants/returns"); - return ret; + return p11_test_run (argc, argv); } diff --git a/common/tests/test-dict.c b/common/tests/test-dict.c index fc40b07..7c6f851 100644 --- a/common/tests/test-dict.c +++ b/common/tests/test-dict.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <assert.h> #include <stdlib.h> @@ -43,17 +43,17 @@ #include "dict.h" static void -test_create (CuTest *tc) +test_create (void) { p11_dict *map; map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); p11_dict_free (map); } static void -test_free_null (CuTest *tc) +test_free_null (void) { p11_dict_free (NULL); } @@ -98,24 +98,24 @@ value_destroy (void *data) } static void -test_free_destroys (CuTest *tc) +test_free_destroys (void) { p11_dict *map; Key key = { 8, 0 }; int value = 0; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); if (!p11_dict_set (map, &key, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_dict_free (map); - CuAssertIntEquals (tc, true, key.freed); - CuAssertIntEquals (tc, 2, value); + assert_num_eq (true, key.freed); + assert_num_eq (2, value); } static void -test_iterate (CuTest *tc) +test_iterate (void) { p11_dict *map; p11_dictiter iter; @@ -126,19 +126,19 @@ test_iterate (CuTest *tc) int ret; map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); if (!p11_dict_set (map, &key, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_dict_iterate (map, &iter); ret = p11_dict_next (&iter, &pkey, &pvalue); - CuAssertIntEquals (tc, 1, ret); - CuAssertPtrEquals (tc, pkey, &key); - CuAssertPtrEquals (tc, pvalue, &value); + assert_num_eq (1, ret); + assert_ptr_eq (pkey, &key); + assert_ptr_eq (pvalue, &value); ret = p11_dict_next (&iter, &pkey, &pvalue); - CuAssertIntEquals (tc, 0, ret); + assert_num_eq (0, ret); p11_dict_free (map); } @@ -153,7 +153,7 @@ compar_strings (const void *one, } static void -test_iterate_remove (CuTest *tc) +test_iterate_remove (void) { p11_dict *map; p11_dictiter iter; @@ -165,45 +165,45 @@ test_iterate_remove (CuTest *tc) int i; map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); for (i = 0; i < 3; i++) { if (!p11_dict_set (map, keys[i], values[i])) - CuFail (tc, "should not be reached"); + assert_not_reached (); } p11_dict_iterate (map, &iter); ret = p11_dict_next (&iter, &okeys[0], &ovalues[0]); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_dict_next (&iter, &okeys[1], &ovalues[1]); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); if (!p11_dict_remove (map, okeys[1])) - CuFail (tc, "should not be reached"); + assert_not_reached (); ret = p11_dict_next (&iter, &okeys[2], &ovalues[2]); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_dict_next (&iter, NULL, NULL); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); - CuAssertIntEquals (tc, 2, p11_dict_size (map)); + assert_num_eq (2, p11_dict_size (map)); p11_dict_free (map); qsort (okeys, 3, sizeof (void *), compar_strings); qsort (ovalues, 3, sizeof (void *), compar_strings); for (i = 0; i < 3; i++) { - CuAssertStrEquals (tc, keys[i], okeys[i]); - CuAssertPtrEquals (tc, keys[i], okeys[i]); - CuAssertStrEquals (tc, values[i], ovalues[i]); - CuAssertPtrEquals (tc, values[i], ovalues[i]); + assert_str_eq (keys[i], okeys[i]); + assert_ptr_eq (keys[i], okeys[i]); + assert_str_eq (values[i], ovalues[i]); + assert_ptr_eq (values[i], ovalues[i]); } } static void -test_set_get (CuTest *tc) +test_set_get (void) { char *key = "KEY"; char *value = "VALUE"; @@ -213,13 +213,13 @@ test_set_get (CuTest *tc) map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); p11_dict_set (map, key, value); check = p11_dict_get (map, key); - CuAssertPtrEquals (tc, check, value); + assert_ptr_eq (check, value); p11_dict_free (map); } static void -test_set_get_remove (CuTest *tc) +test_set_get_remove (void) { char *key = "KEY"; char *value = "VALUE"; @@ -230,24 +230,24 @@ test_set_get_remove (CuTest *tc) map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); if (!p11_dict_set (map, key, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); check = p11_dict_get (map, key); - CuAssertPtrEquals (tc, check, value); + assert_ptr_eq (check, value); ret = p11_dict_remove (map, key); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_dict_remove (map, key); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); check = p11_dict_get (map, key); - CuAssert (tc, "should be null", check == NULL); + assert (check == NULL); p11_dict_free (map); } static void -test_set_clear (CuTest *tc) +test_set_clear (void) { char *key = "KEY"; char *value = "VALUE"; @@ -257,18 +257,18 @@ test_set_clear (CuTest *tc) map = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL); if (!p11_dict_set (map, key, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_dict_clear (map); check = p11_dict_get (map, key); - CuAssert (tc, "should be null", check == NULL); + assert (check == NULL); p11_dict_free (map); } static void -test_remove_destroys (CuTest *tc) +test_remove_destroys (void) { p11_dict *map; Key key = { 8, 0 }; @@ -276,23 +276,23 @@ test_remove_destroys (CuTest *tc) bool ret; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); if (!p11_dict_set (map, &key, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); ret = p11_dict_remove (map, &key); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, true, key.freed); - CuAssertIntEquals (tc, 2, value); + assert_num_eq (true, ret); + assert_num_eq (true, key.freed); + assert_num_eq (2, value); /* should not be destroyed again */ key.freed = false; value = 0; ret = p11_dict_remove (map, &key); - CuAssertIntEquals (tc, false, ret); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (false, ret); + assert_num_eq (false, key.freed); + assert_num_eq (0, value); /* should not be destroyed again */ key.freed = false; @@ -300,12 +300,12 @@ test_remove_destroys (CuTest *tc) p11_dict_free (map); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (false, key.freed); + assert_num_eq (0, value); } static void -test_set_destroys (CuTest *tc) +test_set_destroys (void) { p11_dict *map; Key key = { 8, 0 }; @@ -314,88 +314,88 @@ test_set_destroys (CuTest *tc) bool ret; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); if (!p11_dict_set (map, &key, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); key.freed = key2.freed = false; value = value2 = 0; /* Setting same key and value, should not be destroyed */ ret = p11_dict_set (map, &key, &value); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, false, key2.freed); - CuAssertIntEquals (tc, 0, value); - CuAssertIntEquals (tc, 0, value2); + assert_num_eq (true, ret); + assert_num_eq (false, key.freed); + assert_num_eq (false, key2.freed); + assert_num_eq (0, value); + assert_num_eq (0, value2); key.freed = key2.freed = false; value = value2 = 0; /* Setting a new key same value, key should be destroyed */ ret = p11_dict_set (map, &key2, &value); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, true, key.freed); - CuAssertIntEquals (tc, false, key2.freed); - CuAssertIntEquals (tc, 0, value); - CuAssertIntEquals (tc, 0, value2); + assert_num_eq (true, ret); + assert_num_eq (true, key.freed); + assert_num_eq (false, key2.freed); + assert_num_eq (0, value); + assert_num_eq (0, value2); key.freed = key2.freed = false; value = value2 = 0; /* Setting same key, new value, value should be destroyed */ ret = p11_dict_set (map, &key2, &value2); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, false, key2.freed); - CuAssertIntEquals (tc, 2, value); - CuAssertIntEquals (tc, 0, value2); + assert_num_eq (true, ret); + assert_num_eq (false, key.freed); + assert_num_eq (false, key2.freed); + assert_num_eq (2, value); + assert_num_eq (0, value2); key.freed = key2.freed = false; value = value2 = 0; /* Setting new key new value, both should be destroyed */ ret = p11_dict_set (map, &key, &value); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, true, key2.freed); - CuAssertIntEquals (tc, 0, value); - CuAssertIntEquals (tc, 2, value2); + assert_num_eq (true, ret); + assert_num_eq (false, key.freed); + assert_num_eq (true, key2.freed); + assert_num_eq (0, value); + assert_num_eq (2, value2); key.freed = key2.freed = false; value = value2 = 0; p11_dict_free (map); - CuAssertIntEquals (tc, true, key.freed); - CuAssertIntEquals (tc, 2, value); - CuAssertIntEquals (tc, false, key2.freed); - CuAssertIntEquals (tc, 0, value2); + assert_num_eq (true, key.freed); + assert_num_eq (2, value); + assert_num_eq (false, key2.freed); + assert_num_eq (0, value2); } static void -test_clear_destroys (CuTest *tc) +test_clear_destroys (void) { p11_dict *map; Key key = { 18, 0 }; int value = 0; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); - CuAssertPtrNotNull (tc, map); + assert_ptr_not_null (map); if (!p11_dict_set (map, &key, &value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); p11_dict_clear (map); - CuAssertIntEquals (tc, true, key.freed); - CuAssertIntEquals (tc, 2, value); + assert_num_eq (true, key.freed); + assert_num_eq (2, value); /* should not be destroyed again */ key.freed = false; value = 0; p11_dict_clear (map); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (false, key.freed); + assert_num_eq (0, value); /* should not be destroyed again */ key.freed = false; @@ -403,8 +403,8 @@ test_clear_destroys (CuTest *tc) p11_dict_free (map); - CuAssertIntEquals (tc, false, key.freed); - CuAssertIntEquals (tc, 0, value); + assert_num_eq (false, key.freed); + assert_num_eq (0, value); } static unsigned int @@ -415,7 +415,7 @@ test_hash_intptr_with_collisions (const void *data) } static void -test_hash_add_check_lots_and_collisions (CuTest *tc) +test_hash_add_check_lots_and_collisions (void) { p11_dict *map; int *value; @@ -428,20 +428,20 @@ test_hash_add_check_lots_and_collisions (CuTest *tc) value = malloc (sizeof (int)); *value = i; if (!p11_dict_set (map, value, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); } for (i = 0; i < 20000; ++i) { value = p11_dict_get (map, &i); - CuAssertPtrNotNull (tc, value); - CuAssertIntEquals (tc, i, *value); + assert_ptr_not_null (value); + assert_num_eq (i, *value); } p11_dict_free (map); } static void -test_hash_count (CuTest *tc) +test_hash_count (void) { p11_dict *map; int *value; @@ -450,30 +450,30 @@ test_hash_count (CuTest *tc) map = p11_dict_new (p11_dict_intptr_hash, p11_dict_intptr_equal, NULL, free); - CuAssertIntEquals (tc, 0, p11_dict_size (map)); + assert_num_eq (0, p11_dict_size (map)); for (i = 0; i < 20000; ++i) { value = malloc (sizeof (int)); *value = i; if (!p11_dict_set (map, value, value)) - CuFail (tc, "should not be reached"); - CuAssertIntEquals (tc, i + 1, p11_dict_size (map)); + assert_not_reached (); + assert_num_eq (i + 1, p11_dict_size (map)); } for (i = 0; i < 20000; ++i) { ret = p11_dict_remove (map, &i); - CuAssertIntEquals (tc, true, ret); - CuAssertIntEquals (tc, 20000 - (i + 1), p11_dict_size (map)); + assert_num_eq (true, ret); + assert_num_eq (20000 - (i + 1), p11_dict_size (map)); } p11_dict_clear (map); - CuAssertIntEquals (tc, 0, p11_dict_size (map)); + assert_num_eq (0, p11_dict_size (map)); p11_dict_free (map); } static void -test_hash_ulongptr (CuTest *tc) +test_hash_ulongptr (void) { p11_dict *map; unsigned long *value; @@ -485,47 +485,35 @@ test_hash_ulongptr (CuTest *tc) value = malloc (sizeof (unsigned long)); *value = i; if (!p11_dict_set (map, value, value)) - CuFail (tc, "should not be reached"); + assert_not_reached (); } for (i = 0; i < 20000; ++i) { value = p11_dict_get (map, &i); - CuAssertPtrNotNull (tc, value); - CuAssertIntEquals (tc, i, *value); + assert_ptr_not_null (value); + assert_num_eq (i, *value); } p11_dict_free (map); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_create); - SUITE_ADD_TEST (suite, test_set_get); - SUITE_ADD_TEST (suite, test_set_get_remove); - SUITE_ADD_TEST (suite, test_remove_destroys); - SUITE_ADD_TEST (suite, test_set_clear); - SUITE_ADD_TEST (suite, test_set_destroys); - SUITE_ADD_TEST (suite, test_clear_destroys); - SUITE_ADD_TEST (suite, test_free_null); - SUITE_ADD_TEST (suite, test_free_destroys); - SUITE_ADD_TEST (suite, test_iterate); - SUITE_ADD_TEST (suite, test_iterate_remove); - SUITE_ADD_TEST (suite, test_hash_add_check_lots_and_collisions); - SUITE_ADD_TEST (suite, test_hash_count); - SUITE_ADD_TEST (suite, test_hash_ulongptr); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_create, "/dict/create"); + p11_test (test_set_get, "/dict/set-get"); + p11_test (test_set_get_remove, "/dict/set-get-remove"); + p11_test (test_remove_destroys, "/dict/remove-destroys"); + p11_test (test_set_clear, "/dict/set-clear"); + p11_test (test_set_destroys, "/dict/set-destroys"); + p11_test (test_clear_destroys, "/dict/clear-destroys"); + p11_test (test_free_null, "/dict/free-null"); + p11_test (test_free_destroys, "/dict/free-destroys"); + p11_test (test_iterate, "/dict/iterate"); + p11_test (test_iterate_remove, "/dict/iterate-remove"); + p11_test (test_hash_add_check_lots_and_collisions, "/dict/add-check-lots-and-collisions"); + p11_test (test_hash_count, "/dict/count"); + p11_test (test_hash_ulongptr, "/dict/ulongptr"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-hash.c b/common/tests/test-hash.c index eecf09b..c679cad 100644 --- a/common/tests/test-hash.c +++ b/common/tests/test-hash.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <assert.h> #include <stdint.h> @@ -56,7 +56,7 @@ const char *sha1_checksum[] = { }; static void -test_sha1 (CuTest *cu) +test_sha1 (void) { unsigned char checksum[P11_HASH_SHA1_LEN]; size_t len; @@ -67,28 +67,28 @@ test_sha1 (CuTest *cu) len = strlen (sha1_input[i]); p11_hash_sha1 (checksum, sha1_input[i], len, NULL); - CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); + assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); if (len > 6) { p11_hash_sha1 (checksum, sha1_input[i], 6, sha1_input[i] + 6, len - 6, NULL); - CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); + assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); } } } static void -test_sha1_long (CuTest *cu) +test_sha1_long (void) { unsigned char checksum[P11_HASH_SHA1_LEN]; char *expected = "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"; char *input; input = malloc (1000000); - CuAssertTrue (cu, input != NULL); + assert (input != NULL); memset (input, 'a', 1000000); p11_hash_sha1 (checksum, input, 1000000, NULL); - CuAssertTrue (cu, memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0); + assert (memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0); free (input); } @@ -112,7 +112,7 @@ const char *md5_checksum[] = { }; static void -test_md5 (CuTest *cu) +test_md5 (void) { unsigned char checksum[P11_HASH_MD5_LEN]; size_t len; @@ -123,17 +123,17 @@ test_md5 (CuTest *cu) len = strlen (md5_input[i]); p11_hash_md5 (checksum, md5_input[i], len, NULL); - CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); + assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); if (len > 5) { p11_hash_md5 (checksum, md5_input[i], 5, md5_input[i] + 5, len - 5, NULL); - CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); + assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); } } } static void -test_murmur2 (CuTest *cu) +test_murmur3 (void) { uint32_t one, two, four, seven, eleven, split; @@ -146,23 +146,23 @@ test_murmur2 (CuTest *cu) p11_hash_murmur3 ((unsigned char *)&eleven, "eleven", 6, NULL); p11_hash_murmur3 ((unsigned char *)&split, "ele", 3, "ven", 3, NULL); - CuAssertTrue (cu, one != two); - CuAssertTrue (cu, one != four); - CuAssertTrue (cu, one != seven); - CuAssertTrue (cu, one != eleven); + assert (one != two); + assert (one != four); + assert (one != seven); + assert (one != eleven); - CuAssertTrue (cu, two != four); - CuAssertTrue (cu, two != seven); - CuAssertTrue (cu, two != eleven); + assert (two != four); + assert (two != seven); + assert (two != eleven); - CuAssertTrue (cu, four != seven); - CuAssertTrue (cu, four != eleven); + assert (four != seven); + assert (four != eleven); - CuAssertTrue (cu, split == eleven); + assert (split == eleven); } static void -test_murmur2_incr (CuTest *cu) +test_murmur3_incr (void) { uint32_t first, second; @@ -182,29 +182,17 @@ test_murmur2_incr (CuTest *cu) "!", (size_t)1, NULL); - CuAssertIntEquals (cu, first, second); + assert_num_eq (first, second); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_sha1); - SUITE_ADD_TEST (suite, test_sha1_long); - SUITE_ADD_TEST (suite, test_md5); - SUITE_ADD_TEST (suite, test_murmur2); - SUITE_ADD_TEST (suite, test_murmur2_incr); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_sha1, "/hash/sha1"); + p11_test (test_sha1_long, "/hash/sha1-long"); + p11_test (test_md5, "/hash/md5"); + p11_test (test_murmur3, "/hash/murmur3"); + p11_test (test_murmur3_incr, "/hash/murmur3-incr"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-lexer.c b/common/tests/test-lexer.c index 58d5d65..ff18a89 100644 --- a/common/tests/test-lexer.c +++ b/common/tests/test-lexer.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -62,9 +62,9 @@ on_pem_get_type (const char *type, } static void -check_lex_msg (CuTest *tc, - const char *file, +check_lex_msg (const char *file, int line, + const char *function, const expected_tok *expected, const char *input, bool failure) @@ -77,60 +77,63 @@ check_lex_msg (CuTest *tc, p11_lexer_init (&lexer, "test", input, strlen (input)); for (i = 0; p11_lexer_next (&lexer, &failed); i++) { - CuAssertIntEquals_LineMsg (tc, file, line, - "lexer token type does not match", - expected[i].tok_type, lexer.tok_type); + if (expected[i].tok_type != lexer.tok_type) + p11_test_fail (file, line, function, + "lexer token type does not match: (%d != %d)", + expected[i].tok_type, lexer.tok_type); switch (lexer.tok_type) { case TOK_FIELD: - CuAssertStrEquals_LineMsg (tc, file, line, - "field name doesn't match", - expected[i].name, lexer.tok.field.name); - CuAssertStrEquals_LineMsg (tc, file, line, - "field value doesn't match", - expected[i].value, lexer.tok.field.value); + if (strcmp (expected[i].name, lexer.tok.field.name) != 0) + p11_test_fail (file, line, function, + "field name doesn't match: (%s != %s)", + expected[i].name, lexer.tok.field.name); + if (strcmp (expected[i].value, lexer.tok.field.value) != 0) + p11_test_fail (file, line, function, + "field value doesn't match: (%s != %s)", + expected[i].value, lexer.tok.field.value); break; case TOK_SECTION: - CuAssertStrEquals_LineMsg (tc, file, line, - "section name doesn't match", - expected[i].name, lexer.tok.field.name); + if (strcmp (expected[i].name, lexer.tok.field.name) != 0) + p11_test_fail (file, line, function, + "section name doesn't match: (%s != %s)", + expected[i].name, lexer.tok.field.name); break; case TOK_PEM: type = NULL; count = p11_pem_parse (lexer.tok.pem.begin, lexer.tok.pem.length, on_pem_get_type, &type); - CuAssertIntEquals_LineMsg (tc, file, line, - "wrong number of PEM blocks", - 1, count); - CuAssertStrEquals_LineMsg (tc, file, line, - "wrong type of PEM block", - expected[i].name, type); + if (count != 1) + p11_test_fail (file, line, function, "more than one PEM block: %d", count); + if (strcmp (expected[i].name, type) != 0) + p11_test_fail (file, line, function, + "wrong type of PEM block: (%s != %s)", + expected[i].name, type); free (type); break; case TOK_EOF: - CuFail_Line (tc, file, line, NULL, "eof should not be recieved"); + p11_test_fail (file, line, function, "eof should not be recieved"); break; } } - if (failure) - CuAssert_Line (tc, file, line, "lexing didn't fail", failed); - else - CuAssert_Line (tc, file, line, "lexing failed", !failed); - CuAssertIntEquals_LineMsg (tc, file, line, - "premature end of lexing", - TOK_EOF, expected[i].tok_type); + if (failure && !failed) + p11_test_fail (file, line, function, "lexing didn't fail"); + else if (!failure && failed) + p11_test_fail (file, line, function, "lexing failed"); + if (TOK_EOF != expected[i].tok_type) + p11_test_fail (file, line, function, "premature end of lexing"); p11_lexer_done (&lexer); } -#define check_lex_success(tc, expected, input) \ - check_lex_msg (tc, __FILE__, __LINE__, expected, input, false) +#define check_lex_success(expected, input) \ + check_lex_msg (__FILE__, __LINE__, __FUNCTION__, expected, input, false) -#define check_lex_failure(tc, expected, input) \ - check_lex_msg (tc, __FILE__, __LINE__, expected, input, true) +#define check_lex_failure(expected, input) \ + check_lex_msg (__FILE__, __LINE__, __FUNCTION__, expected, input, true) static void -test_basic (CuTest *tc) +test_basic (void) { const char *input = "[the header]\n" "field: value\n" @@ -145,11 +148,11 @@ test_basic (CuTest *tc) { TOK_EOF } }; - check_lex_success (tc, expected, input); + check_lex_success (expected, input); } static void -test_corners (CuTest *tc) +test_corners (void) { const char *input = "\r\n" /* blankline */ " [the header]\r\n" /* bad line endings */ @@ -175,11 +178,11 @@ test_corners (CuTest *tc) { TOK_EOF } }; - check_lex_success (tc, expected, input); + check_lex_success (expected, input); } static void -test_following (CuTest *tc) +test_following (void) { const char *input = "-----BEGIN BLOCK1-----\n" "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n" @@ -192,11 +195,11 @@ test_following (CuTest *tc) { TOK_EOF } }; - check_lex_success (tc, expected, input); + check_lex_success (expected, input); } static void -test_bad_pem (CuTest *tc) +test_bad_pem (void) { const char *input = "field: value\n" "-----BEGIN BLOCK1-----\n" @@ -209,13 +212,13 @@ test_bad_pem (CuTest *tc) p11_message_quiet (); - check_lex_failure (tc, expected, input); + check_lex_failure (expected, input); p11_message_loud (); } static void -test_bad_section (CuTest *tc) +test_bad_section (void) { const char *input = "field: value\n" "[section\n" @@ -228,13 +231,13 @@ test_bad_section (CuTest *tc) p11_message_quiet (); - check_lex_failure (tc, expected, input); + check_lex_failure (expected, input); p11_message_loud (); } static void -test_bad_value (CuTest *tc) +test_bad_value (void) { const char *input = "field_value\n" "[section\n" @@ -246,35 +249,20 @@ test_bad_value (CuTest *tc) p11_message_quiet (); - check_lex_failure (tc, expected, input); + check_lex_failure (expected, input); p11_message_loud (); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_basic); - SUITE_ADD_TEST (suite, test_corners); - SUITE_ADD_TEST (suite, test_following); - SUITE_ADD_TEST (suite, test_bad_pem); - SUITE_ADD_TEST (suite, test_bad_section); - SUITE_ADD_TEST (suite, test_bad_value); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_basic, "/lexer/basic"); + p11_test (test_corners, "/lexer/corners"); + p11_test (test_following, "/lexer/following"); + p11_test (test_bad_pem, "/lexer/bad-pem"); + p11_test (test_bad_section, "/lexer/bad-section"); + p11_test (test_bad_value, "/lexer/bad-value"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-oid.c b/common/tests/test-oid.c index 71b8278..05945d9 100644 --- a/common/tests/test-oid.c +++ b/common/tests/test-oid.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -47,7 +47,7 @@ #include "pkix.asn.h" static void -test_known_oids (CuTest *cu) +test_known_oids (void) { char buffer[128]; node_asn *definitions = NULL; @@ -79,29 +79,29 @@ test_known_oids (CuTest *cu) }; ret = asn1_array2tree (pkix_asn1_tab, &definitions, NULL); - CuAssertTrue (cu, ret == ASN1_SUCCESS); + assert (ret == ASN1_SUCCESS); for (i = 0; known_oids[i].oid != NULL; i++) { - CuAssertTrue (cu, p11_oid_simple (known_oids[i].oid, known_oids[i].length)); - CuAssertIntEquals (cu, known_oids[i].length, p11_oid_length (known_oids[i].oid)); - CuAssertTrue (cu, p11_oid_equal (known_oids[i].oid, known_oids[i].oid)); + assert (p11_oid_simple (known_oids[i].oid, known_oids[i].length)); + assert_num_eq (known_oids[i].length, p11_oid_length (known_oids[i].oid)); + assert (p11_oid_equal (known_oids[i].oid, known_oids[i].oid)); if (i > 0) - CuAssertTrue (cu, !p11_oid_equal (known_oids[i].oid, known_oids[i - 1].oid)); + assert (!p11_oid_equal (known_oids[i].oid, known_oids[i - 1].oid)); /* AttributeType is a OBJECT IDENTIFIER */ ret = asn1_create_element (definitions, "PKIX1.AttributeType", &node); - CuAssertTrue (cu, ret == ASN1_SUCCESS); + assert (ret == ASN1_SUCCESS); ret = asn1_der_decoding (&node, known_oids[i].oid, known_oids[i].length, NULL); - CuAssertTrue (cu, ret == ASN1_SUCCESS); + assert (ret == ASN1_SUCCESS); len = sizeof (buffer); ret = asn1_read_value (node, "", buffer, &len); - CuAssertTrue (cu, ret == ASN1_SUCCESS); + assert (ret == ASN1_SUCCESS); - CuAssertStrEquals (cu, known_oids[i].string, buffer); + assert_str_eq (known_oids[i].string, buffer); asn1_delete_structure (&node); } @@ -110,24 +110,9 @@ test_known_oids (CuTest *cu) } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_known_oids); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_known_oids, "/oids/known"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-path.c b/common/tests/test-path.c index 8263d1f..ec2c200 100644 --- a/common/tests/test-path.c +++ b/common/tests/test-path.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -43,7 +43,7 @@ #include "path.h" static void -test_base (CuTest *tc) +test_base (void) { struct { const char *in; @@ -70,133 +70,134 @@ test_base (CuTest *tc) for (i = 0; fixtures[i].in != NULL; i++) { out = p11_path_base (fixtures[i].in); - CuAssertStrEquals (tc, fixtures[i].out, out); + assert_str_eq (fixtures[i].out, out); free (out); } } -static void -check_equals_and_free_msg (CuTest *tc, - const char *file, - int line, - const char *ex, - char *ac) -{ - CuAssertStrEquals_LineMsg (tc, file, line, NULL, ex, ac); - free (ac); -} - -#define check_equals_and_free(tc, ex, ac) \ - check_equals_and_free_msg ((tc), __FILE__, __LINE__, (ex), (ac)) +#define check_equals_and_free(ex, ac) \ + do { assert_str_eq (ex, ac); free (ac); } while (0) static void -test_build (CuTest *tc) +test_build (void) { #ifdef OS_UNIX - check_equals_and_free (tc, "/root/second", + check_equals_and_free ("/root/second", p11_path_build ("/root", "second", NULL)); - check_equals_and_free (tc, "/root/second", + check_equals_and_free ("/root/second", p11_path_build ("/root", "/second", NULL)); - check_equals_and_free (tc, "/root/second", + check_equals_and_free ("/root/second", p11_path_build ("/root/", "second", NULL)); - check_equals_and_free (tc, "/root/second/third", + check_equals_and_free ("/root/second/third", p11_path_build ("/root", "second", "third", NULL)); - check_equals_and_free (tc, "/root/second/third", + check_equals_and_free ("/root/second/third", p11_path_build ("/root", "/second/third", NULL)); #else /* OS_WIN32 */ - check_equals_and_free (tc, "C:\\root\\second", + check_equals_and_free ("C:\\root\\second", p11_path_build ("C:\\root", "second", NULL)); - check_equals_and_free (tc, "C:\\root\\second", + check_equals_and_free ("C:\\root\\second", p11_path_build ("C:\\root", "\\second", NULL)); - check_equals_and_free (tc, "C:\\root\\second", + check_equals_and_free ("C:\\root\\second", p11_path_build ("C:\\root\\", "second", NULL)); - check_equals_and_free (tc, "C:\\root\\second\\third", + check_equals_and_free ("C:\\root\\second\\third", p11_path_build ("C:\\root", "second", "third", NULL)); - check_equals_and_free (tc, "C:\\root\\second/third", + check_equals_and_free ("C:\\root\\second/third", p11_path_build ("C:\\root", "second/third", NULL)); #endif } static void -test_expand (CuTest *tc) +test_expand (void) { char *path; #ifdef OS_UNIX putenv ("HOME=/home/blah"); - check_equals_and_free (tc, "/home/blah/my/path", + check_equals_and_free ("/home/blah/my/path", p11_path_expand ("$HOME/my/path")); - check_equals_and_free (tc, "/home/blah/my/path", + check_equals_and_free ("/home/blah/my/path", p11_path_expand ("~/my/path")); + check_equals_and_free ("/home/blah", + p11_path_expand ("$HOME")); + check_equals_and_free ("/home/blah", + p11_path_expand ("~")); putenv ("TEMP=/tmpdir"); - check_equals_and_free (tc, "/tmpdir/my/path", + check_equals_and_free ("/tmpdir/my/path", p11_path_expand ("$TEMP/my/path")); + check_equals_and_free ("/tmpdir", + p11_path_expand ("$TEMP")); #else /* OS_WIN32 */ putenv ("HOME=C:\\Users\\blah"); - check_equals_and_free (tc, "C:\\Users\\blah\\path", + check_equals_and_free ("C:\\Users\\blah\\path", p11_path_expand ("$HOME/path")); - check_equals_and_free (tc, "C:\\Users\\blah\\path", + check_equals_and_free ("C:\\Users\\blah\\path", p11_path_expand ("$HOME\\path")); - check_equals_and_free (tc, "C:\\Users\\blah\\path", + check_equals_and_free ("C:\\Users\\blah\\path", p11_path_expand ("~/path")); - check_equals_and_free (tc, "C:\\Users\\blah\\path", + check_equals_and_free ("C:\\Users\\blah\\path", p11_path_expand ("~\\path")); putenv ("TEMP=C:\\Temp Directory"); - check_equals_and_free (tc, "C:\\Temp Directory\\path", + check_equals_and_free ("C:\\Temp Directory\\path", p11_path_expand ("$TEMP/path")); - check_equals_and_free (tc, "C:\\Temp Directory\\path", + check_equals_and_free ("C:\\Temp Directory\\path", p11_path_expand ("$TEMP\\path")); #endif putenv("HOME="); path = p11_path_expand ("$HOME/this/is/my/path"); - CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL); + assert (strstr (path, "this/is/my/path") != NULL); free (path); putenv("HOME="); path = p11_path_expand ("~/this/is/my/path"); - CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL); + assert (strstr (path, "this/is/my/path") != NULL); free (path); putenv("TEMP="); path = p11_path_expand ("$TEMP/this/is/my/path"); - CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL); + assert (strstr (path, "this/is/my/path") != NULL); free (path); } static void -test_absolute (CuTest *tc) +test_absolute (void) { #ifdef OS_UNIX - CuAssertTrue (tc, p11_path_absolute ("/home")); - CuAssertTrue (tc, !p11_path_absolute ("home")); + assert (p11_path_absolute ("/home")); + assert (!p11_path_absolute ("home")); #else /* OS_WIN32 */ - CuAssertTrue (tc, p11_path_absolute ("C:\\home")); - CuAssertTrue (tc, !p11_path_absolute ("home")); - CuAssertTrue (tc, !p11_path_absolute ("/home")); + assert (p11_path_absolute ("C:\\home")); + assert (!p11_path_absolute ("home")); + assert (p11_path_absolute ("/home")); #endif } +static void +test_parent (void) +{ + check_equals_and_free ("/", p11_path_parent ("/root")); + check_equals_and_free ("/", p11_path_parent ("/root/")); + check_equals_and_free ("/", p11_path_parent ("/root//")); + check_equals_and_free ("/root", p11_path_parent ("/root/second")); + check_equals_and_free ("/root", p11_path_parent ("/root//second")); + check_equals_and_free ("/root", p11_path_parent ("/root//second//")); + check_equals_and_free ("/root", p11_path_parent ("/root///second")); + check_equals_and_free ("/root/second", p11_path_parent ("/root/second/test.file")); + assert_ptr_eq (NULL, p11_path_parent ("/")); + assert_ptr_eq (NULL, p11_path_parent ("//")); + assert_ptr_eq (NULL, p11_path_parent ("")); +} + int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_base); - SUITE_ADD_TEST (suite, test_build); - SUITE_ADD_TEST (suite, test_expand); - SUITE_ADD_TEST (suite, test_absolute); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_base, "/path/base"); + p11_test (test_build, "/path/build"); + p11_test (test_expand, "/path/expand"); + p11_test (test_absolute, "/path/absolute"); + p11_test (test_parent, "/path/parent"); + + return p11_test_run (argc, argv); } diff --git a/common/tests/test-pem.c b/common/tests/test-pem.c index 54a59d6..0c7d60a 100644 --- a/common/tests/test-pem.c +++ b/common/tests/test-pem.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -125,7 +125,6 @@ struct { }; typedef struct { - CuTest *cu; int input_index; int output_index; int parsed; @@ -139,8 +138,8 @@ on_parse_pem_success (const char *type, { Closure *cl = user_data; - CuAssertIntEquals (cl->cu, success_fixtures[cl->input_index].output[cl->output_index].length, length); - CuAssertTrue (cl->cu, memcmp (success_fixtures[cl->input_index].output[cl->output_index].data, contents, + assert_num_eq (success_fixtures[cl->input_index].output[cl->output_index].length, length); + assert (memcmp (success_fixtures[cl->input_index].output[cl->output_index].data, contents, success_fixtures[cl->input_index].output[cl->output_index].length) == 0); cl->output_index++; @@ -148,7 +147,7 @@ on_parse_pem_success (const char *type, } static void -test_pem_success (CuTest *cu) +test_pem_success (void) { Closure cl; int ret; @@ -156,7 +155,6 @@ test_pem_success (CuTest *cu) int j; for (i = 0; success_fixtures[i].input != NULL; i++) { - cl.cu = cu; cl.input_index = i; cl.output_index = 0; cl.parsed = 0; @@ -164,12 +162,12 @@ test_pem_success (CuTest *cu) ret = p11_pem_parse (success_fixtures[i].input, strlen (success_fixtures[i].input), on_parse_pem_success, &cl); - CuAssertTrue (cu, success_fixtures[i].output[cl.output_index].type == NULL); + assert (success_fixtures[i].output[cl.output_index].type == NULL); /* Count number of outputs, return from p11_pem_parse() should match */ for (j = 0; success_fixtures[i].output[j].type != NULL; j++); - CuAssertIntEquals (cu, j, ret); - CuAssertIntEquals (cu, ret, cl.parsed); + assert_num_eq (j, ret); + assert_num_eq (ret, cl.parsed); } } @@ -215,20 +213,19 @@ on_parse_pem_failure (const char *type, size_t length, void *user_data) { - CuTest *cu = user_data; - CuAssertTrue (cu, false && "not reached"); + assert (false && "not reached"); } static void -test_pem_failure (CuTest *cu) +test_pem_failure (void) { int ret; int i; for (i = 0; failure_fixtures[i] != NULL; i++) { ret = p11_pem_parse (failure_fixtures[i], strlen (failure_fixtures[i]), - on_parse_pem_failure, cu); - CuAssertIntEquals (cu, 0, ret); + on_parse_pem_failure, NULL); + assert_num_eq (0, ret); } } @@ -239,11 +236,6 @@ typedef struct { const char *output; } WriteFixture; -typedef struct { - CuTest *cu; - WriteFixture *fixture; -} WriteClosure; - static WriteFixture write_fixtures[] = { { "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87" @@ -303,60 +295,47 @@ on_parse_written (const char *type, size_t length, void *user_data) { - WriteClosure *cl = user_data; + WriteFixture *fixture = user_data; - CuAssertStrEquals (cl->cu, cl->fixture->type, type); - CuAssertIntEquals (cl->cu, cl->fixture->length, length); - CuAssertTrue (cl->cu, memcmp (contents, cl->fixture->input, length) == 0); + assert_str_eq (fixture->type, type); + assert_num_eq (fixture->length, length); + assert (memcmp (contents, fixture->input, length) == 0); } static void -test_pem_write (CuTest *cu) +test_pem_write (void) { WriteFixture *fixture; - WriteClosure cl; - size_t length; - char *output; + p11_buffer buf; unsigned int count; int i; for (i = 0; write_fixtures[i].input != NULL; i++) { fixture = write_fixtures + i; - output = p11_pem_write ((unsigned char *)fixture->input, - fixture->length, - fixture->type, &length); - CuAssertStrEquals (cu, fixture->output, output); - CuAssertIntEquals (cu, strlen (fixture->output), length); + if (!p11_buffer_init_null (&buf, 0)) + assert_not_reached (); - cl.fixture = fixture; - cl.cu = cu; + if (!p11_pem_write ((unsigned char *)fixture->input, + fixture->length, + fixture->type, &buf)) + assert_not_reached (); + assert_str_eq (fixture->output, buf.data); + assert_num_eq (strlen (fixture->output), buf.len); - count = p11_pem_parse (output, length, on_parse_written, &cl); - CuAssertIntEquals (cu, 1, count); + count = p11_pem_parse (buf.data, buf.len, on_parse_written, fixture); + assert_num_eq (1, count); - free (output); + p11_buffer_uninit (&buf); } } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_pem_success); - SUITE_ADD_TEST (suite, test_pem_failure); - SUITE_ADD_TEST (suite, test_pem_write); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_pem_success, "/pem/success"); + p11_test (test_pem_failure, "/pem/failure"); + p11_test (test_pem_write, "/pem/write"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-url.c b/common/tests/test-url.c index ed84f0c..892bf3c 100644 --- a/common/tests/test-url.c +++ b/common/tests/test-url.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include "debug.h" #include "message.h" @@ -46,9 +46,9 @@ #include "url.h" static void -check_decode_msg (CuTest *tc, - const char *file, +check_decode_msg (const char *file, int line, + const char *function, const char *input, ssize_t input_len, const char *expected, @@ -62,106 +62,103 @@ check_decode_msg (CuTest *tc, decoded = p11_url_decode (input, input + input_len, "", &length); if (expected == NULL) { - CuAssert_Line (tc, file, line, "decoding should have failed", decoded == NULL); + if (decoded != NULL) + p11_test_fail (file, line, function, "decoding should have failed"); } else { - CuAssert_Line (tc, file, line, "decoding failed", decoded != NULL); - CuAssertIntEquals_LineMsg (tc, file, line, "wrong length", expected_len, length); - CuAssert_Line (tc, file, line, "decoded wrong", memcmp (decoded, expected, length) == 0); + if (decoded == NULL) + p11_test_fail (file, line, function, "decoding failed"); + if (expected_len != length) + p11_test_fail (file, line, function, "wrong length: (%lu != %lu)", + (unsigned long)expected_len, (unsigned long)length); + if (memcmp (decoded, expected, length) != 0) + p11_test_fail (file, line, function, "decoding wrong"); free (decoded); } } -#define check_decode_success(tc, input, input_len, expected, expected_len) \ - check_decode_msg (tc, __FILE__, __LINE__, input, input_len, expected, expected_len) +#define check_decode_success(input, input_len, expected, expected_len) \ + check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, expected, expected_len) -#define check_decode_failure(tc, input, input_len) \ - check_decode_msg (tc, __FILE__, __LINE__, input, input_len, NULL, 0) +#define check_decode_failure(input, input_len) \ + check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, NULL, 0) static void -test_decode_success (CuTest *tc) +test_decode_success (void) { - check_decode_success (tc, "%54%45%53%54%00", -1, "TEST", 5); - check_decode_success (tc, "%54%45%53%54%00", 6, "TE", 2); - check_decode_success (tc, "%54est%00", -1, "Test", 5); + check_decode_success ("%54%45%53%54%00", -1, "TEST", 5); + check_decode_success ("%54%45%53%54%00", 6, "TE", 2); + check_decode_success ("%54est%00", -1, "Test", 5); } static void -test_decode_skip (CuTest *tc) +test_decode_skip (void) { const char *input = "%54 %45 %53 %54 %00"; unsigned char *decoded; size_t length; decoded = p11_url_decode (input, input + strlen (input), P11_URL_WHITESPACE, &length); - CuAssertStrEquals (tc, "TEST", (char *)decoded); - CuAssertIntEquals (tc, 5, length); + assert_str_eq ("TEST", (char *)decoded); + assert_num_eq (5, length); free (decoded); } static void -test_decode_failure (CuTest *tc) +test_decode_failure (void) { /* Early termination */ - check_decode_failure (tc, "%54%45%53%5", -1); - check_decode_failure (tc, "%54%45%53%", -1); + check_decode_failure ("%54%45%53%5", -1); + check_decode_failure ("%54%45%53%", -1); /* Not hex characters */ - check_decode_failure (tc, "%54%XX%53%54%00", -1); + check_decode_failure ("%54%XX%53%54%00", -1); } static void -test_encode (CuTest *tc) +test_encode (void) { const unsigned char *input = (unsigned char *)"TEST"; - char *encoded; - size_t length; + p11_buffer buf; + + if (!p11_buffer_init_null (&buf, 5)) + assert_not_reached (); - encoded = p11_url_encode (input, input + 5, "", &length); - CuAssertStrEquals (tc, "%54%45%53%54%00", (char *)encoded); - CuAssertIntEquals (tc, 15, length); + p11_url_encode (input, input + 5, "", &buf); + assert (p11_buffer_ok (&buf)); + assert_str_eq ("%54%45%53%54%00", (char *)buf.data); + assert_num_eq (15, buf.len); - free (encoded); + p11_buffer_uninit (&buf); } static void -test_encode_verbatim (CuTest *tc) +test_encode_verbatim (void) { const unsigned char *input = (unsigned char *)"TEST"; - char *encoded; - size_t length; + p11_buffer buf; - encoded = p11_url_encode (input, input + 5, "ES", &length); - CuAssertStrEquals (tc, "%54ES%54%00", (char *)encoded); - CuAssertIntEquals (tc, 11, length); + if (!p11_buffer_init_null (&buf, 5)) + assert_not_reached (); - free (encoded); + p11_url_encode (input, input + 5, "ES", &buf); + assert (p11_buffer_ok (&buf)); + assert_str_eq ("%54ES%54%00", (char *)buf.data); + assert_num_eq (11, buf.len); + + p11_buffer_uninit (&buf); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_decode_success); - SUITE_ADD_TEST (suite, test_decode_skip); - SUITE_ADD_TEST (suite, test_decode_failure); - - SUITE_ADD_TEST (suite, test_encode); - SUITE_ADD_TEST (suite, test_encode_verbatim); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - return ret; + p11_test (test_decode_success, "/url/decode-success"); + p11_test (test_decode_skip, "/url/decode-skip"); + p11_test (test_decode_failure, "/url/decode-failure"); + + p11_test (test_encode, "/url/encode"); + p11_test (test_encode_verbatim, "/url/encode-verbatim"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-utf8.c b/common/tests/test-utf8.c index ed13fa2..9b2c3d5 100644 --- a/common/tests/test-utf8.c +++ b/common/tests/test-utf8.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include "utf8.h" @@ -43,7 +43,7 @@ #define ELEMS(x) (sizeof (x) / sizeof (x[0])) static void -test_ucs2be (CuTest *cu) +test_ucs2be (void) { char *output; size_t length; @@ -73,14 +73,14 @@ test_ucs2be (CuTest *cu) fixtures[i].input_len, &length); - CuAssertIntEquals (cu, fixtures[i].output_len, length); - CuAssertStrEquals (cu, fixtures[i].output, output); + assert_num_eq (fixtures[i].output_len, length); + assert_str_eq (fixtures[i].output, output); free (output); } } static void -test_ucs2be_fail (CuTest *cu) +test_ucs2be_fail (void) { char *output; size_t length; @@ -97,12 +97,12 @@ test_ucs2be_fail (CuTest *cu) output = p11_utf8_for_ucs2be (fixtures[i].input, fixtures[i].input_len, &length); - CuAssertPtrEquals (cu, NULL, output); + assert_ptr_eq (NULL, output); } } static void -test_ucs4be (CuTest *cu) +test_ucs4be (void) { char *output; size_t length; @@ -146,15 +146,15 @@ test_ucs4be (CuTest *cu) fixtures[i].input_len, &length); - CuAssertIntEquals (cu, fixtures[i].output_len, length); - CuAssertStrEquals (cu, fixtures[i].output, output); + assert_num_eq (fixtures[i].output_len, length); + assert_str_eq (fixtures[i].output, output); free (output); } } static void -test_ucs4be_fail (CuTest *cu) +test_ucs4be_fail (void) { char *output; size_t length; @@ -179,12 +179,12 @@ test_ucs4be_fail (CuTest *cu) output = p11_utf8_for_ucs4be (fixtures[i].input, fixtures[i].input_len, &length); - CuAssertPtrEquals (cu, NULL, output); + assert_ptr_eq (NULL, output); } } static void -test_utf8 (CuTest *cu) +test_utf8 (void) { bool ret; int i; @@ -203,12 +203,12 @@ test_utf8 (CuTest *cu) for (i = 0; i < ELEMS (fixtures); i++) { ret = p11_utf8_validate (fixtures[i].input, fixtures[i].input_len); - CuAssertIntEquals (cu, true, ret); + assert_num_eq (true, ret); } } static void -test_utf8_fail (CuTest *cu) +test_utf8_fail (void) { bool ret; int i; @@ -226,31 +226,19 @@ test_utf8_fail (CuTest *cu) for (i = 0; i < ELEMS (fixtures); i++) { ret = p11_utf8_validate (fixtures[i].input, fixtures[i].input_len); - CuAssertIntEquals (cu, false, ret); + assert_num_eq (false, ret); } } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - SUITE_ADD_TEST (suite, test_ucs2be); - SUITE_ADD_TEST (suite, test_ucs2be_fail); - SUITE_ADD_TEST (suite, test_ucs4be); - SUITE_ADD_TEST (suite, test_ucs4be_fail); - SUITE_ADD_TEST (suite, test_utf8); - SUITE_ADD_TEST (suite, test_utf8_fail); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_test (test_ucs2be, "/utf8/ucs2be"); + p11_test (test_ucs2be_fail, "/utf8/ucs2be_fail"); + p11_test (test_ucs4be, "/utf8/ucs4be"); + p11_test (test_ucs4be_fail, "/utf8/ucs4be_fail"); + p11_test (test_utf8, "/utf8/utf8"); + p11_test (test_utf8_fail, "/utf8/utf8_fail"); + return p11_test_run (argc, argv); } diff --git a/common/tests/test-x509.c b/common/tests/test-x509.c index 2596c9c..9f7d258 100644 --- a/common/tests/test-x509.c +++ b/common/tests/test-x509.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include "asn1.h" #include "debug.h" @@ -51,14 +51,14 @@ struct { } test; static void -setup (CuTest *cu) +setup (void *unused) { test.asn1_defs = p11_asn1_defs_load (); - CuAssertPtrNotNull (cu, test.asn1_defs); + assert_ptr_not_null (test.asn1_defs); } static void -teardown (CuTest *cu) +teardown (void *unused) { p11_dict_free (test.asn1_defs); memset (&test, 0, sizeof (test)); @@ -226,29 +226,25 @@ struct { }; static void -test_parse_extended_key_usage (CuTest *cu) +test_parse_extended_key_usage (void) { p11_array *ekus; int i, j, count; - setup (cu); - for (i = 0; extended_key_usage_fixtures[i].eku != NULL; i++) { ekus = p11_x509_parse_extended_key_usage (test.asn1_defs, (const unsigned char *)extended_key_usage_fixtures[i].eku, extended_key_usage_fixtures[i].length); - CuAssertPtrNotNull (cu, ekus); + assert_ptr_not_null (ekus); for (count = 0; extended_key_usage_fixtures[i].expected[count] != NULL; count++); - CuAssertIntEquals (cu, count, ekus->num); + assert_num_eq (count, ekus->num); for (j = 0; j < count; j++) - CuAssertStrEquals (cu, ekus->elem[j], extended_key_usage_fixtures[i].expected[j]); + assert_str_eq (ekus->elem[j], extended_key_usage_fixtures[i].expected[j]); p11_array_free (ekus); } - - teardown (cu); } struct { @@ -263,82 +259,70 @@ struct { }; static void -test_parse_key_usage (CuTest *cu) +test_parse_key_usage (void) { unsigned int ku; int i; bool ret; - setup (cu); - for (i = 0; key_usage_fixtures[i].ku != NULL; i++) { ku = 0; ret = p11_x509_parse_key_usage (test.asn1_defs, (const unsigned char *)key_usage_fixtures[i].ku, key_usage_fixtures[i].length, &ku); - CuAssertIntEquals (cu, true, ret); + assert_num_eq (true, ret); - CuAssertIntEquals (cu, key_usage_fixtures[i].expected, ku); + assert_num_eq (key_usage_fixtures[i].expected, ku); } - - teardown (cu); } static void -test_parse_extension (CuTest *cu) +test_parse_extension (void) { node_asn *cert; unsigned char *ext; size_t length; bool is_ca; - setup (cu); - cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate", test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL); - CuAssertPtrNotNull (cu, cert); + assert_ptr_not_null (cert); ext = p11_x509_find_extension (cert, P11_OID_BASIC_CONSTRAINTS, test_cacert3_ca_der, sizeof (test_cacert3_ca_der), &length); - CuAssertPtrNotNull (cu, ext); - CuAssertTrue (cu, length > 0); + assert_ptr_not_null (ext); + assert (length > 0); asn1_delete_structure (&cert); if (!p11_x509_parse_basic_constraints (test.asn1_defs, ext, length, &is_ca)) - CuFail (cu, "failed to parse message"); + assert_fail ("failed to parse message", "basic constraints"); free (ext); - - teardown (cu); } static void -test_parse_extension_not_found (CuTest *cu) +test_parse_extension_not_found (void) { node_asn *cert; unsigned char *ext; size_t length; - setup (cu); - cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate", test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL); - CuAssertPtrNotNull (cu, cert); + assert_ptr_not_null (cert); ext = p11_x509_find_extension (cert, P11_OID_OPENSSL_REJECT, test_cacert3_ca_der, sizeof (test_cacert3_ca_der), &length); - CuAssertPtrEquals (cu, NULL, ext); + assert_ptr_eq (NULL, ext); asn1_delete_structure (&cert); - - teardown (cu); } static void -test_directory_string (CuTest *tc) +test_directory_string (void) { struct { unsigned char input[100]; @@ -392,17 +376,17 @@ test_directory_string (CuTest *tc) string = p11_x509_parse_directory_string (fixtures[i].input, fixtures[i].input_len, &unknown, &length); - CuAssertPtrNotNull (tc, string); - CuAssertIntEquals (tc, false, unknown); + assert_ptr_not_null (string); + assert_num_eq (false, unknown); - CuAssertIntEquals (tc, fixtures[i].output_len, length); - CuAssertStrEquals (tc, fixtures[i].output, string); + assert_num_eq (fixtures[i].output_len, length); + assert_str_eq (fixtures[i].output, string); free (string); } } static void -test_directory_string_unknown (CuTest *tc) +test_directory_string_unknown (void) { /* Not a valid choice in DirectoryString */ unsigned char input[] = { 0x05, 0x07, 'A', ' ', ' ', 'n', 'i', 'c', 'e' }; @@ -411,34 +395,22 @@ test_directory_string_unknown (CuTest *tc) size_t length; string = p11_x509_parse_directory_string (input, sizeof (input), &unknown, &length); - CuAssertPtrEquals (tc, NULL, string); - CuAssertIntEquals (tc, true, unknown); + assert_ptr_eq (NULL, string); + assert_num_eq (true, unknown); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_parse_extended_key_usage); - SUITE_ADD_TEST (suite, test_parse_key_usage); - SUITE_ADD_TEST (suite, test_parse_extension); - SUITE_ADD_TEST (suite, test_parse_extension_not_found); - SUITE_ADD_TEST (suite, test_directory_string); - SUITE_ADD_TEST (suite, test_directory_string_unknown); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_fixture (setup, teardown); + p11_test (test_parse_extended_key_usage, "/x509/parse-extended-key-usage"); + p11_test (test_parse_key_usage, "/x509/parse-key-usage"); + p11_test (test_parse_extension, "/x509/parse-extension"); + p11_test (test_parse_extension_not_found, "/x509/parse-extension-not-found"); + + p11_fixture (NULL, NULL); + p11_test (test_directory_string, "/x509/directory-string"); + p11_test (test_directory_string_unknown, "/x509/directory-string-unknown"); + return p11_test_run (argc, argv); } diff --git a/common/url.c b/common/url.c index 6ccf74d..4b7e47b 100644 --- a/common/url.c +++ b/common/url.c @@ -103,40 +103,31 @@ p11_url_decode (const char *value, return result; } -char * +void p11_url_encode (const unsigned char *value, const unsigned char *end, const char *verbatim, - size_t *length) + p11_buffer *buf) { - char *p; - char *result; + char hex[3]; assert (value <= end); - /* Just allocate for worst case */ - result = malloc (((end - value) * 3) + 1); - return_val_if_fail (result != NULL, NULL); - /* Now loop through looking for escapes */ - p = result; while (value != end) { /* These characters we let through verbatim */ if (*value && strchr (verbatim, *value) != NULL) { - *(p++) = *(value++); + p11_buffer_add (buf, value, 1); /* All others get encoded */ } else { - *(p++) = '%'; - *(p++) = HEX_CHARS[((unsigned char)*value) >> 4]; - *(p++) = HEX_CHARS[((unsigned char)*value) & 0x0F]; - ++value; + hex[0] = '%'; + hex[1] = HEX_CHARS[((unsigned char)*value) >> 4]; + hex[2] = HEX_CHARS[((unsigned char)*value) & 0x0F]; + p11_buffer_add (buf, hex, 3); } - } - *p = 0; - if (length) - *length = p - result; - return result; + ++value; + } } diff --git a/common/url.h b/common/url.h index fa7938a..4ab1e43 100644 --- a/common/url.h +++ b/common/url.h @@ -36,6 +36,7 @@ #ifndef P11_URL_H #define P11_URL_H +#include "buffer.h" #include "compat.h" #include <stdlib.h> @@ -51,9 +52,9 @@ unsigned char * p11_url_decode (const char *value, const char *skip, size_t *length); -char * p11_url_encode (const unsigned char *value, +void p11_url_encode (const unsigned char *value, const unsigned char *end, const char *verbatim, - size_t *length); + p11_buffer *buf); #endif /* P11_URL_H */ |