summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/extract-info.c13
-rw-r--r--tools/tests/test-extract.c50
2 files changed, 61 insertions, 2 deletions
diff --git a/tools/extract-info.c b/tools/extract-info.c
index aa66c83..ee6dbe1 100644
--- a/tools/extract-info.c
+++ b/tools/extract-info.c
@@ -316,9 +316,18 @@ void
p11_extract_info_limit_purpose (p11_extract_info *ex,
const char *purpose)
{
- if (!ex->limit_to_purposes)
+ char *value;
+
+ if (!ex->limit_to_purposes) {
ex->limit_to_purposes = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, NULL);
- p11_dict_set (ex->limit_to_purposes, strdup (purpose), NULL);
+ return_if_fail (ex->limit_to_purposes != NULL);
+ }
+
+ value = strdup (purpose);
+ return_if_fail (value != NULL);
+
+ if (!p11_dict_set (ex->limit_to_purposes, value, value))
+ return_if_reached ();
}
static char *
diff --git a/tools/tests/test-extract.c b/tools/tests/test-extract.c
index 8bdd600..5e2f6fe 100644
--- a/tools/tests/test-extract.c
+++ b/tools/tests/test-extract.c
@@ -272,6 +272,54 @@ test_info_skip_non_certificate (CuTest *tc)
teardown (tc);
}
+static void
+test_limit_to_purpose_match (CuTest *tc)
+{
+ CK_RV rv;
+
+ setup (tc);
+
+ mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
+ mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
+
+ p11_extract_info_limit_purpose (&test.ex, P11_OID_SERVER_AUTH_STR);
+ p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
+ p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
+
+ p11_message_quiet ();
+
+ rv = p11_kit_iter_next (test.iter);
+ CuAssertIntEquals (tc, CKR_OK, rv);
+
+ p11_message_loud ();
+
+ teardown (tc);
+}
+
+static void
+test_limit_to_purpose_no_match (CuTest *tc)
+{
+ CK_RV rv;
+
+ setup (tc);
+
+ mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs);
+ mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client);
+
+ p11_extract_info_limit_purpose (&test.ex, "3.3.3.3");
+ p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL);
+ p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
+
+ p11_message_quiet ();
+
+ rv = p11_kit_iter_next (test.iter);
+ CuAssertIntEquals (tc, CKR_CANCEL, rv);
+
+ p11_message_loud ();
+
+ teardown (tc);
+}
+
int
main (void)
{
@@ -290,6 +338,8 @@ main (void)
SUITE_ADD_TEST (suite, test_info_limit_purposes);
SUITE_ADD_TEST (suite, test_info_invalid_purposes);
SUITE_ADD_TEST (suite, test_info_skip_non_certificate);
+ SUITE_ADD_TEST (suite, test_limit_to_purpose_match);
+ SUITE_ADD_TEST (suite, test_limit_to_purpose_no_match);
CuSuiteRun (suite);
CuSuiteSummary (suite, output);