Secret.Value

Fields

None

Methods

class

new (secret, length, content_type)

class

new_full (secret, length, content_type, destroy)

get ()

get_content_type ()

get_text ()

ref ()

unref ()

unref_to_password (length)

Details

class Secret.Value

A value containing a secret

A Secret.Value contains a password or other secret value.

Use [method`Value`.get] to get the actual secret data, such as a password. The secret data is not necessarily null-terminated, unless the content type is “text/plain”.

Each Secret.Value has a content type. For passwords, this is text/plain. Use [method`Value`.get_content_type] to look at the content type.

Secret.Value is reference counted and immutable. The secret data is only freed when all references have been released via [method`Value`.unref].

classmethod new(secret, length, content_type)
Parameters:
  • secret (str) – the secret data

  • length (int) – the length of the data

  • content_type (str) – the content type of the data

Returns:

the new Secret.Value

Return type:

Secret.Value

Create a Secret.Value for the secret data passed in.

The secret data is copied into non-pageable ‘secure’ memory.

If the length is less than zero, then secret is assumed to be null-terminated.

classmethod new_full(secret, length, content_type, destroy)
Parameters:
  • secret (str) – the secret data

  • length (int) – the length of the data

  • content_type (str) – the content type of the data

  • destroy (GLib.DestroyNotify) – function to call to free the secret data

Returns:

the new Secret.Value

Return type:

Secret.Value

Create a Secret.Value for the secret data passed in.

The secret data is not copied, and will later be freed with the destroy function.

If the length is less than zero, then secret is assumed to be null-terminated.

get()
Returns:

the secret data

Return type:

bytes

Get the secret data in the Secret.Value.

The value is not necessarily null-terminated unless it was created with [ctor`Value`.new] or a null-terminated string was passed to [ctor`Value`.new_full].

get_content_type()
Returns:

the content type

Return type:

str

Get the content type of the secret value, such as text/plain.

get_text()
Returns:

the content type

Return type:

str or None

Get the secret data in the Secret.Value if it contains a textual value.

The content type must be text/plain.

ref()
Returns:

the value

Return type:

Secret.Value

Add another reference to the Secret.Value.

For each reference [method`Value`.unref] should be called to unreference the value.

unref()

Unreference a Secret.Value.

When the last reference is gone, then the value will be freed.

unref_to_password(length)
Parameters:

length (int) – the length of the secret

Returns:

a new password string stored in nonpageable memory which must be freed with [func`password_free`] when done

length:

the length of the secret

Return type:

(str, length: int)

Unreference a Secret.Value and steal the secret data in Secret.Value as nonpageable memory.

New in version 0.19.0.