Skip to content

Commit

Permalink
p11test: Formatting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakuje committed Jan 24, 2024
1 parent 279d89e commit 6cc1009
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 68 deletions.
24 changes: 12 additions & 12 deletions src/tests/p11test/p11test_case_ec_derive.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ pkcs11_derive(test_cert_t *o, token_info_t * info,
CK_BBOOL _true = TRUE;
CK_BBOOL _false = FALSE;
CK_ATTRIBUTE template[] = {
{CKA_TOKEN, &_false, sizeof(_false)}, /* session only object */
{CKA_CLASS, &newkey_class, sizeof(newkey_class)},
{CKA_ID, &newkey_id, sizeof(newkey_id)},
{CKA_LABEL, &newkey_label, sizeof(newkey_label)},
{CKA_KEY_TYPE, &newkey_type, sizeof(newkey_type)},
{CKA_VALUE_LEN, &newkey_len, sizeof(newkey_len)},
{CKA_SENSITIVE, &_false, sizeof(_false)},
{CKA_EXTRACTABLE, &_true, sizeof(_true)},
{CKA_ENCRYPT, &_true, sizeof(_true)},
{CKA_DECRYPT, &_true, sizeof(_true)},
{CKA_WRAP, &_true, sizeof(_true)},
{CKA_UNWRAP, &_true, sizeof(_true)}
{CKA_TOKEN, &_false, sizeof(_false)}, /* session only object */
{CKA_CLASS, &newkey_class, sizeof(newkey_class)},
{CKA_ID, &newkey_id, sizeof(newkey_id)},
{CKA_LABEL, &newkey_label, sizeof(newkey_label)},
{CKA_KEY_TYPE, &newkey_type, sizeof(newkey_type)},
{CKA_VALUE_LEN, &newkey_len, sizeof(newkey_len)},
{CKA_SENSITIVE, &_false, sizeof(_false)},
{CKA_EXTRACTABLE, &_true, sizeof(_true)},
{CKA_ENCRYPT, &_true, sizeof(_true)},
{CKA_DECRYPT, &_true, sizeof(_true)},
{CKA_WRAP, &_true, sizeof(_true)},
{CKA_UNWRAP, &_true, sizeof(_true)},
};
CK_ATTRIBUTE get_value = {CKA_VALUE, NULL_PTR, 0};
CK_ULONG template_len = 10;
Expand Down
39 changes: 19 additions & 20 deletions src/tests/p11test/p11test_case_readonly.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,35 +707,34 @@ void readonly_tests(void **state) {
/* do the Sign&Verify and/or Encrypt&Decrypt */
used = 0;
if (o->private_handle == CK_INVALID_HANDLE) {
debug_print(" [SKIP %s ] Missing private key",
o->id_str);
debug_print(" [SKIP %s ] Missing private key", o->id_str);
continue;
}
/* XXX some keys do not have appropriate flags, but we can use them
* or vice versa */
//if (o->sign && o->verify)
for (j = 0; j < o->num_mechs; j++) {
test_mech_t *m = &(objects.data[i].mechs[j]);
if ((m->usage_flags & CKF_SIGN) == 0) {
/* Skip non-signature mechanisms (for example derive ones) */
continue;
}
used |= sign_verify_test(o, info, m, 32, 0);
// if (o->sign && o->verify)
for (j = 0; j < o->num_mechs; j++) {
test_mech_t *m = &(objects.data[i].mechs[j]);
if ((m->usage_flags & CKF_SIGN) == 0) {
/* Skip non-signature mechanisms (for example derive ones) */
continue;
}
used |= sign_verify_test(o, info, m, 32, 0);
}

//if (o->encrypt && o->decrypt)
for (j = 0; j < o->num_mechs; j++) {
test_mech_t *m = &(objects.data[i].mechs[j]);
if ((m->usage_flags & CKF_DECRYPT) == 0) {
/* Skip non-decrypt mechanisms (for example derive ones) */
continue;
}
used |= encrypt_decrypt_test(o, info, m, 32, 0);
// if (o->encrypt && o->decrypt)
for (j = 0; j < o->num_mechs; j++) {
test_mech_t *m = &(objects.data[i].mechs[j]);
if ((m->usage_flags & CKF_DECRYPT) == 0) {
/* Skip non-decrypt mechanisms (for example derive ones) */
continue;
}
used |= encrypt_decrypt_test(o, info, m, 32, 0);
}

if (!used) {
debug_print(" [ WARN %s ] Private key with unknown purpose T:%02lX",
o->id_str, o->key_type);
debug_print(" [WARN %s ] Private key with unknown purpose T:%02lX", o->id_str,
o->key_type);
}
}

Expand Down
72 changes: 36 additions & 36 deletions src/tests/p11test/p11test_case_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,43 @@ void usage_test(void **state) {
continue;

printf("[ %s ] [%6lu] [ %s ] [%s%s] [%s%s] [%s %s] [%s%s] [ %s ]\n",
(o->key_type == CKK_RSA ? "RSA " :
o->key_type == CKK_EC ? " EC " :
o->key_type == CKK_EC_EDWARDS ? "EC_E" :
o->key_type == CKK_EC_MONTGOMERY ? "EC_M" :
o->key_type == CKK_AES ? "AES " :
o->key_type == CKK_GENERIC_SECRET ? "GEN " : " ?? "),
o->bits,
o->verify_public == 1 ? " ./ " : " ",
o->sign ? "[./] " : "[ ] ",
o->verify ? " [./] " : " [ ] ",
o->encrypt ? "[./] " : "[ ] ",
o->decrypt ? " [./] " : " [ ] ",
o->wrap ? "[./]" : "[ ]",
o->unwrap ? "[./]" : "[ ]",
o->derive_pub ? "[./]" : "[ ]",
o->derive_priv ? "[./]" : "[ ]",
o->always_auth ? "[./]" : "[ ]");
(o->key_type == CKK_RSA ? "RSA " : o->key_type == CKK_EC ? " EC "
: o->key_type == CKK_EC_EDWARDS ? "EC_E"
: o->key_type == CKK_EC_MONTGOMERY ? "EC_M"
: o->key_type == CKK_AES ? "AES "
: o->key_type == CKK_GENERIC_SECRET ? "GEN "
: " ?? "),
o->bits,
o->verify_public == 1 ? " ./ " : " ",
o->sign ? "[./] " : "[ ] ",
o->verify ? " [./] " : " [ ] ",
o->encrypt ? "[./] " : "[ ] ",
o->decrypt ? " [./] " : " [ ] ",
o->wrap ? "[./]" : "[ ]",
o->unwrap ? "[./]" : "[ ]",
o->derive_pub ? "[./]" : "[ ]",
o->derive_priv ? "[./]" : "[ ]",
o->always_auth ? "[./]" : "[ ]");
P11TEST_DATA_ROW(info, 14,
's', o->id_str,
's', o->label,
's', (o->key_type == CKK_RSA ? "RSA" :
o->key_type == CKK_EC ? "EC" :
o->key_type == CKK_EC_EDWARDS ? "EC_E" :
o->key_type == CKK_EC_MONTGOMERY ? "EC_M" :
o->key_type == CKK_AES ? "AES" :
o->key_type == CKK_GENERIC_SECRET ? "GEN" : " ?? "),
'd', o->bits,
's', o->verify_public == 1 ? "YES" : "",
's', o->sign ? "YES" : "",
's', o->verify ? "YES" : "",
's', o->encrypt ? "YES" : "",
's', o->decrypt ? "YES" : "",
's', o->wrap ? "YES" : "",
's', o->unwrap ? "YES" : "",
's', o->derive_pub ? "YES" : "",
's', o->derive_priv ? "YES" : "",
's', o->always_auth ? "YES" : "");
's', o->id_str,
's', o->label,
's', (o->key_type == CKK_RSA ? "RSA" : o->key_type == CKK_EC ? "EC"
: o->key_type == CKK_EC_EDWARDS ? "EC_E"
: o->key_type == CKK_EC_MONTGOMERY ? "EC_M"
: o->key_type == CKK_AES ? "AES"
: o->key_type == CKK_GENERIC_SECRET ? "GEN"
: " ?? "),
'd', o->bits,
's', o->verify_public == 1 ? "YES" : "",
's', o->sign ? "YES" : "",
's', o->verify ? "YES" : "",
's', o->encrypt ? "YES" : "",
's', o->decrypt ? "YES" : "",
's', o->wrap ? "YES" : "",
's', o->unwrap ? "YES" : "",
's', o->derive_pub ? "YES" : "",
's', o->derive_priv ? "YES" : "",
's', o->always_auth ? "YES" : "");
}
printf(" Public == Cert -----^ ^-----^ ^-----^ ^----^ ^---^\n");
printf(" Sign & Verify Attributes ------' | | |\n");
Expand Down

0 comments on commit 6cc1009

Please sign in to comment.