[gnome-keyring/dbus-api] [gck] Add missing gck_attribute_get_string() function and add tests.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring/dbus-api] [gck] Add missing gck_attribute_get_string() function and add tests.
- Date: Mon, 10 Aug 2009 01:02:40 +0000 (UTC)
commit 7436c475e54c40a0350ba9071f1541204127e09c
Author: Stef Walter <stef memberwebs com>
Date: Sun Aug 9 19:39:43 2009 +0000
[gck] Add missing gck_attribute_get_string() function and add tests.
Add tests to all gck_attribute_xxx() functions, and add missing
functions, remove unused declarations.
pkcs11/gck/gck-attributes.c | 23 ++-
pkcs11/gck/gck-attributes.h | 5 -
pkcs11/gck/tests/unit-test-attributes.c | 574 ++++++++++++++++++++++++++++++-
3 files changed, 588 insertions(+), 14 deletions(-)
---
diff --git a/pkcs11/gck/gck-attributes.c b/pkcs11/gck/gck-attributes.c
index 3b48665..047050f 100644
--- a/pkcs11/gck/gck-attributes.c
+++ b/pkcs11/gck/gck-attributes.c
@@ -111,6 +111,27 @@ gck_attribute_get_time (CK_ATTRIBUTE_PTR attr, glong *when)
}
CK_RV
+gck_attribute_get_string (CK_ATTRIBUTE_PTR attr, gchar **value)
+{
+ g_return_val_if_fail (attr, CKR_GENERAL_ERROR);
+ g_return_val_if_fail (value, CKR_GENERAL_ERROR);
+
+ if (attr->ulValueLen == 0) {
+ *value = NULL;
+ return CKR_OK;
+ }
+
+ if (!attr->pValue)
+ return CKR_ATTRIBUTE_VALUE_INVALID;
+
+ if (!g_utf8_validate (attr->pValue, attr->ulValueLen, NULL))
+ return CKR_ATTRIBUTE_VALUE_INVALID;
+
+ *value = g_strndup (attr->pValue, attr->ulValueLen);
+ return CKR_OK;
+}
+
+CK_RV
gck_attribute_set_bool (CK_ATTRIBUTE_PTR attr, CK_BBOOL value)
{
return gck_attribute_set_data (attr, &value, sizeof (CK_BBOOL));
@@ -216,7 +237,7 @@ gck_attribute_set_mpi (CK_ATTRIBUTE_PTR attr, gcry_mpi_t mpi)
}
if (len > attr->ulValueLen) {
- attr->ulValueLen = len;
+ attr->ulValueLen = (CK_ULONG)-1;
return CKR_BUFFER_TOO_SMALL;
}
diff --git a/pkcs11/gck/gck-attributes.h b/pkcs11/gck/gck-attributes.h
index 80a643a..b4509a1 100644
--- a/pkcs11/gck/gck-attributes.h
+++ b/pkcs11/gck/gck-attributes.h
@@ -56,11 +56,6 @@ CK_RV gck_attribute_set_data (CK_ATTRI
gconstpointer value,
gsize n_value);
-CK_RV gck_attribute_return_data (CK_VOID_PTR output,
- CK_ULONG_PTR n_output,
- gconstpointer input,
- gsize n_input);
-
CK_RV gck_attribute_set_mpi (CK_ATTRIBUTE_PTR attr,
gcry_mpi_t mpi);
diff --git a/pkcs11/gck/tests/unit-test-attributes.c b/pkcs11/gck/tests/unit-test-attributes.c
index d8cba87..e0290b6 100644
--- a/pkcs11/gck/tests/unit-test-attributes.c
+++ b/pkcs11/gck/tests/unit-test-attributes.c
@@ -25,6 +25,17 @@
#include "gck/gck-attributes.h"
+/* Some test data */
+static CK_OBJECT_CLASS attr_template_klass = CKO_DATA;
+static CK_BBOOL attr_template_token = CK_TRUE;
+static CK_ATTRIBUTE attr_template[] = {
+ { CKA_LABEL, "funny", 5 },
+ { CKA_CLASS, &attr_template_klass, sizeof (CK_OBJECT_CLASS) },
+ { CKA_ID, "my-identifier", 13 },
+ { CKA_TOKEN, &attr_template_token, sizeof (CK_BBOOL) },
+ { CKA_VALUE, "\a[\315\025", 4 }
+};
+
DEFINE_TEST(attribute_consume)
{
CK_ATTRIBUTE attr;
@@ -34,13 +45,62 @@ DEFINE_TEST(attribute_consume)
g_assert (attr.type == (gulong)-1);
}
+DEFINE_TEST(attribute_consumed)
+{
+ CK_ATTRIBUTE attr;
+ gboolean ret;
+
+ attr.type = CKA_LABEL;
+
+ ret = gck_attribute_consumed (&attr);
+ g_assert (ret == FALSE);
+
+ gck_attribute_consume (&attr);
+
+ ret = gck_attribute_consumed (&attr);
+ g_assert (ret == TRUE);
+}
+
+DEFINE_TEST(attribute_set_data)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_RV rv;
+
+ rv = gck_attribute_set_data (&attr, "mytest", 6);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 6);
+ g_assert (memcmp (buffer, "mytest", 6) == 0);
+}
+
+DEFINE_TEST(attribute_set_data_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 4 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_data (&attr, "mytest", 6);
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+}
+
+DEFINE_TEST(attribute_set_data_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_data (&attr, "mytest", 6);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 6);
+}
+
DEFINE_TEST(attribute_get_bool)
{
CK_ATTRIBUTE attr;
CK_BBOOL val = CK_TRUE;
gboolean value;
CK_RV rv;
-
+
attr.ulValueLen = sizeof (CK_BBOOL);
attr.pValue = &val;
rv = gck_attribute_get_bool (&attr, &value);
@@ -66,7 +126,7 @@ DEFINE_TEST(attribute_set_time)
CK_ATTRIBUTE attr;
gchar buf[30];
CK_RV rv;
-
+
attr.ulValueLen = 30;
attr.pValue = buf;
rv = gck_attribute_set_time (&attr, 1247930171);
@@ -80,7 +140,7 @@ DEFINE_TEST(attribute_set_time_empty)
CK_ATTRIBUTE attr;
gchar buf[30];
CK_RV rv;
-
+
attr.ulValueLen = 30;
attr.pValue = buf;
rv = gck_attribute_set_time (&attr, -1);
@@ -92,7 +152,7 @@ DEFINE_TEST(attribute_set_time_length)
{
CK_ATTRIBUTE attr;
CK_RV rv;
-
+
attr.pValue = NULL;
attr.ulValueLen = 0;
rv = gck_attribute_set_time (&attr, 1247930171);
@@ -106,7 +166,7 @@ DEFINE_TEST(attribute_get_time)
CK_ATTRIBUTE attr;
glong when;
CK_RV rv;
-
+
attr.ulValueLen = 16;
attr.pValue = "2009071815161100";
rv = gck_attribute_get_time (&attr, &when);
@@ -119,7 +179,7 @@ DEFINE_TEST(attribute_get_time_empty)
CK_ATTRIBUTE attr;
glong when;
CK_RV rv;
-
+
attr.ulValueLen = 0;
attr.pValue = "";
rv = gck_attribute_get_time (&attr, &when);
@@ -132,7 +192,7 @@ DEFINE_TEST(attribute_get_time_invalid)
CK_ATTRIBUTE attr;
glong when;
CK_RV rv;
-
+
attr.ulValueLen = 16;
attr.pValue = "aaaaaaaaaaaaaaaa";
rv = gck_attribute_get_time (&attr, &when);
@@ -144,9 +204,507 @@ DEFINE_TEST(attribute_get_time_invalid_length)
CK_ATTRIBUTE attr;
glong when;
CK_RV rv;
-
+
attr.ulValueLen = 8;
attr.pValue = "2009071815161100";
rv = gck_attribute_get_time (&attr, &when);
g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
}
+
+DEFINE_TEST(attribute_get_string)
+{
+ CK_ATTRIBUTE attr;
+ gchar *value;
+ CK_RV rv;
+
+ attr.ulValueLen = 4;
+ attr.pValue = "blah";
+
+ rv = gck_attribute_get_string (&attr, &value);
+ g_assert (rv == CKR_OK);
+ g_assert_cmpstr (value, ==, "blah");
+
+ g_free (value);
+}
+
+DEFINE_TEST(attribute_get_string_null)
+{
+ CK_ATTRIBUTE attr;
+ gchar *value;
+ CK_RV rv;
+
+ attr.ulValueLen = 0;
+ attr.pValue = NULL;
+
+ rv = gck_attribute_get_string (&attr, &value);
+ g_assert (rv == CKR_OK);
+ g_assert (value == NULL);
+}
+
+DEFINE_TEST(attribute_get_string_not_utf8)
+{
+ CK_ATTRIBUTE attr;
+ gchar *value;
+ CK_RV rv;
+
+ /* No embedded nulls, or non-UTF8 */
+ attr.ulValueLen = 5;
+ attr.pValue = "\0test";
+
+ rv = gck_attribute_get_string (&attr, &value);
+ g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
+}
+
+DEFINE_TEST(attribute_get_string_bad_pointer)
+{
+ CK_ATTRIBUTE attr;
+ gchar *value;
+ CK_RV rv;
+
+ /* No embedded nulls, or non-UTF8 */
+ attr.ulValueLen = 5;
+ attr.pValue = NULL;
+
+ rv = gck_attribute_get_string (&attr, &value);
+ g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
+}
+
+DEFINE_TEST(attribute_set_bool)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_RV rv;
+
+ rv = gck_attribute_set_bool (&attr, CK_TRUE);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 1);
+ g_assert (memcmp (buffer, "\1", 1) == 0);
+
+ rv = gck_attribute_set_bool (&attr, CK_FALSE);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 1);
+ g_assert (memcmp (buffer, "\0", 1) == 0);
+}
+
+DEFINE_TEST(attribute_set_bool_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_bool (&attr, CK_TRUE);
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+}
+
+DEFINE_TEST(attribute_set_bool_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_bool (&attr, CK_TRUE);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 1);
+}
+
+DEFINE_TEST(attribute_set_ulong)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_ULONG value = 55;
+ CK_RV rv;
+
+ rv = gck_attribute_set_ulong (&attr, value);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == sizeof (CK_ULONG));
+ g_assert (memcmp (buffer, &value, sizeof (CK_ULONG)) == 0);
+}
+
+DEFINE_TEST(attribute_set_ulong_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_ulong (&attr, 1);
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+}
+
+DEFINE_TEST(attribute_set_ulong_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_ulong (&attr, 98889);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == sizeof (CK_ULONG));
+}
+
+DEFINE_TEST(attribute_set_string)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_RV rv;
+
+ rv = gck_attribute_set_string (&attr, "hello");
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 5);
+ g_assert (memcmp (buffer, "hello", 5) == 0);
+}
+
+DEFINE_TEST(attribute_set_string_null)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_RV rv;
+
+ rv = gck_attribute_set_string (&attr, NULL);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 0);
+}
+
+DEFINE_TEST(attribute_set_string_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 3 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_string (&attr, "hello");
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+}
+
+DEFINE_TEST(attribute_set_string_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_string (&attr, "hello");
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 5);
+}
+
+DEFINE_TEST(attribute_set_date)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_DATE *date;
+ CK_RV rv;
+
+ rv = gck_attribute_set_date (&attr, 1249845741);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == sizeof (CK_DATE));
+ date = (CK_DATE*)buffer;
+ g_assert (memcmp (date->day, "09", 2) == 0);
+ g_assert (memcmp (date->month, "08", 2) == 0);
+ g_assert (memcmp (date->year, "2009", 4) == 0);
+}
+
+DEFINE_TEST(attribute_set_date_none)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ CK_RV rv;
+
+ rv = gck_attribute_set_date (&attr, (time_t)-1);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 0);
+}
+
+DEFINE_TEST(attribute_set_date_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 5 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_date (&attr, 1249845741);
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+}
+
+DEFINE_TEST(attribute_set_date_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ CK_RV rv;
+
+ rv = gck_attribute_set_date (&attr, 1249845741);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == sizeof (CK_DATE));
+}
+
+DEFINE_TEST(attribute_set_mpi)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, sizeof (buffer) };
+ gcry_mpi_t mpi;
+ CK_RV rv;
+
+ mpi = gcry_mpi_new (32);
+ gcry_mpi_set_ui (mpi, 123456789);
+
+ rv = gck_attribute_set_mpi (&attr, mpi);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 4);
+ g_assert (memcmp (buffer, "\a[\315\025", 4) == 0);
+
+ gcry_mpi_release (mpi);
+}
+
+DEFINE_TEST(attribute_set_mpi_short)
+{
+ guchar buffer[32];
+ CK_ATTRIBUTE attr = { 0, buffer, 2 };
+ gcry_mpi_t mpi;
+ CK_RV rv;
+
+ mpi = gcry_mpi_new (32);
+ gcry_mpi_set_ui (mpi, 123456789);
+
+ rv = gck_attribute_set_mpi (&attr, mpi);
+ g_assert (rv == CKR_BUFFER_TOO_SMALL);
+ g_assert (attr.ulValueLen == (CK_ULONG)-1);
+
+ gcry_mpi_release (mpi);
+}
+
+DEFINE_TEST(attribute_set_mpi_length)
+{
+ CK_ATTRIBUTE attr = { 0, NULL, 0 };
+ gcry_mpi_t mpi;
+ CK_RV rv;
+
+ mpi = gcry_mpi_new (32);
+ gcry_mpi_set_ui (mpi, 123456789);
+
+ rv = gck_attribute_set_mpi (&attr, mpi);
+ g_assert (rv == CKR_OK);
+ g_assert (attr.ulValueLen == 4);
+
+ gcry_mpi_release (mpi);
+}
+
+DEFINE_TEST(attribute_equal)
+{
+ /* Make sure we actually have two different strings */
+ gchar *val1 = g_strdup ("my-identifier");
+ gchar *val2 = g_strdup ("my-identifier");
+ CK_ATTRIBUTE attr1 = { CKA_ID, val1, 13 };
+ CK_ATTRIBUTE attr2 = { CKA_ID, val2, 13 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr1, &attr2);
+ g_assert (ret == TRUE);
+
+ g_free (val1);
+ g_free (val2);
+}
+
+DEFINE_TEST(attribute_equal_same)
+{
+ CK_ATTRIBUTE attr = { CKA_ID, "my-identifier", 13 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr, &attr);
+ g_assert (ret == TRUE);
+}
+
+DEFINE_TEST(attribute_equal_same_pointer)
+{
+ gchar *val = "my-identifier";
+ CK_ATTRIBUTE attr1 = { CKA_ID, val, 13 };
+ CK_ATTRIBUTE attr2 = { CKA_ID, val, 13 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr1, &attr2);
+ g_assert (ret == TRUE);
+}
+
+DEFINE_TEST(attribute_equal_diff_types)
+{
+ gchar *val = "my-identifier";
+ CK_ATTRIBUTE attr1 = { CKA_ID, val, 13 };
+ CK_ATTRIBUTE attr2 = { CKA_VALUE, val, 13 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr1, &attr2);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_equal_diff_length)
+{
+ CK_ATTRIBUTE attr1 = { CKA_ID, "my-identifier", 13 };
+ CK_ATTRIBUTE attr2 = { CKA_ID, "my-identifier", 2 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr1, &attr2);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_equal_diff_value)
+{
+ CK_ATTRIBUTE attr1 = { CKA_ID, "my-identifier", 13 };
+ CK_ATTRIBUTE attr2 = { CKA_ID, "xy-identifier", 13 };
+ gboolean ret;
+
+ ret = gck_attribute_equal (&attr1, &attr2);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_hash)
+{
+ CK_ATTRIBUTE attr = { CKA_VALUE, "value", 5 };
+ guint hash;
+
+ /* The hash value below could change as code changes */
+ hash = gck_attribute_hash (&attr);
+ g_assert_cmpuint (hash, ==, 3709494161);
+}
+
+DEFINE_TEST(attribute_contains)
+{
+ CK_ATTRIBUTE attr = { CKA_ID, "my-identifier", 13 };
+ gboolean ret;
+
+ ret = gck_attributes_contains (attr_template, G_N_ELEMENTS (attr_template), &attr);
+ g_assert (ret == TRUE);
+}
+
+DEFINE_TEST(attribute_contains_no_value)
+{
+ CK_ATTRIBUTE attr = { CKA_ID, "other-identifier", 16 };
+ gboolean ret;
+
+ ret = gck_attributes_contains (attr_template, G_N_ELEMENTS (attr_template), &attr);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_contains_no_type)
+{
+ CK_ATTRIBUTE attr = { CKA_VALUE, "value", 5 };
+ gboolean ret;
+
+ ret = gck_attributes_contains (attr_template, G_N_ELEMENTS (attr_template), &attr);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attributes_find)
+{
+ CK_ATTRIBUTE_PTR attr;
+
+ attr = gck_attributes_find (attr_template, G_N_ELEMENTS (attr_template), CKA_LABEL);
+ g_assert (attr != NULL);
+ g_assert (attr->type == CKA_LABEL);
+}
+
+DEFINE_TEST(attributes_find_not_found)
+{
+ CK_ATTRIBUTE_PTR attr;
+
+ attr = gck_attributes_find (attr_template, G_N_ELEMENTS (attr_template), CKA_SENSITIVE);
+ g_assert (attr == NULL);
+}
+
+DEFINE_TEST(attribute_find_boolean)
+{
+ gboolean value;
+ gboolean ret;
+
+ ret = gck_attributes_find_boolean (attr_template, G_N_ELEMENTS (attr_template), CKA_TOKEN, &value);
+ g_assert (ret == TRUE);
+ g_assert (value == TRUE);
+}
+
+DEFINE_TEST(attribute_find_boolean_no_type)
+{
+ gboolean value;
+ gboolean ret;
+
+ ret = gck_attributes_find_boolean (attr_template, G_N_ELEMENTS (attr_template), CKA_SENSITIVE, &value);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_find_boolean_not_bbool)
+{
+ gboolean value;
+ gboolean ret;
+
+ ret = gck_attributes_find_boolean (attr_template, G_N_ELEMENTS (attr_template), CKA_CLASS, &value);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_find_ulong)
+{
+ gulong value;
+ gboolean ret;
+
+ ret = gck_attributes_find_ulong (attr_template, G_N_ELEMENTS (attr_template), CKA_CLASS, &value);
+ g_assert (ret == TRUE);
+ g_assert (value == CKO_DATA);
+}
+
+DEFINE_TEST(attribute_find_ulong_no_type)
+{
+ gulong value;
+ gboolean ret;
+
+ ret = gck_attributes_find_ulong (attr_template, G_N_ELEMENTS (attr_template), CKA_KEY_TYPE, &value);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_find_ulong_not_ulong)
+{
+ gulong value;
+ gboolean ret;
+
+ ret = gck_attributes_find_ulong (attr_template, G_N_ELEMENTS (attr_template), CKA_ID, &value);
+ g_assert (ret == FALSE);
+}
+
+DEFINE_TEST(attribute_find_mpi)
+{
+ gcry_mpi_t mpi = NULL;
+ gboolean ret;
+
+ ret = gck_attributes_find_mpi (attr_template, G_N_ELEMENTS (attr_template), CKA_VALUE, &mpi);
+ g_assert (ret == TRUE);
+ g_assert (mpi != NULL);
+
+ g_assert (gcry_mpi_cmp_ui (mpi, 123456789) == 0);
+ gcry_mpi_release (mpi);
+}
+
+DEFINE_TEST(attribute_find_mpi_no_type)
+{
+ gcry_mpi_t mpi = NULL;
+ gboolean ret;
+
+ ret = gck_attributes_find_mpi (attr_template, G_N_ELEMENTS (attr_template), CKA_MODULUS, &mpi);
+ g_assert (ret == FALSE);
+ g_assert (mpi == NULL);
+}
+
+DEFINE_TEST(attributes_consume)
+{
+ CK_ATTRIBUTE_PTR attrs;
+ CK_ULONG n_attrs;
+
+ /* Dup because we're writing to this */
+ attrs = g_memdup (attr_template, sizeof (attr_template));
+ n_attrs = G_N_ELEMENTS (attr_template);
+
+ /* All these attributes are there */
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_LABEL) != NULL);
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_ID) != NULL);
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_CLASS) != NULL);
+
+ /* Consume some of them */
+ gck_attributes_consume (attrs, n_attrs, CKA_LABEL, CKA_ID, G_MAXULONG);
+
+ /* Two should be gone */
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_LABEL) == NULL);
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_ID) == NULL);
+ g_assert (gck_attributes_find (attrs, n_attrs, CKA_CLASS) != NULL);
+
+ g_free (attrs);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]