Expand description

Rust Libsecret bindings

This library contains safe Rust bindings for Libsecret, a library that offers access to the Secret Service API.

See also

Usage

You can add libsecret by adding it in your Cargo.toml file:

[dependencies.secret]
package = "libsecret"
version = "0.x.y"

Define a password schema

Each stored password has a set of attributes which are later used to lookup the password. The names and types of the attributes are defined in a schema. The schema is usually defined once globally. Here’s how to define a schema:

let mut attributes = std::collections::HashMap::new();
attributes.insert("number", libsecret::SchemaAttributeType::Integer);
attributes.insert("string", libsecret::SchemaAttributeType::String);
attributes.insert("even", libsecret::SchemaAttributeType::Boolean);

let schema = libsecret::Schema::new("some.app.Id", libsecret::SchemaFlags::NONE, attributes);

Store a password

Each stored password has a set of attributes which are later used to lookup the password. The attributes should not contain secrets, as they are not stored in an encrypted fashion.

This first example stores a password asynchronously, and is appropriate for GUI applications so that the UI does not block.

let mut attributes = std::collections::HashMap::new();
attributes.insert("number", "8");
attributes.insert("string", "eight");
attributes.insert("even", "true");

let collection = libsecret::COLLECTION_DEFAULT;
libsecret::password_store_future(Some(&schema), attributes, Some(&collection), "The Label", "the password").await?;

Lookup a password

Each stored password has a set of attributes which are used to lookup the password. If multiple passwords match the lookup attributes, then the one stored most recently is returned.

This first example looks up a password asynchronously, and is appropriate for GUI applications so that the UI does not block.

let mut attributes = std::collections::HashMap::new();
attributes.insert("number", "8");
attributes.insert("even", "true");

let password = libsecret::password_lookup_future(Some(&schema), attributes).await?;

Remove a password

Each stored password has a set of attributes which are used to find which password to remove. If multiple passwords match the attributes, then the one stored most recently is removed.

This first example removes a password asynchronously, and is appropriate for GUI applications so that the UI does not block.

let mut attributes = std::collections::HashMap::new();
attributes.insert("number", "8");
attributes.insert("even", "true");

libsecret::password_clear_future(Some(&schema), attributes).await?;

Re-exports

pub use ffi;

Modules

Structs

Backendv0_19
#SecretBackend represents a backend implementation of password storage.
A proxy object representing a collection of secrets in the Secret Service.
Flags which determine which parts of the #SecretCollection proxy are initialized.
A secret item
Flags which determine which parts of the #SecretItem proxy are initialized.
A prompt in the Service
A read-only view of a secret item in the Secret Service.
Represents a set of attributes that are stored with an item.
An attribute in a #SecretSchema.
Flags for a #SecretSchema definition.
Various flags to be used with ServiceExtManual::search() and Service::search_sync().
A proxy object representing the Secret Service.
Flags which determine which parts of the #SecretService proxy are initialized during a Backend::get() or Service::open() operation.
A value containing a secret

Enums

Flags which determine which parts of the #SecretBackend are initialized.
Errors returned by the Secret Service.
The type of an attribute in a SecretSchema.
SchemaTypev0_18_6
Different types of schemas for storing secrets, intended for use with schema().

Statics

Extension point for the secret backend.
An alias to the default collection.
An alias to the session collection, which will be cleared when the user ends the session.

Functions

Remove unlocked matching passwords from the secret service.
Remove unlocked matching passwords from the secret service.
Lookup a password in the secret service.
Lookup a password in the secret service.
Lookup a password in the secret service.
Lookup a password in the secret service.
Search for items in the secret service.
Search for items in the secret service.
Store a password in the secret service.
Store a password in the secret service.
Store a password in the secret service.
Store a password in the secret service.
Clear the memory used by a password.
schemav0_18_6
Get a secret storage schema of the given @type_.