#include "p11-tests.h" #include #include int p11t_check_verbose = 0; int p11t_check_fail(const char *message, ...) { va_list va; va_start(va, message); p11t_msg_code("FAIL", message, va); va_end(va); return STOP; } int p11t_check_info(const char *message, ...) { va_list va; if(!p11t_check_verbose) return CONTINUE; va_start(va, message); p11t_msg_code("INFO", message, va); va_end(va); return CONTINUE; } int p11t_check_warn(const char *message, ...) { va_list va; va_start(va, message); p11t_msg_code("WARN", message, va); va_end(va); return CONTINUE; } int _p11t_check_rv(const char *what, CK_RV have, CK_RV want) { if(have != want) { if(have == CKR_FUNCTION_NOT_SUPPORTED) p11t_check_info("Not supported"); else p11t_check_fail("%s: expected %s but got %s", what, p11t_msg_rv(want), p11t_msg_rv(have)); return STOP; } return CONTINUE; } int _p11t_check_padded(const char *what, const CK_UTF8CHAR_PTR padded, CK_ULONG length) { CK_ULONG i; for(i = 0; i < length; ++i) { if(!isprint(padded[i])) { p11t_check_fail("%s: non printable character: %d", what, padded[i]); return STOP; } if(!padded[i]) { p11t_check_fail("%s: not blank padded", what); return STOP; } } return CONTINUE; } int _p11t_check_ulong(const char *what, CK_ULONG have, CK_ULONG want) { if(have != want) { p11t_check_fail("%s: expected 0x%08x but have 0x%08x", what, want, have); return STOP; } return CONTINUE; } int _p11t_check_bool(const char *what, CK_BBOOL value) { if(value != CK_FALSE && value != CK_TRUE) { p11t_check_fail("%s: expected CK_TRUE or CK_FALSE but got 0x%02x", what, (int)value); return STOP; } return CONTINUE; } int _p11t_check_string(const char *what, CK_UTF8CHAR_PTR value, CK_ULONG length) { CK_ULONG i; for(i = 0; i < length; ++i) { if(!value[i]) { p11t_check_fail("%s: is null terminated", what); return STOP; } } return CONTINUE; } int _p11t_check_mask(const char *what, CK_ULONG flags, CK_ULONG mask) { if((flags & ~mask) != 0) { p11t_check_fail("%s: extra flags outside of mask: 0x%08x", what, (flags & ~mask)); return STOP; } return CONTINUE; } int _p11t_check_flag(const char *what, CK_ULONG flags, CK_ULONG flag) { if((flags & flag) != flag) { p11t_check_fail("%s: flag 0x%08x should be set in: 0x%08x", what, flag, flags); return STOP; } return CONTINUE; } int _p11t_check_nflag(const char *what, CK_ULONG flags, CK_ULONG nflag) { if((flags & nflag) != 0) { p11t_check_fail("%s: flag 0x%08x should not be set in: 0x%08x", what, nflag, flags); return STOP; } return CONTINUE; }