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"
§Sync versus async API
The following examples use synchronous functions for simplicit. In a GUI
application however you should use the async Future-based API (e.g
password_store_future
and password_lookup_future
) instead to avoid
blocking the UI.
§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:
use libsecret::*;
let mut attributes = HashMap::new();
attributes.insert("number", SchemaAttributeType::Integer);
attributes.insert("string", SchemaAttributeType::String);
attributes.insert("even", SchemaAttributeType::Boolean);
let schema = Schema::new("com.example.app", 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.
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_sync(
Some(&schema),
attributes,
Some(&collection),
"The Label",
"the password",
gio::Cancellable::NONE
)?;
§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: Option<glib::GString> = libsecret::password_lookup_sync(Some(&schema), attributes, gio::Cancellable::NONE)?;
§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 = HashMap::new();
attributes.insert("number", "8");
attributes.insert("even", "true");
libsecret::password_clear_sync(Some(&schema), attributes, gio::Cancellable::NONE)?;
Re-exports§
pub use ffi;
Modules§
Structs§
- Collection
- A proxy object representing a collection of secrets in the Secret Service.
- Collection
Create Flags - Flags for
create()
. - Collection
Flags - Flags which determine which parts of the #SecretCollection proxy are initialized.
- Item
- A secret item
- Item
Create Flags - Flags for
create()
. - Item
Flags - Flags which determine which parts of the #SecretItem proxy are initialized.
- Prompt
- A prompt in the Service
- Retrievable
- A read-only view of a secret item in the Secret Service.
- Schema
- Represents a set of attributes that are stored with an item.
- Schema
Attribute - An attribute in a #SecretSchema.
- Schema
Flags - Flags for a #SecretSchema definition.
- Search
Flags - Various flags to be used with
ServiceExtManual::search()
andService::search_sync()
. - Service
- A proxy object representing the Secret Service.
- Service
Flags - Flags which determine which parts of the #SecretService proxy are initialized
during a
get()
oropen()
operation. - Value
- A value containing a secret
Enums§
- Error
- Errors returned by the Secret Service.
- Schema
Attribute Type - The type of an attribute in a
SecretSchema
. - Schema
Type - Different types of schemas for storing secrets, intended for use with
schema()
.
Statics§
- COLLECTION_
DEFAULT - An alias to the default collection.
- COLLECTION_
SESSION - An alias to the session collection, which will be cleared when the user ends the session.
Functions§
- password_
clear - Remove unlocked matching passwords from the secret service.
- password_
clear_ future - password_
clear_ sync - Remove unlocked matching passwords from the secret service.
- password_
free - password_
lookup - Lookup a password in the secret service.
- password_
lookup_ binary - password_
lookup_ binary_ future - password_
lookup_ binary_ sync - Lookup a password in the secret service.
- password_
lookup_ future - password_
lookup_ nonpageable - password_
lookup_ nonpageable_ future - password_
lookup_ nonpageable_ sync - Lookup a password in the secret service.
- password_
lookup_ sync - Lookup a password in the secret service.
- password_
search - Search for items in the secret service.
- password_
search_ future - password_
search_ sync - Search for items in the secret service.
- password_
store - Store a password in the secret service.
- password_
store_ binary - Store a password in the secret service.
- password_
store_ binary_ future - password_
store_ binary_ sync - Store a password in the secret service.
- password_
store_ future - password_
store_ sync - Store a password in the secret service.
- password_
wipe - Clear the memory used by a password.
- schema
- Get a secret storage schema of the given @type_.