Crate libsecret

Source
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§

prelude

Structs§

Backendv0_19
GLib type: GObject with reference counted clone semantics.
Collection
GLib type: GObject with reference counted clone semantics.
CollectionCreateFlags
CollectionFlags
Item
GLib type: GObject with reference counted clone semantics.
ItemCreateFlags
ItemFlags
Prompt
GLib type: GObject with reference counted clone semantics.
Retrievablev0_19
GLib type: GObject with reference counted clone semantics.
Schema
GLib type: Shared boxed type with reference counted clone semantics.
SchemaAttribute
GLib type: Boxed type with copy-on-clone semantics.
SchemaFlags
SearchFlags
Service
GLib type: GObject with reference counted clone semantics.
ServiceFlags
Value
GLib type: Shared boxed type with reference counted clone semantics.

Enums§

BackendFlagsv0_19
Error
SchemaAttributeType
SchemaTypev0_18_6

Statics§

BACKEND_EXTENSION_POINT_NAME
COLLECTION_DEFAULT
COLLECTION_SESSION

Functions§

password_clear
password_clear_future
password_clear_sync
password_free
password_lookup
password_lookup_binaryv0_19
password_lookup_binary_futurev0_19
password_lookup_binary_syncv0_19
password_lookup_future
password_lookup_nonpageable
password_lookup_nonpageable_future
password_lookup_nonpageable_sync
password_lookup_sync
password_searchv0_19
password_search_futurev0_19
password_search_syncv0_19
password_store
password_store_binaryv0_19
password_store_binary_futurev0_19
password_store_binary_syncv0_19
password_store_future
password_store_sync
password_wipe
schemav0_18_6