27static void test_domains1(
void) {
32 {
"1", 1}, {
"1,2:3,4|5,6;7,8,9,10,11,12,13,14,15,16", 0xffff},
33 {
"1,16", 0x8001}, {
"16", 0x8000},
34 {
"16,15", 0xc000}, {
"1,0xf", 0x4001},
35 {
"0x1,0x2", 3}, {
"0x8888", 0x8888},
36 {
"0", 0}, {
"all", 0xffff},
37 {
"2", 2}, {
"2:4", 10},
40 for (
size_t i = 0; i <
sizeof(tests) /
sizeof(tests[0]); i++) {
47static void test_domains2(
void) {
55 {0xffff,
"1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16"},
58 for (
size_t i = 0; i <
sizeof(tests) /
sizeof(tests[0]); i++) {
61 assert(strcmp(
s, tests[i].
string) == 0);
65static void test_capabilities1(
void) {
70 {
"get-opaque", {
"\x00\x00\x00\x00\x00\x00\x00\x01"}},
71 {
"sign-hmac:verify-hmac|exportable-under-wrap,",
72 {
"\x00\x00\x00\x00\x00\xc1\x00\x00"}},
73 {
",,unwrap-data|:wrap-data,,,", {
"\x00\x00\x00\x60\x00\x00\x00\x00"}},
74 {
"0x7fffffffffffffff", {
"\x7f\xff\xff\xff\xff\xff\xff\xff"}},
75 {
"0xffffffffffffffff", {
"\xff\xff\xff\xff\xff\xff\xff\xff"}},
78 for (
size_t i = 0; i <
sizeof(tests) /
sizeof(tests[0]); i++) {
81 assert(memcmp(&c, &tests[i].
capabilities,
sizeof(c)) == 0);
85static void test_capabilities2(
void) {
89 const char *capabilities_array[8];
90 size_t capabilities_array_len;
91 char *capabilities_list[] = {
"sign-pkcs",
"decrypt-pkcs",
92 "export-wrapped",
"set-option",
93 "get-pseudo-random",
"sign-hmac",
94 "verify-hmac",
"get-log-entries"};
95 char capabilities_string[1024];
99 i <
sizeof(capabilities_list) /
sizeof(capabilities_list[0]); i++) {
100 sprintf(capabilities_string +
len,
"%s:", capabilities_list[i]);
101 len += strlen(capabilities_list[i]) + 1;
103 capabilities_string[
len - 1] =
'\0';
122 capabilities_array_len = 1;
124 &capabilities_array_len);
127 capabilities_array_len =
128 sizeof(capabilities_array) /
sizeof(capabilities_array[0]);
130 &capabilities_array_len);
133 i <
sizeof(capabilities_list) /
sizeof(capabilities_list[0]); i++) {
135 for (
j = 0;
j < capabilities_array_len;
j++) {
136 if (strcmp(capabilities_list[i], capabilities_array[
j]) == 0) {
140 assert(
j < capabilities_array_len);
144static void test_capabilities3(
void) {
145 const char *cap1 =
"sign-pkcs,sign-pss";
146 const char *cap2 =
"decrypt-pkcs,decrypt-oaep";
147 const char *cap3 =
"sign-pss,decrypt-oaep";
172static void test_algorithms(
void) {
198static void test_options(
void) {
243 assert(
yrc ==
YHR_SUCCESS && strcmp(
string,
"authentication-key") == 0);
245 assert(
yrc ==
YHR_SUCCESS && strcmp(
string,
"asymmetric-key") == 0);
253 assert(
yrc ==
YHR_SUCCESS && strcmp(
string,
"otp-aead-key") == 0);
260 test_capabilities1();
261 test_capabilities2();
262 test_capabilities3();
Capabilities representation.
std::tuple< uint64_t, std::array< char, 6733 > > test_types
yh_rc yh_domains_to_string(uint16_t domains, char *string, size_t max_len)
yh_rc yh_string_to_option(const char *string, yh_option *option)
yh_rc yh_string_to_type(const char *string, yh_object_type *type)
yh_rc yh_filter_capabilities(const yh_capabilities *capabilities, const yh_capabilities *filter, yh_capabilities *result)
yh_rc yh_string_to_domains(const char *domains, uint16_t *result)
yh_rc yh_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_string_to_algo(const char *string, yh_algorithm *algo)
bool yh_check_capability(const yh_capabilities *capabilities, const char *capability)
yh_rc yh_capabilities_to_strings(const yh_capabilities *num, const char *result[], size_t *n_result)
bool yh_is_hmac(yh_algorithm algorithm)
yh_rc yh_merge_capabilities(const yh_capabilities *a, const yh_capabilities *b, yh_capabilities *result)
yh_rc yh_type_to_string(yh_object_type type, char const **result)
@ YH_OTP_AEAD_KEY
OTP AEAD Key is a secret key used to decrypt Yubico OTP values.
@ YH_HMAC_KEY
HMAC Key is a secret key used when computing and verifying HMAC signatures.
@ YH_ASYMMETRIC_KEY
Asymmetric Key is the private key of an asymmetric key-pair.
@ YH_AUTHENTICATION_KEY
Authentication Key is used to establish Sessions with a device.
@ YH_ALGO_MGF1_SHA512
mgf1-sha512
@ YH_ALGO_RSA_PKCS1_SHA1
rsa-pkcs1-sha1
@ YH_ALGO_HMAC_SHA512
hmac-sha512
@ YH_ALGO_HMAC_SHA384
hmac-sha384
@ YH_ALGO_HMAC_SHA1
hmac-sha1
@ YH_ALGO_RSA_2048
rsa2048
@ YH_ALGO_HMAC_SHA256
hmac-sha256
@ YH_OPTION_FORCE_AUDIT
Enable/Disable Forced Audit mode.
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
@ YHR_INVALID_PARAMETERS
Returned value when an argument to a function is invalid.
@ YHR_BUFFER_TOO_SMALL
Returned value when there is not enough space to store data.
yh_capabilities capabilities