gp11/gp11.h
authorStefan Walter <stefw@src.gnome.org>
Sun, 17 Aug 2008 16:09:52 +0000 (16:09 +0000)
committerStefan Walter <stefw@src.gnome.org>
Sun, 17 Aug 2008 16:09:52 +0000 (16:09 +0000)
* gp11/gp11-attributes.c:
* gp11/gp11-misc.c:
* gp11/gp11-object.c:
* gp11/gp11-private.h:
* gp11/gp11-session.c:
* gp11/gp11-slot.c:
* gp11/gp11.h
* gp11/tests/unit-test-gp11-object.c:
* gp11/tests/unit-test-gp11-slot.c:
* tool/gkr-tool-import.c: Use gulong for all CK_ULONG derived
types in PKCS#11. Fixes bug #547830

svn path=/trunk/; revision=1248

gp11/gp11-attributes.c
gp11/gp11-misc.c
gp11/gp11-object.c
gp11/gp11-private.h
gp11/gp11-session.c
gp11/gp11-slot.c
gp11/gp11.h
gp11/tests/unit-test-gp11-object.c
gp11/tests/unit-test-gp11-slot.c

index 4793c82..a91a7a8 100644 (file)
@@ -7,8 +7,21 @@
 #include <stdlib.h>
 #include <string.h>
 
+/**
+ * gp11_attribute_init:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The raw value of the attribute.
+ * @length: The length of the raw value.
+ *
+ * Initialize a PKCS#11 attribute. This copies the value memory
+ * into an internal buffer.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init (GP11Attribute *attr, guint attr_type,
+gp11_attribute_init (GP11Attribute *attr, gulong attr_type,
                      gconstpointer value, gsize length)
 {
        g_assert (sizeof (GP11Attribute) == sizeof (CK_ATTRIBUTE));
@@ -18,8 +31,20 @@ gp11_attribute_init (GP11Attribute *attr, guint attr_type,
        attr->value = value && length ? g_memdup (value, length) : NULL;
 }
 
+/**
+ * gp11_attribute_init_invalid:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ *
+ * Initialize a PKCS#11 attribute to an 'invalid' or 'not found'
+ * state. Specifically this sets the value length to (CK_ULONG)-1
+ * as specified in the PKCS#11 specification.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init_invalid (GP11Attribute *attr, guint attr_type)
+gp11_attribute_init_invalid (GP11Attribute *attr, gulong attr_type)
 {
        g_assert (sizeof (GP11Attribute) == sizeof (CK_ATTRIBUTE));
        memset (attr, 0, sizeof (GP11Attribute));
@@ -28,7 +53,7 @@ gp11_attribute_init_invalid (GP11Attribute *attr, guint attr_type)
 }
 
 void
-_gp11_attribute_init_take (GP11Attribute *attr, guint attr_type,
+_gp11_attribute_init_take (GP11Attribute *attr, gulong attr_type,
                            gpointer value, gsize length)
 {
        g_assert (sizeof (GP11Attribute) == sizeof (CK_ATTRIBUTE));
@@ -38,16 +63,40 @@ _gp11_attribute_init_take (GP11Attribute *attr, guint attr_type,
        attr->value = value && length ? value : NULL;
 }
 
+/**
+ * gp11_attribute_init_boolean:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The boolean value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to boolean. This will result
+ * in a CK_BBOOL attribute from the PKCS#11 specs.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init_boolean (GP11Attribute *attr, guint attr_type,
+gp11_attribute_init_boolean (GP11Attribute *attr, gulong attr_type,
                              gboolean value)
 {
        CK_BBOOL bvalue = value ? CK_TRUE : CK_FALSE;
        gp11_attribute_init (attr, attr_type, &bvalue, sizeof (bvalue));
 }
 
+/**
+ * gp11_attribute_init_date:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The date value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a date. This will result
+ * in a CK_DATE attribute from the PKCS#11 specs.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init_date (GP11Attribute *attr, guint attr_type,
+gp11_attribute_init_date (GP11Attribute *attr, gulong attr_type,
                           const GDate *value)
 {
        gchar buffer[9];
@@ -63,71 +112,175 @@ gp11_attribute_init_date (GP11Attribute *attr, guint attr_type,
        gp11_attribute_init (attr, attr_type, &date, sizeof (CK_DATE));
 }
 
+/**
+ * gp11_attribute_init_ulong:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The ulong value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a unsigned long. This will result
+ * in a CK_ULONG attribute from the PKCS#11 specs.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init_ulong (GP11Attribute *attr, guint attr_type,
+gp11_attribute_init_ulong (GP11Attribute *attr, gulong attr_type,
                            gulong value)
 {
        CK_ULONG uvalue = value;
        gp11_attribute_init (attr, attr_type, &uvalue, sizeof (uvalue));
 }
 
+/**
+ * gp11_attribute_init_string:
+ * @attr: An uninitialized attribute.
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The null terminated string value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a string. This will result
+ * in an attribute containing the text, but not the null terminator.
+ * The text in the attribute will be of the same encoding as you pass
+ * to this function.
+ *
+ * When done with the attribute you should use gp11_attribute_clear()
+ * to free the internal memory.
+ **/
 void
-gp11_attribute_init_string (GP11Attribute *attr, guint attr_type,
+gp11_attribute_init_string (GP11Attribute *attr, gulong attr_type,
                             const gchar *value)
 {
        gsize len = value ? strlen (value) : 0;
        gp11_attribute_init (attr, attr_type, (gpointer)value, len);
 }
 
-
+/**
+ * gp11_attribute_new:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The raw value of the attribute.
+ * @length: The length of the attribute.
+ *
+ * Create a new PKCS#11 attribute. The value will be copied
+ * into the new attribute.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new (guint attr_type, gpointer value, gsize length)
+gp11_attribute_new (gulong attr_type, gpointer value, gsize length)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init (attr, attr_type, value, length);
        return attr;
 }
 
+/**
+ * gp11_attribute_new_invalid:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ *
+ * Create a new PKCS#11 attribute as 'invalid' or 'not found'
+ * state. Specifically this sets the value length to (CK_ULONG)-1
+ * as specified in the PKCS#11 specification.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new_invalid (guint attr_type)
+gp11_attribute_new_invalid (gulong attr_type)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init_invalid (attr, attr_type);
        return attr;
 }
 
+/**
+ * gp11_attribute_new_boolean:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The boolean value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to boolean. This will result
+ * in a CK_BBOOL attribute from the PKCS#11 specs.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new_boolean (guint attr_type, gboolean value)
+gp11_attribute_new_boolean (gulong attr_type, gboolean value)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init_boolean (attr, attr_type, value);
        return attr;
 }
 
+/**
+ * gp11_attribute_new_date:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The date value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a date. This will result
+ * in a CK_DATE attribute from the PKCS#11 specs.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new_date (guint attr_type, const GDate *value)
+gp11_attribute_new_date (gulong attr_type, const GDate *value)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init_date (attr, attr_type, value);
        return attr;
 }
 
+/**
+ * gp11_attribute_new_ulong:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The ulong value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a unsigned long. This will result
+ * in a CK_ULONG attribute from the PKCS#11 specs.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new_ulong (guint attr_type, gulong value)
+gp11_attribute_new_ulong (gulong attr_type, gulong value)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init_ulong (attr, attr_type, value);
        return attr;
 }
 
+/**
+ * gp11_attribute_new_string:
+ * @attr_type: The PKCS#11 attribute type to set on the attribute.
+ * @value: The null terminated string value of the attribute.
+ *
+ * Initialize a PKCS#11 attribute to a string. This will result
+ * in an attribute containing the text, but not the null terminator.
+ * The text in the attribute will be of the same encoding as you pass
+ * to this function.
+ *
+ * Return value: The new attribute. When done with the attribute use
+ * gp11_attribute_free() to free it.
+ **/
 GP11Attribute*
-gp11_attribute_new_string (guint attr_type, const gchar *value)
+gp11_attribute_new_string (gulong attr_type, const gchar *value)
 {
        GP11Attribute *attr = g_slice_new0 (GP11Attribute);
        gp11_attribute_init_string (attr, attr_type, value);
        return attr;
 }
 
+/**
+ * gp11_attribute_is_invalid:
+ * @attr: The attribute to check.
+ *
+ * Check if the PKCS#11 attribute represents 'invalid' or 'not found'
+ * according to the PKCS#11 spec. That is, having length
+ * of (CK_ULONG)-1.
+ *
+ * Return value: Whether the attribute represents invalid or not.
+ */
 gboolean
 gp11_attribute_is_invalid (GP11Attribute *attr)
 {
@@ -135,6 +288,17 @@ gp11_attribute_is_invalid (GP11Attribute *attr)
        return attr->length == (gulong)-1;
 }
 
+/**
+ * gp11_attribute_get_boolean:
+ * @attr: The attribute to retrieve value from.
+ *
+ * Get the CK_BBOOL of a PKCS#11 attribute. No conversion
+ * is performed. It is an error to pass an attribute to this
+ * function unless you're know it's supposed to contain a
+ * boolean value.
+ *
+ * Return value: The boolean value of the attribute.
+ */
 gboolean
 gp11_attribute_get_boolean (GP11Attribute *attr)
 {
@@ -146,6 +310,17 @@ gp11_attribute_get_boolean (GP11Attribute *attr)
        return *((CK_BBOOL*)attr->value) == CK_TRUE ? TRUE : FALSE;
 }
 
+/**
+ * gp11_attribute_get_ulong:
+ * @attr: The attribute to retrieve value from.
+ *
+ * Get the CK_ULONG value of a PKCS#11 attribute. No
+ * conversion is performed. It is an error to pass an attribute
+ * to this function unless you're know it's supposed to contain
+ * a value of the right type.
+ *
+ * Return value: The ulong value of the attribute.
+ */
 gulong
 gp11_attribute_get_ulong (GP11Attribute *attr)
 {
@@ -157,6 +332,18 @@ gp11_attribute_get_ulong (GP11Attribute *attr)
        return *((CK_ULONG*)attr->value);
 }
 
+/**
+ * gp11_attribute_get_string:
+ * @attr: The attribute to retrieve value from.
+ *
+ * Get the string value of a PKCS#11 attribute. No
+ * conversion is performed. It is an error to pass an attribute
+ * to this function unless you're know it's supposed to contain
+ * a value of the right type.
+ *
+ * Return value: A null terminated string, to be freed with g_free(),
+ * or NULL if the value contained a NULL string.
+ */
 gchar*
 gp11_attribute_get_string (GP11Attribute *attr)
 {
@@ -170,6 +357,16 @@ gp11_attribute_get_string (GP11Attribute *attr)
        return g_strndup ((gchar*)attr->value, attr->length);
 }
 
+/**
+ * gp11_attribute_get_date:
+ * @attr: The attribute to retrieve value from.
+ * @value: The date value to fill in with the parsed date.
+ *
+ * Get the CK_DATE of a PKCS#11 attribute. No
+ * conversion is performed. It is an error to pass an attribute
+ * to this function unless you're know it's supposed to contain
+ * a value of the right type.
+ */
 void
 gp11_attribute_get_date (GP11Attribute *attr, GDate *value)
 {
@@ -207,6 +404,16 @@ gp11_attribute_get_date (GP11Attribute *attr, GDate *value)
        g_date_set_dmy (value, day, month, year);
 }
 
+/**
+ * gp11_attribute_dup:
+ * @attr: The attribute to duplicate.
+ *
+ * Duplicate the PKCS#11 attribute. All value memory is
+ * also copied.
+ *
+ * Return value: The duplicated attribute. Use gp11_attribute_free()
+ * to free it.
+ */
 GP11Attribute*
 gp11_attribute_dup (GP11Attribute *attr)
 {
@@ -220,6 +427,17 @@ gp11_attribute_dup (GP11Attribute *attr)
        return copy;
 }
 
+/**
+ * gp11_attribute_init_copy:
+ * @dest: An uninitialized attribute.
+ * @src: An attribute to copy.
+ *
+ * Initialize a PKCS#11 attribute as a copy of another attribute.
+ * This copies the value memory as well.
+ *
+ * When done with the copied attribute you should use
+ * gp11_attribute_clear() to free the internal memory.
+ **/
 void
 gp11_attribute_init_copy (GP11Attribute *dest, GP11Attribute *src)
 {
@@ -235,6 +453,14 @@ gp11_attribute_init_copy (GP11Attribute *dest, GP11Attribute *src)
        dest->value = src->value && src->length ? g_memdup (src->value, src->length) : NULL;
 }
 
+/**
+ * gp11_attribute_clear:
+ * @attr: Attribute to clear.
+ *
+ * Clear allocated memory held by a statically allocated attribute.
+ * These are usually initialized with gp11_attribute_init() or a
+ * similar function.
+ **/
 void
 gp11_attribute_clear (GP11Attribute *attr)
 {
@@ -243,6 +469,14 @@ gp11_attribute_clear (GP11Attribute *attr)
        memset (attr, 0, sizeof (GP11Attribute));
 }
 
+/**
+ * gp11_attribute_free:
+ * @attr: Attribute to free.
+ *
+ * Free an attribute and its allocated memory. These is usually
+ * used with attributes that are allocated by gp11_attribute_new()
+ * or a similar function.
+ **/
 void
 gp11_attribute_free (GP11Attribute *attr)
 {
@@ -258,6 +492,13 @@ struct _GP11Attributes {
        gint refs;
 };
 
+/**
+ * gp11_attributes_get_boxed_type:
+ *
+ * Get the boxed type representing a GP11Attributes array.
+ *
+ * Return value: The boxed type.
+ **/
 GType
 gp11_attributes_get_boxed_type (void)
 {
@@ -269,6 +510,14 @@ gp11_attributes_get_boxed_type (void)
        return type;
 }
 
+/**
+ * gp11_attributes_new:
+ *
+ * Create a new GP11Attributes array.
+ *
+ * Return value: The new attributes array. When done with the array
+ * release it with gp11_attributes_unref().
+ **/
 GP11Attributes*
 gp11_attributes_new (void)
 {
@@ -283,7 +532,7 @@ gp11_attributes_new (void)
 }
 
 static GP11Attributes*
-initialize_from_valist (guint type, va_list va)
+initialize_from_valist (gulong type, va_list va)
 {
        GP11Attributes *attrs;
        gssize length;
@@ -292,7 +541,7 @@ initialize_from_valist (guint type, va_list va)
        attrs = gp11_attributes_new ();
 
        /* No attributes */
-       if (type == (guint)-1)
+       if (type == (gulong)-1)
                return attrs;
 
        do {
@@ -325,15 +574,25 @@ initialize_from_valist (guint type, va_list va)
                        break;
                };
 
-               type = va_arg (va, guint);
+               type = va_arg (va, gulong);
 
-       } while (type != (guint)-1);
+       } while (type != (gulong)-1);
 
        return attrs;
 }
 
+/**
+ * gp11_attributes_newv:
+ *
+ * Create a new GP11Attributes array.
+ *
+ * The arguments must be triples of: attribute type, data type, value
+ *
+ * Return value: The new attributes array. When done with the array
+ * release it with gp11_attributes_unref().
+ **/
 GP11Attributes*
-gp11_attributes_newv (guint first_type, ...)
+gp11_attributes_newv (gulong first_type, ...)
 {
        GP11Attributes *attrs;
        va_list va;
@@ -348,7 +607,7 @@ gp11_attributes_newv (guint first_type, ...)
 GP11Attributes*
 gp11_attributes_new_valist (va_list va)
 {
-       guint type = va_arg (va, guint);
+       gulong type = va_arg (va, gulong);
        return initialize_from_valist (type, va);
 }
 
@@ -391,7 +650,7 @@ gp11_attributes_add (GP11Attributes *attrs, GP11Attribute *attr)
 }
 
 void
-_gp11_attributes_add_take (GP11Attributes *attrs, guint attr_type,
+_gp11_attributes_add_take (GP11Attributes *attrs, gulong attr_type,
                            gpointer value, gsize length)
 {
        GP11Attribute *added;
@@ -402,7 +661,7 @@ _gp11_attributes_add_take (GP11Attributes *attrs, guint attr_type,
 }
 
 void
-gp11_attributes_add_data (GP11Attributes *attrs, guint attr_type,
+gp11_attributes_add_data (GP11Attributes *attrs, gulong attr_type,
                           gconstpointer value, gsize length)
 {
        GP11Attribute *added;
@@ -413,7 +672,7 @@ gp11_attributes_add_data (GP11Attributes *attrs, guint attr_type,
 }
 
 void
-gp11_attributes_add_invalid (GP11Attributes *attrs, guint attr_type)
+gp11_attributes_add_invalid (GP11Attributes *attrs, gulong attr_type)
 {
        GP11Attribute *added;
        g_return_if_fail (attrs);
@@ -423,7 +682,7 @@ gp11_attributes_add_invalid (GP11Attributes *attrs, guint attr_type)
 }
 
 void
-gp11_attributes_add_boolean (GP11Attributes *attrs, guint attr_type, gboolean value)
+gp11_attributes_add_boolean (GP11Attributes *attrs, gulong attr_type, gboolean value)
 {
        GP11Attribute *added;
        g_return_if_fail (attrs);
@@ -433,7 +692,7 @@ gp11_attributes_add_boolean (GP11Attributes *attrs, guint attr_type, gboolean va
 }
 
 void
-gp11_attributes_add_string (GP11Attributes *attrs, guint attr_type, const gchar *value)
+gp11_attributes_add_string (GP11Attributes *attrs, gulong attr_type, const gchar *value)
 {
        GP11Attribute *added;
        g_return_if_fail (attrs);
@@ -443,7 +702,7 @@ gp11_attributes_add_string (GP11Attributes *attrs, guint attr_type, const gchar
 }
 
 void
-gp11_attributes_add_date (GP11Attributes *attrs, guint attr_type, const GDate *value)
+gp11_attributes_add_date (GP11Attributes *attrs, gulong attr_type, const GDate *value)
 {
        GP11Attribute *added;
        g_return_if_fail (attrs);
@@ -453,7 +712,7 @@ gp11_attributes_add_date (GP11Attributes *attrs, guint attr_type, const GDate *v
 }
 
 void
-gp11_attributes_add_ulong (GP11Attributes *attrs, guint attr_type, gulong value)
+gp11_attributes_add_ulong (GP11Attributes *attrs, gulong attr_type, gulong value)
 {
        GP11Attribute *added;
        g_return_if_fail (attrs);
@@ -471,7 +730,7 @@ gp11_attributes_count (GP11Attributes *attrs)
 
 
 GP11Attribute*
-gp11_attributes_find (GP11Attributes *attrs, guint attr_type)
+gp11_attributes_find (GP11Attributes *attrs, gulong attr_type)
 {
        GP11Attribute *attr;
        guint i;
@@ -488,7 +747,7 @@ gp11_attributes_find (GP11Attributes *attrs, guint attr_type)
 }
 
 gboolean
-gp11_attributes_find_boolean (GP11Attributes *attrs, guint attr_type, gboolean *value)
+gp11_attributes_find_boolean (GP11Attributes *attrs, gulong attr_type, gboolean *value)
 {
        GP11Attribute *attr;
        g_return_val_if_fail (value, FALSE);
@@ -501,7 +760,7 @@ gp11_attributes_find_boolean (GP11Attributes *attrs, guint attr_type, gboolean *
 }
 
 gboolean
-gp11_attributes_find_ulong (GP11Attributes *attrs, guint attr_type, gulong *value)
+gp11_attributes_find_ulong (GP11Attributes *attrs, gulong attr_type, gulong *value)
 {
        GP11Attribute *attr;
        g_return_val_if_fail (value, FALSE);
@@ -514,7 +773,7 @@ gp11_attributes_find_ulong (GP11Attributes *attrs, guint attr_type, gulong *valu
 }
 
 gboolean
-gp11_attributes_find_string (GP11Attributes *attrs, guint attr_type, gchar **value)
+gp11_attributes_find_string (GP11Attributes *attrs, gulong attr_type, gchar **value)
 {
        GP11Attribute *attr;
        g_return_val_if_fail (value, FALSE);
@@ -527,7 +786,7 @@ gp11_attributes_find_string (GP11Attributes *attrs, guint attr_type, gchar **val
 }
 
 gboolean
-gp11_attributes_find_date (GP11Attributes *attrs, guint attr_type, GDate *value)
+gp11_attributes_find_date (GP11Attributes *attrs, gulong attr_type, GDate *value)
 {
        GP11Attribute *attr;
        g_return_val_if_fail (value, FALSE);
index 32a208c..7e20a87 100644 (file)
@@ -199,7 +199,7 @@ gp11_message_from_rv (CK_RV rv)
                return _("The signature request was rejected by the user");
 
        default:
-               g_message ("unknown error: %u", (guint)rv);
+               g_message ("unknown error: %lu", (gulong)rv);
                return _("Unknown error");
        }
 }
index 1494f61..98ecdea 100644 (file)
@@ -285,7 +285,7 @@ gp11_object_set_finish (GP11Object *object, GAsyncResult *result, GError **err)
 
 typedef struct _GetAttributes {
        GP11Arguments base;
-       guint *attr_types;
+       gulong *attr_types;
        gsize n_attr_types;
        CK_OBJECT_HANDLE object;
        GP11Attributes *results;
@@ -381,25 +381,25 @@ gp11_object_get (GP11Object *object, GError **err, ...)
        GP11Attributes *result;
        GArray *array;
        va_list va;
-       guint type;
+       gulong type;
 
-       array = g_array_new (0, 1, sizeof (guint));
+       array = g_array_new (0, 1, sizeof (gulong));
        va_start (va, err);
        for (;;) {
-               type = va_arg (va, guint);
-               if (type == (guint)-1)
+               type = va_arg (va, gulong);
+               if (type == (gulong)-1)
                        break;
                g_array_append_val (array, type);
        }
        va_end (va);
 
-       result = gp11_object_get_full (object, (guint*)array->data, array->len, NULL, err);
+       result = gp11_object_get_full (object, (gulong*)array->data, array->len, NULL, err);
        g_array_free (array, TRUE);
        return result;
 }
 
 GP11Attributes*
-gp11_object_get_full (GP11Object *object, const guint *attr_types, gsize n_attr_types,
+gp11_object_get_full (GP11Object *object, const gulong *attr_types, gsize n_attr_types,
                       GCancellable *cancellable, GError **err)
 {
        GetAttributes args;
@@ -407,7 +407,7 @@ gp11_object_get_full (GP11Object *object, const guint *attr_types, gsize n_attr_
        g_return_val_if_fail (GP11_IS_OBJECT (object), FALSE);
 
        memset (&args, 0, sizeof (args));
-       args.attr_types = (guint*)attr_types;
+       args.attr_types = (gulong*)attr_types;
        args.n_attr_types = n_attr_types;
        args.object = object->handle;
 
@@ -420,7 +420,7 @@ gp11_object_get_full (GP11Object *object, const guint *attr_types, gsize n_attr_
 }
 
 void
-gp11_object_get_async (GP11Object *object, const guint *attr_types, gsize n_attr_types,
+gp11_object_get_async (GP11Object *object, const gulong *attr_types, gsize n_attr_types,
                        GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 {
        GetAttributes *args;
@@ -431,7 +431,7 @@ gp11_object_get_async (GP11Object *object, const guint *attr_types, gsize n_attr
                                      sizeof (*args), free_get_attributes);
        args->n_attr_types = n_attr_types;
        if (n_attr_types)
-               args->attr_types = g_memdup (attr_types, sizeof (guint) * n_attr_types);
+               args->attr_types = g_memdup (attr_types, sizeof (gulong) * n_attr_types);
        args->object = object->handle;
 
        _gp11_call_async_go (args, cancellable, callback, user_data);
@@ -455,13 +455,13 @@ gp11_object_get_finish (GP11Object *object, GAsyncResult *result, GError **err)
 }
 
 GP11Attribute*
-gp11_object_get_one (GP11Object *object, guint attr_type, GError **err)
+gp11_object_get_one (GP11Object *object, gulong attr_type, GError **err)
 {
        return gp11_object_get_one_full (object, attr_type, NULL, err);
 }
 
 GP11Attribute*
-gp11_object_get_one_full (GP11Object *object, guint attr_type,
+gp11_object_get_one_full (GP11Object *object, gulong attr_type,
                           GCancellable *cancellable, GError **err)
 {
        GP11Attributes *attrs;
@@ -479,7 +479,7 @@ gp11_object_get_one_full (GP11Object *object, guint attr_type,
 }
 
 void
-gp11_object_get_one_async (GP11Object *object, guint attr_type, GCancellable *cancellable,
+gp11_object_get_one_async (GP11Object *object, gulong attr_type, GCancellable *cancellable,
                            GAsyncReadyCallback callback, gpointer user_data)
 {
        gp11_object_get_async (object, &attr_type, 1, cancellable, callback, user_data);
index e432ccd..19acfe1 100644 (file)
@@ -14,12 +14,12 @@ G_BEGIN_DECLS
  */
 
 void                _gp11_attribute_init_take               (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gpointer value,
                                                              gsize length);
 
 void                _gp11_attributes_add_take               (GP11Attributes *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gpointer value,
                                                              gsize length);
 
index d6c5412..63cefe2 100644 (file)
@@ -212,7 +212,7 @@ gp11_session_get_info (GP11Session *session)
 
 typedef struct _Login {
        GP11Arguments base;
-       guint32 user_type;
+       gulong user_type;
        guchar *pin;
        gsize n_pin;
 } Login;
@@ -232,14 +232,14 @@ perform_login (Login *args)
 }
 
 gboolean
-gp11_session_login (GP11Session *session, guint32 user_type, const guchar *pin,
+gp11_session_login (GP11Session *session, gulong user_type, const guchar *pin,
                     gsize n_pin, GError **err)
 {
        return gp11_session_login_full (session, user_type, pin, n_pin, NULL, err);
 }
 
 gboolean
-gp11_session_login_full (GP11Session *session, guint32 user_type, const guchar *pin,
+gp11_session_login_full (GP11Session *session, gulong user_type, const guchar *pin,
                          gsize n_pin, GCancellable *cancellable, GError **err)
 {
        Login args = { GP11_ARGUMENTS_INIT, user_type, (guchar*)pin, n_pin };
@@ -248,7 +248,7 @@ gp11_session_login_full (GP11Session *session, guint32 user_type, const guchar *
 }
 
 void
-gp11_session_login_async (GP11Session *session, guint32 user_type, const guchar *pin,
+gp11_session_login_async (GP11Session *session, gulong user_type, const guchar *pin,
                           gsize n_pin, GCancellable *cancellable, GAsyncReadyCallback callback,
                           gpointer user_data)
 {
@@ -662,7 +662,7 @@ crypt_finish (GP11Session *session, GAsyncResult *result, gsize *n_result, GErro
 }
 
 guchar*
-gp11_session_encrypt (GP11Session *session, GP11Object *key, guint mech, const guchar *input,
+gp11_session_encrypt (GP11Session *session, GP11Object *key, gulong mech, const guchar *input,
                       gsize n_input, gsize *n_result, GError **err)
 {
        GP11Mechanism mech_args = { mech, NULL, 0 };
@@ -710,7 +710,7 @@ gp11_session_encrypt_finish (GP11Session *session, GAsyncResult *result, gsize *
 }
 
 guchar*
-gp11_session_decrypt (GP11Session *session, GP11Object *key, guint mech_type, const guchar *input,
+gp11_session_decrypt (GP11Session *session, GP11Object *key, gulong mech_type, const guchar *input,
                       gsize n_input, gsize *n_result, GError **err)
 {
        GP11Mechanism mech_args = { mech_type, NULL, 0 };
@@ -756,7 +756,7 @@ gp11_session_decrypt_finish (GP11Session *session, GAsyncResult *result,
 }
 
 guchar*
-gp11_session_sign (GP11Session *session, GP11Object *key, guint mech_type, const guchar *input,
+gp11_session_sign (GP11Session *session, GP11Object *key, gulong mech_type, const guchar *input,
                    gsize n_input, gsize *n_result, GError **err)
 {
        GP11Mechanism mech_args = { mech_type, NULL, 0 };
@@ -839,7 +839,7 @@ perform_verify (Verify *args)
 }
 
 gboolean
-gp11_session_verify (GP11Session *session, GP11Object *key, guint mech_type, const guchar *input,
+gp11_session_verify (GP11Session *session, GP11Object *key, gulong mech_type, const guchar *input,
                      gsize n_input, const guchar *signature, gsize n_signature, GError **err)
 {
        GP11Mechanism mech_args = { mech_type, NULL, 0 };
index 58e4733..57b62dc 100644 (file)
@@ -36,9 +36,9 @@ G_DEFINE_TYPE (GP11Slot, gp11_slot, G_TYPE_OBJECT);
       (G_TYPE_INSTANCE_GET_PRIVATE((o), GP11_TYPE_SLOT, GP11SlotPrivate))
 
 typedef struct _SessionPool {
-       guint flags;
+       gulong flags;
        GP11Module *module; /* weak */
-       GSList *sessions; /* list of CK_SESSION_HANDLE */
+       GArray *sessions; /* array of CK_SESSION_HANDLE */
 } SessionPool;
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -65,9 +65,11 @@ static void
 free_session_pool (gpointer p)
 {
        SessionPool *pool = p;
-       GSList *l;
-       for (l = pool->sessions; l; l = g_slist_next (l))
-               close_session (pool->module, GPOINTER_TO_UINT (l->data));
+       guint i;
+
+       for(i = 0; i < pool->sessions->len; ++i)
+               close_session (pool->module, g_array_index(pool->sessions, CK_SESSION_HANDLE, i));
+       g_array_free(pool->sessions, TRUE);
        g_free (pool);
 }
 
@@ -78,7 +80,7 @@ foreach_count_sessions (gpointer key, gpointer value, gpointer user_data)
 {
        SessionPool *pool = value;
        guint *result = user_data;
-       *result += g_slist_length (pool->sessions);
+       *result += pool->sessions->len;
 }
 
 static guint
@@ -97,7 +99,7 @@ count_session_table (GP11Slot *slot, guint flags)
 #endif /* UNUSED */
 
 static void
-push_session_table (GP11Slot *slot, guint flags, CK_SESSION_HANDLE handle)
+push_session_table (GP11Slot *slot, gulong flags, CK_SESSION_HANDLE handle)
 {
        GP11SlotPrivate *pv = GP11_SLOT_GET_PRIVATE (slot);
        SessionPool *pool;
@@ -110,20 +112,21 @@ push_session_table (GP11Slot *slot, guint flags, CK_SESSION_HANDLE handle)
        g_assert (handle);
        g_assert (GP11_IS_MODULE (slot->module));
 
-       pool = g_hash_table_lookup (pv->open_sessions, GUINT_TO_POINTER (flags));
+       pool = g_hash_table_lookup (pv->open_sessions, &flags);
        if (!pool) {
                pool = g_new0 (SessionPool, 1);
                pool->flags = flags;
                pool->module = slot->module; /* weak ref */
-               g_hash_table_insert (pv->open_sessions, GUINT_TO_POINTER (flags), pool);
+               pool->sessions = g_array_new (FALSE, TRUE, sizeof (CK_SESSION_HANDLE));
+               g_hash_table_insert (pv->open_sessions, g_memdup (&flags, sizeof (flags)), pool);
        }
 
        g_assert (pool->flags == flags);
-       pool->sessions = g_slist_prepend (pool->sessions, GUINT_TO_POINTER (handle));
+       g_array_append_val (pool->sessions, handle);
 }
 
 static CK_SESSION_HANDLE
-pop_session_table (GP11Slot *slot, guint flags)
+pop_session_table (GP11Slot *slot, gulong flags)
 {
        GP11SlotPrivate *pv = GP11_SLOT_GET_PRIVATE (slot);
        CK_SESSION_HANDLE result;
@@ -134,13 +137,14 @@ pop_session_table (GP11Slot *slot, guint flags)
 
        g_assert (GP11_IS_MODULE (slot->module));
 
-       pool = g_hash_table_lookup (pv->open_sessions, GUINT_TO_POINTER (flags));
+       pool = g_hash_table_lookup (pv->open_sessions, &flags);
        if (!pool)
                return 0;
 
-       result = GPOINTER_TO_UINT (pool->sessions->data);
+       g_assert (pool->sessions->len > 0);
+       result = g_array_index (pool->sessions, CK_SESSION_HANDLE, pool->sessions->len - 1);
        g_assert (result != 0);
-       pool->sessions = g_slist_remove (pool->sessions, pool->sessions->data);
+       g_array_remove_index_fast (pool->sessions, pool->sessions->len - 1);
 
        return result;
 }
@@ -154,19 +158,38 @@ destroy_session_table (GP11Slot *slot)
        pv->open_sessions = NULL;
 }
 
+static guint
+ulong_hash (gconstpointer v)
+{
+       // TODO: I'm sure there's a better gulong hash
+       const signed char *p = v;
+       guint32 i, h = *p;
+
+       for(i = 0; i < sizeof (gulong); ++i)
+               h = (h << 5) - h + *(p++);
+
+       return h;
+}
+
+static gboolean
+ulong_equal (gconstpointer v1, gconstpointer v2)
+{
+       return *((const gulong*)v1) == *((const gulong*)v2);
+}
+
 static void
 create_session_table (GP11Slot *slot)
 {
        GP11SlotPrivate *pv = GP11_SLOT_GET_PRIVATE (slot);
        if (!pv->open_sessions)
-               pv->open_sessions = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, free_session_pool);
+               pv->open_sessions = g_hash_table_new_full (ulong_hash, ulong_equal, g_free, free_session_pool);
 }
 
 static void
 reuse_session_handle (GP11Session *session, GP11Slot *slot)
 {
        CK_SESSION_INFO info;
-       guint flags;
+       gulong *flags;
        CK_RV rv;
 
        g_return_if_fail (GP11_IS_SESSION (session));
@@ -192,18 +215,18 @@ reuse_session_handle (GP11Session *session, GP11Slot *slot)
         * check them against the session's current flags. If they're no
         * longer present, then don't reuse this session.
         */
-       flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (session),
-                                                    "gp11-open-session-flags"));
-       if ((flags & info.flags) != flags)
+       flags = g_object_get_data (G_OBJECT (session), "gp11-open-session-flags");
+       g_return_if_fail (flags);
+       if ((*flags & info.flags) != *flags)
                return;
 
        /* Keep this one around for later use */
-       push_session_table (slot, flags, session->handle);
+       push_session_table (slot, *flags, session->handle);
        session->handle = 0;
 }
 
 static GP11Session*
-make_session_object (GP11Slot *slot, guint flags, CK_SESSION_HANDLE handle)
+make_session_object (GP11Slot *slot, gulong flags, CK_SESSION_HANDLE handle)
 {
        GP11Session *session;
 
@@ -215,7 +238,8 @@ make_session_object (GP11Slot *slot, guint flags, CK_SESSION_HANDLE handle)
        g_signal_connect (session, "discard-handle", G_CALLBACK (reuse_session_handle), slot);
 
        /* Mark the flags on the session for later looking up */
-       g_object_set_data (G_OBJECT (session), "gp11-open-session-flags", GUINT_TO_POINTER (flags));
+       g_object_set_data_full (G_OBJECT (session), "gp11-open-session-flags",
+                               g_memdup (&flags, sizeof (flags)), g_free);
 
        return session;
 }
@@ -542,12 +566,12 @@ gp11_slot_get_token_info (GP11Slot *slot)
        return tokeninfo;
 }
 
-GSList*
+GP11Mechanisms*
 gp11_slot_get_mechanisms (GP11Slot *slot)
 {
        CK_MECHANISM_TYPE_PTR mech_list;
        CK_ULONG count, i;
-       GSList *result;
+       GP11Mechanisms *result;
        CK_RV rv;
 
        g_return_val_if_fail (GP11_IS_SLOT (slot), NULL);
@@ -571,17 +595,17 @@ gp11_slot_get_mechanisms (GP11Slot *slot)
                return NULL;
        }
 
-       result = NULL;
+       result = g_array_new (FALSE, TRUE, sizeof (CK_MECHANISM_TYPE));
        for (i = 0; i < count; ++i)
-               result = g_slist_prepend (result, GUINT_TO_POINTER (mech_list[i]));
+               g_array_append_val (result, mech_list[i]);
 
        g_free (mech_list);
-       return g_slist_reverse (result);
+       return result;
 
 }
 
 GP11MechanismInfo*
-gp11_slot_get_mechanism_info (GP11Slot *slot, guint mech_type)
+gp11_slot_get_mechanism_info (GP11Slot *slot, gulong mech_type)
 {
        GP11MechanismInfo *mechinfo;
        CK_MECHANISM_INFO info;
@@ -658,7 +682,7 @@ gp11_slot_init_token_finish (GP11Slot *slot, GAsyncResult *result, GError **err)
 
 typedef struct OpenSession {
        GP11Arguments base;
-       guint flags;
+       gulong flags;
        CK_SESSION_HANDLE session;
 } OpenSession;
 
@@ -671,13 +695,13 @@ perform_open_session (OpenSession *args)
 }
 
 GP11Session*
-gp11_slot_open_session (GP11Slot *slot, guint flags, GError **err)
+gp11_slot_open_session (GP11Slot *slot, gulong flags, GError **err)
 {
        return gp11_slot_open_session_full (slot, flags, NULL, err);
 }
 
 GP11Session*
-gp11_slot_open_session_full (GP11Slot *slot, guint flags, GCancellable *cancellable, GError **err)
+gp11_slot_open_session_full (GP11Slot *slot, gulong flags, GCancellable *cancellable, GError **err)
 {
        OpenSession args = { GP11_ARGUMENTS_INIT, flags, 0 };
        CK_SESSION_HANDLE handle;
@@ -695,7 +719,7 @@ gp11_slot_open_session_full (GP11Slot *slot, guint flags, GCancellable *cancella
 }
 
 void
-gp11_slot_open_session_async (GP11Slot *slot, guint flags, GCancellable *cancellable,
+gp11_slot_open_session_async (GP11Slot *slot, gulong flags, GCancellable *cancellable,
                               GAsyncReadyCallback callback, gpointer user_data)
 {
        OpenSession *args = _gp11_call_async_prep (slot, slot, perform_open_session,
index 7c4d2fa..bb53c8f 100644 (file)
@@ -25,7 +25,7 @@ const gchar*        gp11_message_from_rv                    (CK_RV rv);
 gchar*              gp11_string_from_chars                  (const guchar *data, gsize max);
 
 typedef struct GP11Mechanism {
-       guint type;
+       gulong type;
        gpointer parameter;
        gulong n_parameter;
 } GP11Mechanism;
@@ -48,48 +48,48 @@ enum {
 };
 
 void                gp11_attribute_init                     (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gconstpointer value,
                                                              gsize length);
 
 void                gp11_attribute_init_invalid             (GP11Attribute *attr,
-                                                             guint attr_type);
+                                                             gulong attr_type);
 
 void                gp11_attribute_init_boolean             (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gboolean value);
 
 void                gp11_attribute_init_date                (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              const GDate *value);
 
 void                gp11_attribute_init_ulong               (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gulong value);
 
 void                gp11_attribute_init_string              (GP11Attribute *attr,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              const gchar *value);
 
 void                gp11_attribute_init_copy                (GP11Attribute *dest,
                                                              GP11Attribute *src);
 
-GP11Attribute*      gp11_attribute_new                      (guint attr_type,
+GP11Attribute*      gp11_attribute_new                      (gulong attr_type,
                                                              gpointer value,
                                                              gsize length);
 
-GP11Attribute*      gp11_attribute_new_invalid              (guint attr_type);
+GP11Attribute*      gp11_attribute_new_invalid              (gulong attr_type);
 
-GP11Attribute*      gp11_attribute_new_boolean              (guint attr_type,
+GP11Attribute*      gp11_attribute_new_boolean              (gulong attr_type,
                                                              gboolean value);
 
-GP11Attribute*      gp11_attribute_new_date                 (guint attr_type,
+GP11Attribute*      gp11_attribute_new_date                 (gulong attr_type,
                                                              const GDate *value);
 
-GP11Attribute*      gp11_attribute_new_ulong                (guint attr_type,
+GP11Attribute*      gp11_attribute_new_ulong                (gulong attr_type,
                                                              gulong value);
 
-GP11Attribute*      gp11_attribute_new_string               (guint attr_type,
+GP11Attribute*      gp11_attribute_new_string               (gulong attr_type,
                                                              const gchar *value);
 
 gboolean            gp11_attribute_is_invalid               (GP11Attribute *attr);
@@ -118,7 +118,7 @@ GType               gp11_attributes_get_boxed_type          (void) G_GNUC_CONST;
 
 GP11Attributes*     gp11_attributes_new                     (void);
 
-GP11Attributes*     gp11_attributes_newv                    (guint attr_type, ...);
+GP11Attributes*     gp11_attributes_newv                    (gulong attr_type, ...);
 
 GP11Attributes*     gp11_attributes_new_valist              (va_list va);
 
@@ -133,46 +133,46 @@ void                gp11_attributes_add                     (GP11Attributes *att
                                                              GP11Attribute *attr);
 
 void                gp11_attributes_add_data                (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gconstpointer value,
                                                              gsize length);
 
 void                gp11_attributes_add_invalid             (GP11Attributes *attrs,
-                                                             guint attr_type);
+                                                             gulong attr_type);
 
 void                gp11_attributes_add_boolean             (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gboolean value);
 
 void                gp11_attributes_add_string              (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              const gchar *string);
 
 void                gp11_attributes_add_date                (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              const GDate *date);
 
 void                gp11_attributes_add_ulong               (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gulong value);
 
 GP11Attribute*      gp11_attributes_find                    (GP11Attributes *attrs,
-                                                             guint attr_type);
+                                                             gulong attr_type);
 
 gboolean            gp11_attributes_find_boolean            (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gboolean *value);
 
 gboolean            gp11_attributes_find_ulong              (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gulong *value);
 
 gboolean            gp11_attributes_find_string             (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              gchar **value);
 
 gboolean            gp11_attributes_find_date               (GP11Attributes *attrs,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              GDate *value);
 
 gulong              gp11_attributes_count                   (GP11Attributes *attrs);
@@ -184,7 +184,6 @@ void                gp11_attributes_unref                   (GP11Attributes *att
 /* -------------------------------------------------------------------------
  * FORWARDS
  */
-
 typedef struct _GP11Slot GP11Slot;
 typedef struct _GP11Module GP11Module;
 typedef struct _GP11Session GP11Session;
@@ -195,15 +194,15 @@ typedef struct _GP11Object GP11Object;
  */
 
 typedef struct _GP11ModuleInfo {
-       guint pkcs11_version_major;
-       guint pkcs11_version_minor;
+       guint8 pkcs11_version_major;
+       guint8 pkcs11_version_minor;
 
        gchar *manufacturer_id;
-       guint32 flags;
+       gulong flags;
 
        gchar *library_description;
-       guint library_version_major;
-       guint library_version_minor;
+       guint8 library_version_major;
+       guint8 library_version_minor;
 } GP11ModuleInfo;
 
 void                gp11_module_info_free                   (GP11ModuleInfo *module_info);
@@ -253,11 +252,11 @@ enum {
 typedef struct _GP11SlotInfo {
        gchar *slot_description;
        gchar *manufacturer_id;
-       guint32 flags;
-       guint hardware_version_major;
-       guint hardware_version_minor;
-       guint firmware_version_major;
-       guint firmware_version_minor;
+       gulong flags;
+       guint8 hardware_version_major;
+       guint8 hardware_version_minor;
+       guint8 firmware_version_major;
+       guint8 firmware_version_minor;
 } GP11SlotInfo;
 
 void                gp11_slot_info_free                      (GP11SlotInfo *slot_info);
@@ -267,7 +266,7 @@ typedef struct _GP11TokenInfo {
        gchar *manufacturer_id;
        gchar *model;
        gchar *serial_number;
-       guint32 flags;
+       gulong flags;
        glong max_session_count;
        glong session_count;
        glong max_rw_session_count;
@@ -278,10 +277,10 @@ typedef struct _GP11TokenInfo {
        glong free_public_memory;
        glong total_private_memory;
        glong free_private_memory;
-       guint hardware_version_major;
-       guint hardware_version_minor;
-       guint firmware_version_major;
-       guint firmware_version_minor;
+       guint8 hardware_version_major;
+       guint8 hardware_version_minor;
+       guint8 firmware_version_major;
+       guint8 firmware_version_minor;
        gint64 utc_time;
 } GP11TokenInfo;
 
@@ -290,11 +289,19 @@ void                gp11_token_info_free                    (GP11TokenInfo *toke
 typedef struct _GP11MechanismInfo {
        gulong min_key_size;
        gulong max_key_size;
-       guint32 flags;
+       gulong flags;
 } GP11MechanismInfo;
 
 void                gp11_mechanism_info_free                (GP11MechanismInfo *mech_info);
 
+typedef GArray GP11Mechanisms;
+
+#define gp11_mechanisms_length(a)      ((a)->len)
+
+#define gp11_mechanisms_at(a, i)       (g_array_index(a, CK_MECHANISM_TYPE, i))
+
+#define gp11_mechanisms_free(a)         (g_array_free(a, TRUE))
+
 #define GP11_TYPE_SLOT             (gp11_slot_get_type())
 #define GP11_SLOT(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GP11_TYPE_SLOT, GP11Slot))
 #define GP11_SLOT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GP11_TYPE_SLOT, GP11Slot))
@@ -345,10 +352,10 @@ GP11SlotInfo*       gp11_slot_get_info                      (GP11Slot *slot);
 
 GP11TokenInfo*      gp11_slot_get_token_info                (GP11Slot *slot);
 
-GSList*             gp11_slot_get_mechanisms                (GP11Slot *slot);
+GP11Mechanisms*     gp11_slot_get_mechanisms                (GP11Slot *slot);
 
 GP11MechanismInfo*  gp11_slot_get_mechanism_info            (GP11Slot *slot,
-                                                             guint32 mech_type);
+                                                             gulong mech_type);
 
 #if UNIMPLEMENTED
 
@@ -373,16 +380,16 @@ gboolean            gp11_slot_init_token_finish             (GP11Slot *slot,
 #endif /* UNIMPLEMENTED */
 
 GP11Session*        gp11_slot_open_session                  (GP11Slot *slot,
-                                                             guint flags,
+                                                             gulong flags,
                                                              GError **err);
 
 GP11Session*        gp11_slot_open_session_full             (GP11Slot *slot,
-                                                             guint flags,
+                                                             gulong flags,
                                                              GCancellable *cancellable,
                                                              GError **err);
 
 void                gp11_slot_open_session_async            (GP11Slot *slot,
-                                                             guint flags,
+                                                             gulong flags,
                                                              GCancellable *cancellable,
                                                              GAsyncReadyCallback callback,
                                                              gpointer user_data);
@@ -396,9 +403,9 @@ GP11Session*        gp11_slot_open_session_finish           (GP11Slot *slot,
  */
 
 typedef struct _GP11SessionInfo {
-       guint32 slot_id;
-       guint32 state;
-       guint32 flags;
+       gulong slot_id;
+       gulong state;
+       gulong flags;
        gulong device_error;
 } GP11SessionInfo;
 
@@ -503,20 +510,20 @@ gboolean            gp11_session_set_operation_state_finish (GP11Session *sessio
 #endif /* UNIMPLEMENTED */
 
 gboolean            gp11_session_login                      (GP11Session *session,
-                                                             guint32 user_type,
+                                                             gulong user_type,
                                                              const guchar *pin,
                                                              gsize n_pin,
                                                              GError **err);
 
 gboolean            gp11_session_login_full                 (GP11Session *session,
-                                                             guint32 user_type,
+                                                             gulong user_type,
                                                              const guchar *pin,
                                                              gsize n_pin,
                                                              GCancellable *cancellable,
                                                              GError **err);
 
 void                gp11_session_login_async                (GP11Session *session,
-                                                             guint32 user_type,
+                                                             gulong user_type,
                                                              const guchar *pin,
                                                              gsize n_pin,
                                                              GCancellable *cancellable,
@@ -654,7 +661,7 @@ guchar*             gp11_session_generate_random_finish     (GP11Session *sessio
 
 guchar*             gp11_session_encrypt                     (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech,
+                                                              gulong mech,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -710,7 +717,7 @@ GP11Processor*      gp11_session_batch_encrypt_finish        (GP11Session *sessi
 #if UNTESTED
 guchar*             gp11_session_decrypt                     (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -761,7 +768,7 @@ GP11Processor*      gp11_session_batch_decrypt_finish        (GP11Session *sessi
                                                               GError **err);
 
 guchar*             gp11_session_digest                      (GP11Session *session,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -866,7 +873,7 @@ GP11Processor*      gp11_session_batch_decrypt_verify_finish (GP11Session *sessi
 
 guchar*             gp11_session_sign                        (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -937,7 +944,7 @@ GP11Processor*      gp11_session_batch_sign_encrypt_finish   (GP11Session *sessi
 
 guchar*             gp11_session_sign_recover                (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -972,7 +979,7 @@ guchar*             gp11_session_sign_recover_finish         (GP11Session *sessi
 
 gboolean            gp11_session_verify                      (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               const guchar *signature,
@@ -1032,7 +1039,7 @@ GkrProcessor*       gp11_session_batch_verify_finish         (GP11Session *sessi
 
 guchar*             gp11_session_verify_recover              (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               gsize *n_result,
@@ -1063,7 +1070,7 @@ guchar*             gp11_session_verify_recover_finish       (GP11Session *sessi
 
 guchar*             gp11_session_wrap                        (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               GP11Object *wrapped_key,
                                                               gsize *n_result,
                                                               GError **err);
@@ -1091,7 +1098,7 @@ guchar*             gp11_session_wrap_finish                 (GP11Session *sessi
 
 GP11Object*         gp11_session_unwrap                      (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               const guchar *input,
                                                               gsize n_input,
                                                               GError **err,
@@ -1122,7 +1129,7 @@ GP11Object*         gp11_session_unwrap_finish               (GP11Session *sessi
 
 GP11Object*         gp11_session_derive                      (GP11Session *session,
                                                               GP11Object *key,
-                                                              guint mech_type,
+                                                              gulong mech_type,
                                                               GError **err,
                                                               ...);
 
@@ -1264,13 +1271,13 @@ GP11Attributes*     gp11_object_get                         (GP11Object *object,
                                                              ...);
 
 GP11Attributes*     gp11_object_get_full                    (GP11Object *object,
-                                                             const guint *attr_types,
+                                                             const gulong *attr_types,
                                                              gsize n_attr_types,
                                                              GCancellable *cancellable,
                                                              GError **err);
 
 void                gp11_object_get_async                   (GP11Object *object,
-                                                             const guint *attr_types,
+                                                             const gulong *attr_types,
                                                              gsize n_attr_types,
                                                              GCancellable *cancellable,
                                                              GAsyncReadyCallback callback,
@@ -1281,16 +1288,16 @@ GP11Attributes*     gp11_object_get_finish                  (GP11Object *object,
                                                              GError **err);
 
 GP11Attribute*      gp11_object_get_one                     (GP11Object *object,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              GError **err);
 
 GP11Attribute*      gp11_object_get_one_full                (GP11Object *object,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              GCancellable *cancellable,
                                                              GError **err);
 
 void                gp11_object_get_one_async               (GP11Object *object,
-                                                             guint attr_type,
+                                                             gulong attr_type,
                                                              GCancellable *cancellable,
                                                              GAsyncReadyCallback callback,
                                                              gpointer user_data);
index 8319188..5e7c573 100644 (file)
@@ -189,7 +189,7 @@ DEFINE_TEST(get_attributes)
        GError *err = NULL;
        gulong klass;
        gchar *value = NULL;
-       guint types[2] = { CKA_CLASS, CKA_LABEL };
+       gulong types[2] = { CKA_CLASS, CKA_LABEL };
 
        /* Simple */
        attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
index f58cee5..1ef6f36 100644 (file)
@@ -101,20 +101,21 @@ DEFINE_TEST(slot_props)
 
 DEFINE_TEST(slot_mechanisms)
 {
-       GSList *mechs, *l;
+       GP11Mechanisms *mechs;
        GP11MechanismInfo *info;
+       guint i;
 
        mechs = gp11_slot_get_mechanisms (slot);
-       g_assert (2 == g_slist_length (mechs) && "wrong number of mech types returned");
+       g_assert (2 == gp11_mechanisms_length (mechs) && "wrong number of mech types returned");
 
-       for (l = mechs; l; l = g_slist_next (l)) {
+       for (i = 0; i < gp11_mechanisms_length (mechs); ++i) {
 
-               info = gp11_slot_get_mechanism_info (slot, GPOINTER_TO_UINT (l->data));
+               info = gp11_slot_get_mechanism_info (slot, gp11_mechanisms_at (mechs, i));
                g_assert (info != NULL && "no mech info returned");
 
                gp11_mechanism_info_free (info);
        }
 
-       g_slist_free (mechs);
+       gp11_mechanisms_free (mechs);
 }