## GckAttributes

GckAttributes — A set of PKCS11 attributes.

## Synopsis

                        GckAttributes;
    GckAttributes *     gck_attributes_new                  (void);
    GckAttributes *     gck_attributes_new_empty            (gulong attr_type,
                                                             ...);
    GckAttribute *      gck_attributes_at                   (GckAttributes *attrs,
                                                             guint index);
    GckAttribute *      gck_attributes_add                  (GckAttributes *attrs,
                                                             GckAttribute *attr);
    GckAttribute *      gck_attributes_add_data             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const guchar *value,
                                                             gsize length);
    GckAttribute *      gck_attributes_add_invalid          (GckAttributes *attrs,
                                                             gulong attr_type);
    GckAttribute *      gck_attributes_add_empty            (GckAttributes *attrs,
                                                             gulong attr_type);
    GckAttribute *      gck_attributes_add_boolean          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean value);
    GckAttribute *      gck_attributes_add_string           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const gchar *value);
    GckAttribute *      gck_attributes_add_date             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const GDate *value);
    GckAttribute *      gck_attributes_add_ulong            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong value);
    void                gck_attributes_add_all              (GckAttributes *attrs,
                                                             GckAttributes *from);
    void                gck_attributes_set_boolean          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean value);
    void                gck_attributes_set_string           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const gchar *value);
    void                gck_attributes_set_date             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const GDate *value);
    void                gck_attributes_set_ulong            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong value);
    GckAttribute *      gck_attributes_find                 (GckAttributes *attrs,
                                                             gulong attr_type);
    gboolean            gck_attributes_find_boolean         (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean *value);
    gboolean            gck_attributes_find_ulong           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong *value);
    gboolean            gck_attributes_find_string          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gchar **value);
    gboolean            gck_attributes_find_date            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             GDate *value);
    gulong              gck_attributes_count                (GckAttributes *attrs);
    GckAttributes *     gck_attributes_ref                  (GckAttributes *attrs);
    void                gck_attributes_unref                (gpointer attrs);
    gboolean            gck_attributes_contains             (GckAttributes *attrs,
                                                             GckAttribute *match);
    void                gck_attributes_dump                 (GckAttributes *attrs);
    GckAttributes *     gck_attributes_new_full             (GckAllocator allocator);
    #define             GCK_TYPE_ATTRIBUTES
    gpointer            (*GckAllocator)                     (gpointer data,
                                                             gsize length);

## Object Hierarchy

      GBoxed
       +----GckAttributes

## Description

A set of GckAttribute structures. 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

### GckAttributes

    typedef struct _GckAttributes GckAttributes;

A set of GckAttribute structures.

### gck_attributes_new ()

    GckAttributes *     gck_attributes_new                  (void);

Create a new GckAttributes array.

Returns : | the new attributes array; when done with the array release it with `gck_attributes_unref()`. [transfer full]

### gck_attributes_new_empty ()

    GckAttributes *     gck_attributes_new_empty            (gulong attr_type,
                                                             ...);

Creates an GckAttributes array with empty attributes. The arguments should be values of attribute types, terminated with gck_INVALID.

`attr_type` : | The first attribute type to add as empty.
`...` : | The arguments should be values of attribute types, terminated with gck_INVALID.
Returns : | the new attributes array; when done with the array release it with `gck_attributes_unref()`. [transfer full]

### gck_attributes_at ()

    GckAttribute *      gck_attributes_at                   (GckAttributes *attrs,
                                                             guint index);

Get attribute at the specified index in the attribute array.

Use `gck_attributes_count()` to determine how many attributes are in the array.

`attrs` : | The attributes array.
`index` : | The attribute index to retrieve.
Returns : | the specified attribute. [transfer none]

### gck_attributes_add ()

    GckAttribute *      gck_attributes_add                  (GckAttributes *attrs,
                                                             GckAttribute *attr);

Add the specified attribute to the array.

The value stored in the attribute will be copied.

`attrs` : | The attributes array to add to
`attr` : | The attribute to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_data ()

    GckAttribute *      gck_attributes_add_data             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const guchar *value,
                                                             gsize length);

Add an attribute with the specified type and value to the array.

The value stored in the attribute will be copied.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
`value` : | the raw memory of the attribute value. [array length=length]
`length` : | The length of the attribute value.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_invalid ()

    GckAttribute *      gck_attributes_add_invalid          (GckAttributes *attrs,
                                                             gulong attr_type);

Add an attribute with the specified type and an 'invalid' value to the array.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_empty ()

    GckAttribute *      gck_attributes_add_empty            (GckAttributes *attrs,
                                                             gulong attr_type);

Add an attribute with the specified type, with empty data.

`attrs` : | The attributes array to add.
`attr_type` : | The type of attribute to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_boolean ()

    GckAttribute *      gck_attributes_add_boolean          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean value);

Add an attribute with the specified type and value to the array.

The value will be stored as a CK_BBOOL PKCS#11 style attribute.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
`value` : | The boolean value to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_string ()

    GckAttribute *      gck_attributes_add_string           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const gchar *value);

Add an attribute with the specified type and value to the array.

The value will be copied into the attribute.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
`value` : | The null terminated string value to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_date ()

    GckAttribute *      gck_attributes_add_date             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const GDate *value);

Add an attribute with the specified type and value to the array.

The value will be stored as a CK_DATE PKCS#11 style attribute.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
`value` : | The GDate value to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_ulong ()

    GckAttribute *      gck_attributes_add_ulong            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong value);

Add an attribute with the specified type and value to the array.

The value will be stored as a CK_ULONG PKCS#11 style attribute.

`attrs` : | The attributes array to add to.
`attr_type` : | The type of attribute to add.
`value` : | The gulong value to add.
Returns : | the attribute that was added. [transfer none]

### gck_attributes_add_all ()

    void                gck_attributes_add_all              (GckAttributes *attrs,
                                                             GckAttributes *from);

Add all attributes in `from` to `attrs`.

`attrs` : | A set of attributes
`from` : | Attributes to add

### gck_attributes_set_boolean ()

    void                gck_attributes_set_boolean          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean value);

Set the attribute of attr_type in the attribute array to the given value. If no such value exists, then add one.

`attrs` : | the attributes
`attr_type` : | the type of attribute to set
`value` : | boolean value to set

### gck_attributes_set_string ()

    void                gck_attributes_set_string           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const gchar *value);

Set the attribute of attr_type in the attribute array to the given value. If no such value exists, then add one.

`attrs` : | the attributes
`attr_type` : | the type of attribute to set
`value` : | null terminated string value to set

### gck_attributes_set_date ()

    void                gck_attributes_set_date             (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             const GDate *value);

Set the attribute of attr_type in the attribute array to the given value. If no such value exists, then add one.

`attrs` : | the attributes
`attr_type` : | the type of attribute to set
`value` : | date value to set

### gck_attributes_set_ulong ()

    void                gck_attributes_set_ulong            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong value);

Set the attribute of attr_type in the attribute array to the given value. If no such value exists, then add one.

`attrs` : | the attributes
`attr_type` : | the type of attribute to set
`value` : | gulong value to set

### gck_attributes_find ()

    GckAttribute *      gck_attributes_find                 (GckAttributes *attrs,
                                                             gulong attr_type);

Find an attribute with the specified type in the array.

`attrs` : | The attributes array to search.
`attr_type` : | The type of attribute to find.
Returns : | the first attribute found with the specified type, or `NULL`. [transfer none]

### gck_attributes_find_boolean ()

    gboolean            gck_attributes_find_boolean         (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gboolean *value);

Find an attribute with the specified type in the array.

The attribute (if found) must be of the right size to store a boolean value (ie: CK_BBOOL). If the attribute is marked invalid then it will be treated as not found.

`attrs` : | The attributes array to search.
`attr_type` : | The type of attribute to find.
`value` : | The resulting gboolean value.
Returns : | Whether a value was found or not.

### gck_attributes_find_ulong ()

    gboolean            gck_attributes_find_ulong           (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gulong *value);

Find an attribute with the specified type in the array.

The attribute (if found) must be of the right size to store a unsigned long value (ie: CK_ULONG). If the attribute is marked invalid then it will be treated as not found.

`attrs` : | The attributes array to search.
`attr_type` : | The type of attribute to find.
`value` : | The resulting gulong value.
Returns : | Whether a value was found or not.

### gck_attributes_find_string ()

    gboolean            gck_attributes_find_string          (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             gchar **value);

Find an attribute with the specified type in the array.

If the attribute is marked invalid then it will be treated as not found. The resulting string will be null-terminated, and must be freed by the caller using `g_free()`.

`attrs` : | The attributes array to search.
`attr_type` : | The type of attribute to find.
`value` : | The resulting string value.
Returns : | Whether a value was found or not.

### gck_attributes_find_date ()

    gboolean            gck_attributes_find_date            (GckAttributes *attrs,
                                                             gulong attr_type,
                                                             GDate *value);

Find an attribute with the specified type in the array.

The attribute (if found) must be of the right size to store a date value (ie: CK_DATE). If the attribute is marked invalid then it will be treated as not found.

`attrs` : | The attributes array to search.
`attr_type` : | The type of attribute to find.
`value` : | The resulting GDate value.
Returns : | Whether a value was found or not.

### gck_attributes_count ()

    gulong              gck_attributes_count                (GckAttributes *attrs);

Get the number of attributes in this attribute array.

`attrs` : | The attributes array to count.
Returns : | The number of contained attributes.

### gck_attributes_ref ()

    GckAttributes *     gck_attributes_ref                  (GckAttributes *attrs);

Reference this attributes array.

`attrs` : | An attribute array
Returns : | the attributes. [transfer full]

### gck_attributes_unref ()

    void                gck_attributes_unref                (gpointer attrs);

Unreference this attribute array.

When all outstanding references are NULL, the array will be freed.

`attrs` : | An attribute array

### gck_attributes_contains ()

    gboolean            gck_attributes_contains             (GckAttributes *attrs,
                                                             GckAttribute *match);

Check whether the attributes contain a certain attribute.

`attrs` : | The attributes to check
`match` : | The attribute to find
Returns : | `TRUE` if the attributes contain the attribute.

### gck_attributes_dump ()

    void                gck_attributes_dump                 (GckAttributes *attrs);

Dump the attributes using `g_printerr()`.

`attrs` : | The attributes

### gck_attributes_new_full ()

    GckAttributes *     gck_attributes_new_full             (GckAllocator allocator);

Create a new GckAttributes array.

`allocator` : | Memory allocator for attribute data, or NULL for default.
Returns : | the new attributes array; when done with the array release it with `gck_attributes_unref()`. [transfer full]

### GCK_TYPE_ATTRIBUTES

    #define             GCK_TYPE_ATTRIBUTES                     (gck_attributes_get_boxed_type ())

Boxed type for GckAttributes

### GckAllocator ()

    gpointer            (*GckAllocator)                     (gpointer data,
                                                             gsize length);

An allocator used to allocate data for the attributes in this GckAttributes set.

This is a function that acts like g_realloc. Specifically it frees when length is set to zero, it allocates when data is set to NULL, and it reallocates when both are valid.

`data` : | Memory to allocate or deallocate.
`length` : | New length of memory.
Returns : | The allocated memory, or NULL when freeing.