Gck.Attribute

Fields

Name

Type

Access

Description

length

int

r/w

The length of the attribute. May be [constINVALID] if the attribute is invalid.

type

int

r/w

The attribute type, such as CKA_LABEL.

value

bytes

r/w

The value of the attribute. May be None.

Methods

class

new (attr_type, value, length)

class

new_boolean (attr_type, value)

class

new_date (attr_type, value)

class

new_empty (attr_type)

class

new_invalid (attr_type)

class

new_string (attr_type, value)

class

new_ulong (attr_type, value)

clear ()

dump ()

dup ()

equal (attr2)

free ()

get_boolean ()

get_data ()

get_date (value)

get_string ()

get_ulong ()

hash ()

init_copy (src)

is_invalid ()

Details

class Gck.Attribute

This structure represents a PKCS#11 CK_ATTRIBUTE. These attributes contain information about a PKCS#11 object. Use [method`Object`.get] or [method`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.

classmethod new(attr_type, value, length)[source]
Parameters:
  • attr_type (int) – the PKCS#11 attribute type to set on the attribute

  • value (int) – the raw value of the attribute

  • length (int) – the length of the attribute

Returns:

the new attribute; when done with the attribute use Gck.Attribute.free() to free it

Return type:

Gck.Attribute

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

classmethod new_boolean(attr_type, value)[source]
Parameters:
  • attr_type (int) – the PKCS#11 attribute type to set on the attribute

  • value (bool) – the boolean value of the attribute

Returns:

the new attribute; when done with the attribute u Gck.Attribute.free() to free it

Return type:

Gck.Attribute

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

classmethod new_date(attr_type, value)[source]
Parameters:
  • attr_type (int) – the PKCS#11 attribute type to set on the attribute

  • value (GLib.Date) – the date value of the attribute

Returns:

the new attribute; when done with the attribute u Gck.Attribute.free() to free it

Return type:

Gck.Attribute

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

classmethod new_empty(attr_type)[source]
Parameters:

attr_type (int) – 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

Return type:

Gck.Attribute

Create a new PKCS#11 attribute with empty data.

classmethod new_invalid(attr_type)[source]
Parameters:

attr_type (int) – 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

Return type:

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

classmethod new_string(attr_type, value)[source]
Parameters:
  • attr_type (int) – the PKCS#11 attribute type to set on the attribute

  • value (str) – the null-terminated string value of the attribute

Returns:

the new attribute; when done with the attribute u Gck.Attribute.free() to free it

Return type:

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

classmethod new_ulong(attr_type, value)[source]
Parameters:
  • attr_type (int) – the PKCS#11 attribute type to set on the attribute

  • value (int) – the ulong value of the attribute

Returns:

the new attribute; when done with the attribute u Gck.Attribute.free() to free it

Return type:

Gck.Attribute

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

clear()[source]

Clear allocated memory held by a Gck.Attribute.

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.

dump()[source]

Dump the specified attribute using g_printerr().

dup()[source]
Returns:

the duplicated attribute; use Gck.Attribute.free() to free it

Return type:

Gck.Attribute

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

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

equal(attr2)[source]
Parameters:

attr2 (Gck.Attribute) – second attribute to compare

Returns:

True if the attributes are equal.

Return type:

bool

Compare two attributes. Useful with GLib.HashTable.

free()[source]

Free an attribute and its allocated memory. These is usually used with attributes that are allocated by [ctor`Attribute`.new] or a similar function.

get_boolean()[source]
Returns:

The boolean value of the attribute.

Return type:

bool

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.

get_data()[source]
Returns:

the value data or None

Return type:

bytes

Get the raw value in the attribute.

This is useful from scripting languages. C callers will generally access the Gck.Attribute struct directly.

This function will None if the attribute contains empty or invalid data. The returned data must not be modified and is only valid as long as this attribute.

get_date(value)[source]
Parameters:

value (GLib.Date) – 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.

get_string()[source]
Returns:

a null terminated string, to be freed with GLib.free(), or None if the value was invalid

Return type:

str or None

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.

get_ulong()[source]
Returns:

The ulong value of the attribute.

Return type:

int

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.

hash()[source]
Returns:

the hash code

Return type:

int

Hash an attribute for use in GLib.HashTable keys.

init_copy(src)[source]
Parameters:

src (Gck.Attribute) – 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 [method`Attribute`.clear] to free the internal memory.

is_invalid()[source]
Returns:

Whether the attribute represents invalid or not.

Return type:

bool

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.