GckAttribute

## GckAttribute GckAttribute — A PKCS11 attribute. |

## Synopsis

                        GckAttribute;
    void                gck_attribute_init                  (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gconstpointer value,
                                                             gsize length);
    void                gck_attribute_init_invalid          (GckAttribute *attr,
                                                             gulong attr_type);
    void                gck_attribute_init_empty            (GckAttribute *attr,
                                                             gulong attr_type);
    void                gck_attribute_init_boolean          (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gboolean value);
    void                gck_attribute_init_date             (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const GDate *value);
    void                gck_attribute_init_ulong            (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gulong value);
    void                gck_attribute_init_string           (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const gchar *value);
    void                gck_attribute_init_copy             (GckAttribute *dest,
                                                             const GckAttribute *src);
    GckAttribute *      gck_attribute_new                   (gulong attr_type,
                                                             gpointer value,
                                                             gsize length);
    GckAttribute *      gck_attribute_new_invalid           (gulong attr_type);
    GckAttribute *      gck_attribute_new_empty             (gulong attr_type);
    GckAttribute *      gck_attribute_new_boolean           (gulong attr_type,
                                                             gboolean value);
    GckAttribute *      gck_attribute_new_date              (gulong attr_type,
                                                             const GDate *value);
    GckAttribute *      gck_attribute_new_ulong             (gulong attr_type,
                                                             gulong value);
    GckAttribute *      gck_attribute_new_string            (gulong attr_type,
                                                             const gchar *value);
    gboolean            gck_attribute_is_invalid            (GckAttribute *attr);
    gboolean            gck_attribute_get_boolean           (GckAttribute *attr);
    gulong              gck_attribute_get_ulong             (GckAttribute *attr);
    gchar *             gck_attribute_get_string            (GckAttribute *attr);
    void                gck_attribute_get_date              (GckAttribute *attr,
                                                             GDate *value);
    GckAttribute *      gck_attribute_dup                   (GckAttribute *attr);
    void                gck_attribute_clear                 (GckAttribute *attr);
    void                gck_attribute_free                  (GckAttribute *attr);
    void                gck_attribute_dump                  (GckAttribute *attr);
    gboolean            gck_attribute_equal                 (gconstpointer a,
                                                             gconstpointer b);

## Description

This structure represents a PKCS11 CK_ATTRIBUTE. These attributes contain information about a PKCS11 object. Use `gck_object_get()` or `gck_object_set()` to set and retrieve attributes on an object.

## Details

### GckAttribute

    typedef struct {
    	gulong type;
    	gconstpointer value;
    	gulong length;
    } GckAttribute;

This structure represents a PKCS11 CK_ATTRIBUTE.

gulong `type`; | The attribute type, such as CKA_LABEL.
gconstpointer `value`; | The value of the attribute. May be NULL.
gulong `length`; | The length of the attribute. May be G_MAXULONG if the attribute is invalid.

### gck_attribute_init ()

    void                gck_attribute_init                  (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gconstpointer value,
                                                             gsize length);

Initialize a PKCS#11 attribute. This copies the value memory into an internal buffer.

When done with the attribute you should use `gck_attribute_clear()` to free the internal memory.

`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.

### gck_attribute_init_invalid ()

    void                gck_attribute_init_invalid          (GckAttribute *attr,
                                                             gulong attr_type);

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 `gck_attribute_clear()` to free the internal memory.

`attr` : | An uninitialized attribute.
`attr_type` : | The PKCS#11 attribute type to set on the attribute.

### gck_attribute_init_empty ()

    void                gck_attribute_init_empty            (GckAttribute *attr,
                                                             gulong attr_type);

Initialize a PKCS#11 attribute to an empty state. The attribute type will be set, but no data will be set.

When done with the attribute you should use `gck_attribute_clear()` to free the internal memory.

`attr` : | An uninitialized attribute.
`attr_type` : | The PKCS#11 attribute type to set on the attribute.

### gck_attribute_init_boolean ()

    void                gck_attribute_init_boolean          (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gboolean value);

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 `gck_attribute_clear()` to free the internal memory.

`attr` : | An uninitialized attribute.
`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The boolean value of the attribute.

### gck_attribute_init_date ()

    void                gck_attribute_init_date             (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const GDate *value);

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 `gck_attribute_clear()` to free the internal memory.

`attr` : | An uninitialized attribute.
`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The date value of the attribute.

### gck_attribute_init_ulong ()

    void                gck_attribute_init_ulong            (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gulong value);

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 `gck_attribute_clear()` to free the internal memory.

`attr` : | An uninitialized attribute.
`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The ulong value of the attribute.

### gck_attribute_init_string ()

    void                gck_attribute_init_string           (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const gchar *value);

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 `gck_attribute_clear()` to free the internal memory.

`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.

### gck_attribute_init_copy ()

    void                gck_attribute_init_copy             (GckAttribute *dest,
                                                             const GckAttribute *src);

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 `gck_attribute_clear()` to free the internal memory.

`dest` : | An uninitialized attribute.
`src` : | An attribute to copy.

### gck_attribute_new ()

    GckAttribute *      gck_attribute_new                   (gulong attr_type,
                                                             gpointer value,
                                                             gsize length);

Create a new PKCS#11 attribute. The value will be copied into the new 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 attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_invalid ()

    GckAttribute *      gck_attribute_new_invalid           (gulong attr_type);

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.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_empty ()

    GckAttribute *      gck_attribute_new_empty             (gulong attr_type);

Create a new PKCS#11 attribute with empty data.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_boolean ()

    GckAttribute *      gck_attribute_new_boolean           (gulong attr_type,
                                                             gboolean value);

Initialize a PKCS#11 attribute to boolean. This will result in a CK_BBOOL attribute from the PKCS#11 specs.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The boolean value of the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_date ()

    GckAttribute *      gck_attribute_new_date              (gulong attr_type,
                                                             const GDate *value);

Initialize a PKCS#11 attribute to a date. This will result in a CK_DATE attribute from the PKCS#11 specs.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The date value of the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_ulong ()

    GckAttribute *      gck_attribute_new_ulong             (gulong attr_type,
                                                             gulong value);

Initialize a PKCS#11 attribute to a unsigned long. This will result in a CK_ULONG attribute from the PKCS#11 specs.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The ulong value of the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_new_string ()

    GckAttribute *      gck_attribute_new_string            (gulong attr_type,
                                                             const gchar *value);

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.

`attr_type` : | The PKCS#11 attribute type to set on the attribute.
`value` : | The null terminated string value of the attribute.
Returns : | The new attribute. When done with the attribute use `gck_attribute_free()` to free it.

### gck_attribute_is_invalid ()

    gboolean            gck_attribute_is_invalid            (GckAttribute *attr);

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.

`attr` : | The attribute to check.
Returns : | Whether the attribute represents invalid or not.

### gck_attribute_get_boolean ()

    gboolean            gck_attribute_get_boolean           (GckAttribute *attr);

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.

`attr` : | The attribute to retrieve value from.
Returns : | The boolean value of the attribute.

### gck_attribute_get_ulong ()

    gulong              gck_attribute_get_ulong             (GckAttribute *attr);

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.

`attr` : | The attribute to retrieve value from.
Returns : | The ulong value of the attribute.

### gck_attribute_get_string ()

    gchar *             gck_attribute_get_string            (GckAttribute *attr);

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.

`attr` : | The attribute to retrieve value from.
Returns : | A null terminated string, to be freed with `g_free()`, or NULL if the value contained a NULL string.

### gck_attribute_get_date ()

    void                gck_attribute_get_date              (GckAttribute *attr,
                                                             GDate *value);

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.

`attr` : | The attribute to retrieve value from.
`value` : | The date value to fill in with the parsed date.

### gck_attribute_dup ()

    GckAttribute *      gck_attribute_dup                   (GckAttribute *attr);

Duplicate the PKCS#11 attribute. All value memory is also copied.

`attr` : | The attribute to duplicate.
Returns : | The duplicated attribute. Use `gck_attribute_free()` to free it.

### gck_attribute_clear ()

    void                gck_attribute_clear                 (GckAttribute *attr);

Clear allocated memory held by a statically allocated attribute. These are usually initialized with `gck_attribute_init()` or a similar function.

The type of the attribute will remain set.

`attr` : | Attribute to clear.

### gck_attribute_free ()

    void                gck_attribute_free                  (GckAttribute *attr);

Free an attribute and its allocated memory. These is usually used with attributes that are allocated by `gck_attribute_new()` or a similar function.

`attr` : | Attribute to free.

### gck_attribute_dump ()

    void                gck_attribute_dump                  (GckAttribute *attr);

Dump the specified attribute using `g_printerr()`.

`attr` : | The attribute

### gck_attribute_equal ()

    gboolean            gck_attribute_equal                 (gconstpointer a,
                                                             gconstpointer b);

Compare two attributes. Useful with `GHashTable`.

`a` : | First attribute to compare.
`b` : | Second attribute to compare.
Returns : | `TRUE` if the attributes are equal.