summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-08-27 21:15:24 +0200
committerStef Walter <stef@thewalter.net>2013-08-28 14:00:17 +0200
commit1fac2b92d6c53655086a2cc3a653b8e78d92a043 (patch)
tree696037625b71019662f2fddf0d0a44d1b1b08bdf
parentdec3efbaf4a6550bc45d1b9926e4d66b93306802 (diff)
downloadp11-kit-1fac2b92d6c53655086a2cc3a653b8e78d92a043.tar.gz
iter: Add a p11_kit_iter_destroy_object() function
Handy function since this is a common need.
-rw-r--r--doc/manual/p11-kit-sections.txt1
-rw-r--r--p11-kit/iter.c18
-rw-r--r--p11-kit/iter.h1
-rw-r--r--p11-kit/tests/test-iter.c40
4 files changed, 60 insertions, 0 deletions
diff --git a/doc/manual/p11-kit-sections.txt b/doc/manual/p11-kit-sections.txt
index e066fe1..28ebae0 100644
--- a/doc/manual/p11-kit-sections.txt
+++ b/doc/manual/p11-kit-sections.txt
@@ -113,6 +113,7 @@ p11_kit_iter_get_session
p11_kit_iter_keep_session
p11_kit_iter_get_object
p11_kit_iter_load_attributes
+p11_kit_iter_destroy_object
p11_kit_iter_free
P11KitIterBehavior
</SECTION>
diff --git a/p11-kit/iter.c b/p11-kit/iter.c
index e8e466c..6a3ad4a 100644
--- a/p11-kit/iter.c
+++ b/p11-kit/iter.c
@@ -731,6 +731,24 @@ p11_kit_iter_get_object (P11KitIter *iter)
}
/**
+ * p11_kit_iter_destroy_object:
+ * @iter: teh iterator
+ *
+ * Destory the current matching object.
+ *
+ * This can only be called after p11_kit_iter_next() succeeds.
+ *
+ * Returns: CKR_OK or a failure code
+ */
+CK_RV
+p11_kit_iter_destroy_object (P11KitIter *iter)
+{
+ return_val_if_fail (iter != NULL, CKR_GENERAL_ERROR);
+ return_val_if_fail (iter->iterating, CKR_GENERAL_ERROR);
+ return (iter->module->C_DestroyObject) (iter->session, iter->object);
+}
+
+/**
* p11_kit_iter_load_attributes:
* @iter: the iterator
* @template: (array length=count) (inout): the attributes to load
diff --git a/p11-kit/iter.h b/p11-kit/iter.h
index 2ded9fe..0201db0 100644
--- a/p11-kit/iter.h
+++ b/p11-kit/iter.h
@@ -99,6 +99,7 @@ CK_RV p11_kit_iter_load_attributes (P11KitIter *iter,
CK_SESSION_HANDLE p11_kit_iter_keep_session (P11KitIter *iter);
+CK_RV p11_kit_iter_destroy_object (P11KitIter *iter);
#endif /* P11_KIT_FUTURE_UNSTABLE_API */
diff --git a/p11-kit/tests/test-iter.c b/p11-kit/tests/test-iter.c
index 46b825e..b72795e 100644
--- a/p11-kit/tests/test-iter.c
+++ b/p11-kit/tests/test-iter.c
@@ -1182,6 +1182,45 @@ test_many (void *flags)
assert (rv == CKR_OK);
}
+static void
+test_destroy_object (void)
+{
+ CK_FUNCTION_LIST **modules;
+ P11KitIter *iter;
+ CK_OBJECT_HANDLE object;
+ CK_SESSION_HANDLE session;
+ CK_FUNCTION_LIST *module;
+ CK_ULONG size;
+ CK_RV rv;
+
+ modules = initialize_and_get_modules ();
+
+ iter = p11_kit_iter_new (NULL, P11_KIT_ITER_WANT_WRITABLE);
+
+ p11_kit_iter_begin (iter, modules);
+
+ /* Should have matched */
+ rv = p11_kit_iter_next (iter);
+ assert_num_eq (rv, CKR_OK);
+
+ object = p11_kit_iter_get_object (iter);
+ session = p11_kit_iter_get_session (iter);
+ module = p11_kit_iter_get_module (iter);
+
+ rv = (module->C_GetObjectSize) (session, object, &size);
+ assert_num_eq (rv, CKR_OK);
+
+ rv = p11_kit_iter_destroy_object (iter);
+ assert_num_eq (rv, CKR_OK);
+
+ rv = (module->C_GetObjectSize) (session, object, &size);
+ assert_num_eq (rv, CKR_OBJECT_HANDLE_INVALID);
+
+ p11_kit_iter_free (iter);
+
+ finalize_and_free_modules (modules);
+}
+
int
main (int argc,
char *argv[])
@@ -1218,6 +1257,7 @@ main (int argc,
p11_test (test_load_attributes_fail_late, "/iter/test_load_attributes_fail_late");
p11_testx (test_many, "", "/iter/test-many");
p11_testx (test_many, "busy-sessions", "/iter/test-many-busy");
+ p11_test (test_destroy_object, "/iter/destroy-object");
return p11_test_run (argc, argv);
}