### Struct

# Gck Attribute

#### Description [src]

    struct GckAttribute {
      gulong type;
      guchar value[];
      gulong length;
    }

This structure represents a PKCS#11 `CK_ATTRIBUTE`. These attributes contain information about a PKCS#11 object. Use `gck_object_get()` or `gck_object_set()` to set and 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.

###### Structure members

`type`

  The attribute type, such as `CKA_LABEL`.

`value`

  The value of the attribute. May be `NULL`.

`length`

  The length of the attribute. May be `GCK_INVALID` if the attribute is invalid.

#### Constructors

###### gck_attribute_new

Create a new PKCS#11 attribute. The value will be copied into the new attribute.

###### gck_attribute_new_boolean

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

###### gck_attribute_new_date

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

###### gck_attribute_new_empty

Create a new PKCS#11 attribute with empty data.

###### gck_attribute_new_invalid

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.

###### gck_attribute_new_string

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.

###### gck_attribute_new_ulong

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

#### Instance methods

###### gck_attribute_clear

Clear allocated memory held by a `GckAttribute`.

###### gck_attribute_dump

Dump the specified attribute using g_printerr().

###### gck_attribute_dup

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

###### gck_attribute_equal

Compare two attributes. Useful with `GHashTable`.

###### gck_attribute_free

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

###### gck_attribute_get_boolean

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.

###### gck_attribute_get_data

Get the raw value in the attribute.

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

###### gck_attribute_get_string

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.

###### gck_attribute_get_ulong

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.

###### gck_attribute_hash

Hash an attribute for use in `GHashTable` keys.

###### gck_attribute_init

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

###### gck_attribute_init_boolean

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

###### gck_attribute_init_copy

Initialize a PKCS#11 attribute as a copy of another attribute. This copies the value memory as well.

###### gck_attribute_init_date

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

###### gck_attribute_init_empty

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

###### gck_attribute_init_invalid

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.

###### gck_attribute_init_string

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.

###### gck_attribute_init_ulong

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

###### gck_attribute_is_invalid

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.