GckAttribute

## GckAttribute GckAttribute — A PKCS11 attribute. |

## Synopsis

    struct              GckAttribute;
    gboolean            gck_attribute_is_invalid            (const GckAttribute *attr);
    gboolean            gck_attribute_get_boolean           (const GckAttribute *attr);
    gulong              gck_attribute_get_ulong             (const GckAttribute *attr);
    gchar *             gck_attribute_get_string            (const GckAttribute *attr);
    void                gck_attribute_get_date              (const GckAttribute *attr,
                                                             GDate *value);
    void                gck_attribute_dump                  (const GckAttribute *attr);
    gboolean            gck_attribute_equal                 (gconstpointer attr1,
                                                             gconstpointer attr2);
    guint               gck_attribute_hash                  (gconstpointer attr);
    void                gck_attribute_init                  (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const guchar *value,
                                                             gsize length);
    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_string           (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const gchar *value);
    void                gck_attribute_init_ulong            (GckAttribute *attr,
                                                             gulong attr_type,
                                                             gulong value);
    void                gck_attribute_init_empty            (GckAttribute *attr,
                                                             gulong attr_type);
    void                gck_attribute_init_invalid          (GckAttribute *attr,
                                                             gulong attr_type);
    void                gck_attribute_init_copy             (GckAttribute *dest,
                                                             const GckAttribute *src);
    GckAttribute *      gck_attribute_new                   (gulong attr_type,
                                                             const guchar *value,
                                                             gsize length);
    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_string            (gulong attr_type,
                                                             const gchar *value);
    GckAttribute *      gck_attribute_new_ulong             (gulong attr_type,
                                                             gulong value);
    GckAttribute *      gck_attribute_new_empty             (gulong attr_type);
    GckAttribute *      gck_attribute_new_invalid           (gulong attr_type);
    GckAttribute *      gck_attribute_dup                   (const GckAttribute *attr);
    void                gck_attribute_clear                 (GckAttribute *attr);
    void                gck_attribute_free                  (gpointer attr);

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

Although you are free to allocate a GckAttribute in your own code, no functions in this library will operate on such an attribute.

## Details

### struct GckAttribute

    struct GckAttribute {
    	gulong type;
    	guchar *value;
    	gulong length;
    };

This structure represents a PKCS11 CK_ATTRIBUTE.

gulong `type`; | The attribute type, such as CKA_LABEL.
guchar *`value`; | The value of the attribute. May be NULL. [array length=length]
gulong `length`; | The length of the attribute. May be G_MAXULONG if the attribute is invalid.

### gck_attribute_is_invalid ()

    gboolean            gck_attribute_is_invalid            (const 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           (const 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             (const 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            (const 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 was invalid. [allow-none]

### gck_attribute_get_date ()

    void                gck_attribute_get_date              (const 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_dump ()

    void                gck_attribute_dump                  (const GckAttribute *attr);

Dump the specified attribute using `g_printerr()`.

`attr` : | The attribute

### gck_attribute_equal ()

    gboolean            gck_attribute_equal                 (gconstpointer attr1,
                                                             gconstpointer attr2);

Compare two attributes. Useful with `GHashTable`.

`attr1` : | first attribute to compare. [type Gck.Attribute]
`attr2` : | second attribute to compare. [type Gck.Attribute]
Returns : | `TRUE` if the attributes are equal.

### gck_attribute_hash ()

    guint               gck_attribute_hash                  (gconstpointer attr);

Hash an attribute for use in `GHashTable` keys.

`attr` : | attribute to hash. [type Gck.Attribute]
Returns : | the hash code

### gck_attribute_init ()

    void                gck_attribute_init                  (GckAttribute *attr,
                                                             gulong attr_type,
                                                             const guchar *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. [array length=length]
`length` : | The length of the raw value.

### 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_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_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_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_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_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,
                                                             const guchar *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. [transfer full]

### 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 u `gck_attribute_free()` to free it. [transfer full]

### 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 u `gck_attribute_free()` to free it. [transfer full]

### 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 u `gck_attribute_free()` to free it. [transfer full]

### 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 u `gck_attribute_free()` to free it. [transfer full]

### 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. [transfer full]

### 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. [transfer full]

### gck_attribute_dup ()

    GckAttribute *      gck_attribute_dup                   (const GckAttribute *attr);

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

The `attr` must have been allocated or initialized by a Gck function or the results of this function are undefined.

`attr` : | the attribute to duplicate
Returns : | the duplicated attribute; use `gck_attribute_free()` to free it. [transfer full]

### gck_attribute_clear ()

    void                gck_attribute_clear                 (GckAttribute *attr);

Clear allocated memory held by a GckAttribute.

This attribute must have been allocated by a Gck library function, or the results of this method are undefined.

The type of the attribute will remain set.

`attr` : | Attribute to clear.

### gck_attribute_free ()

    void                gck_attribute_free                  (gpointer 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. [type Gck.Attribute]