summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/manual/p11-kit-sections.txt1
-rw-r--r--p11-kit/iter.c25
-rw-r--r--p11-kit/iter.h2
-rw-r--r--p11-kit/tests/test-iter.c32
4 files changed, 56 insertions, 4 deletions
diff --git a/doc/manual/p11-kit-sections.txt b/doc/manual/p11-kit-sections.txt
index 2780c7f..efd0cc6 100644
--- a/doc/manual/p11-kit-sections.txt
+++ b/doc/manual/p11-kit-sections.txt
@@ -107,6 +107,7 @@ p11_kit_iter_begin_with
p11_kit_iter_next
p11_kit_iter_get_module
p11_kit_iter_get_slot
+p11_kit_iter_get_token
p11_kit_iter_get_session
p11_kit_iter_keep_session
p11_kit_iter_get_object
diff --git a/p11-kit/iter.c b/p11-kit/iter.c
index 3f26eda..61d0ee3 100644
--- a/p11-kit/iter.c
+++ b/p11-kit/iter.c
@@ -84,6 +84,7 @@ struct p11_kit_iter {
CK_SLOT_ID slot;
CK_SESSION_HANDLE session;
CK_OBJECT_HANDLE object;
+ CK_TOKEN_INFO token_info;
/* And various flags */
unsigned int searching : 1;
@@ -434,7 +435,6 @@ call_all_filters (P11KitIter *iter,
static CK_RV
move_next_session (P11KitIter *iter)
{
- CK_TOKEN_INFO tinfo;
CK_ULONG session_flags;
CK_ULONG num_slots;
CK_INFO minfo;
@@ -479,14 +479,14 @@ move_next_session (P11KitIter *iter)
iter->slot = iter->slots[iter->saw_slots++];
assert (iter->module != NULL);
- rv = (iter->module->C_GetTokenInfo) (iter->slot, &tinfo);
- if (rv != CKR_OK || !p11_match_uri_token_info (&iter->match_token, &tinfo))
+ rv = (iter->module->C_GetTokenInfo) (iter->slot, &iter->token_info);
+ if (rv != CKR_OK || !p11_match_uri_token_info (&iter->match_token, &iter->token_info))
continue;
session_flags = CKF_SERIAL_SESSION;
/* Skip if the read/write on a read-only token */
- if (iter->want_writable && (tinfo.flags & CKF_WRITE_PROTECTED) == 0)
+ if (iter->want_writable && (iter->token_info.flags & CKF_WRITE_PROTECTED) == 0)
session_flags |= CKF_RW_SESSION;
rv = (iter->module->C_OpenSession) (iter->slot, session_flags,
@@ -648,6 +648,23 @@ p11_kit_iter_get_slot (P11KitIter *iter)
}
/**
+ * p11_kit_iter_get_token:
+ * @iter: the iterator
+ *
+ * Get the token info for the token which the current matching object is on.
+ *
+ * This can only be called after p11_kit_iter_next(0 succeeds.
+ *
+ * Returns: the slot of the current matching object.
+ */
+CK_TOKEN_INFO *
+p11_kit_iter_get_token (P11KitIter *iter)
+{
+ return_val_if_fail (iter != NULL, NULL);
+ return &iter->token_info;
+}
+
+/**
* p11_kit_iter_get_session:
* @iter: the iterator
*
diff --git a/p11-kit/iter.h b/p11-kit/iter.h
index 17bd6f1..ecf7db0 100644
--- a/p11-kit/iter.h
+++ b/p11-kit/iter.h
@@ -84,6 +84,8 @@ CK_FUNCTION_LIST_PTR p11_kit_iter_get_module (P11KitIter *iter);
CK_SLOT_ID p11_kit_iter_get_slot (P11KitIter *iter);
+CK_TOKEN_INFO * p11_kit_iter_get_token (P11KitIter *iter);
+
CK_SESSION_HANDLE p11_kit_iter_get_session (P11KitIter *iter);
CK_OBJECT_HANDLE p11_kit_iter_get_object (P11KitIter *iter);
diff --git a/p11-kit/tests/test-iter.c b/p11-kit/tests/test-iter.c
index b6bf6f9..a1d1c9c 100644
--- a/p11-kit/tests/test-iter.c
+++ b/p11-kit/tests/test-iter.c
@@ -740,6 +740,37 @@ test_token_mismatch (void)
}
static void
+test_token_info (void)
+{
+ CK_FUNCTION_LIST_PTR *modules;
+ CK_TOKEN_INFO *info;
+ P11KitIter *iter;
+ char *string;
+ CK_RV rv;
+
+ modules = initialize_and_get_modules ();
+
+ iter = p11_kit_iter_new (NULL, 0);
+ p11_kit_iter_begin (iter, modules);
+
+ rv = p11_kit_iter_next (iter);
+ assert_num_eq (rv, CKR_OK);
+
+ info = p11_kit_iter_get_token (iter);
+ assert_ptr_not_null (info);
+
+ string = p11_kit_space_strdup (info->label, sizeof (info->label));
+ assert_ptr_not_null (string);
+
+ assert_str_eq (string, "TEST LABEL");
+
+ free (string);
+ p11_kit_iter_free (iter);
+
+ finalize_and_free_modules (modules);
+}
+
+static void
test_getslotlist_fail_first (void)
{
CK_FUNCTION_LIST module;
@@ -1145,6 +1176,7 @@ main (int argc,
p11_test (test_keep_session, "/iter/test_keep_session");
p11_test (test_token_match, "/iter/test_token_match");
p11_test (test_token_mismatch, "/iter/test_token_mismatch");
+ p11_test (test_token_info, "/iter/token-info");
p11_test (test_module_match, "/iter/test_module_match");
p11_test (test_module_mismatch, "/iter/test_module_mismatch");
p11_test (test_getslotlist_fail_first, "/iter/test_getslotlist_fail_first");