[gnome-keyring: 3/10] [gck] Add helper function to parse bool attribute.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-keyring: 3/10] [gck] Add helper function to parse bool attribute.
- Date: Sun, 19 Jul 2009 19:33:23 +0000 (UTC)
commit 3f7704cd340e9e8ee88dd5180a52cc583bb9daf3
Author: Stef Walter <stef memberwebs com>
Date: Sat Jul 18 22:42:19 2009 +0000
[gck] Add helper function to parse bool attribute.
pkcs11/gck/gck-attributes.c | 17 +++++++++++++++++
pkcs11/gck/gck-attributes.h | 5 ++++-
pkcs11/gck/tests/unit-test-attributes.c | 27 +++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/pkcs11/gck/gck-attributes.c b/pkcs11/gck/gck-attributes.c
index f5c0102..3b48665 100644
--- a/pkcs11/gck/gck-attributes.c
+++ b/pkcs11/gck/gck-attributes.c
@@ -28,6 +28,23 @@
#include <stdio.h>
#include <string.h>
+
+CK_RV
+gck_attribute_get_bool (CK_ATTRIBUTE_PTR attr, gboolean *value)
+{
+ CK_BBOOL* bool;
+
+ g_return_val_if_fail (attr, CKR_GENERAL_ERROR);
+ g_return_val_if_fail (value, CKR_GENERAL_ERROR);
+
+ if (attr->ulValueLen != sizeof (CK_BBOOL) || attr->pValue == NULL)
+ return CKR_ATTRIBUTE_VALUE_INVALID;
+
+ bool = attr->pValue;
+ *value = *bool ? TRUE : FALSE;
+ return CKR_OK;
+}
+
#ifndef HAVE_TIMEGM
static time_t
timegm (struct tm *t)
diff --git a/pkcs11/gck/gck-attributes.h b/pkcs11/gck/gck-attributes.h
index cfbb77d..41ae48a 100644
--- a/pkcs11/gck/gck-attributes.h
+++ b/pkcs11/gck/gck-attributes.h
@@ -28,8 +28,11 @@
#include "pkcs11/pkcs11.h"
+CK_RV gck_attribute_get_bool (CK_ATTRIBUTE_PTR attr,
+ gboolean *value);
+
CK_RV gck_attribute_get_time (CK_ATTRIBUTE_PTR attr,
- glong *when);
+ glong *value);
CK_RV gck_attribute_set_bool (CK_ATTRIBUTE_PTR attr,
CK_BBOOL value);
diff --git a/pkcs11/gck/tests/unit-test-attributes.c b/pkcs11/gck/tests/unit-test-attributes.c
index d1add75..d8cba87 100644
--- a/pkcs11/gck/tests/unit-test-attributes.c
+++ b/pkcs11/gck/tests/unit-test-attributes.c
@@ -34,6 +34,33 @@ DEFINE_TEST(attribute_consume)
g_assert (attr.type == (gulong)-1);
}
+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);
+ g_assert (rv == CKR_OK);
+ g_assert (value == TRUE);
+}
+
+DEFINE_TEST(attribute_get_bool_invalid)
+{
+ CK_ATTRIBUTE attr;
+ CK_ULONG val = 4;
+ gboolean value;
+ CK_RV rv;
+
+ attr.ulValueLen = sizeof (CK_ULONG);
+ attr.pValue = &val;
+ rv = gck_attribute_get_bool (&attr, &value);
+ g_assert (rv == CKR_ATTRIBUTE_VALUE_INVALID);
+}
+
DEFINE_TEST(attribute_set_time)
{
CK_ATTRIBUTE attr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]