10 unstable releases (4 breaking)

0.5.0 Feb 24, 2024
0.4.0 Aug 1, 2023
0.3.0 Feb 25, 2023
0.2.0 Oct 27, 2022
0.1.3 Feb 9, 2022

#67 in Authentication

Download history 1708/week @ 2023-12-31 1830/week @ 2024-01-07 828/week @ 2024-01-14 1136/week @ 2024-01-21 1335/week @ 2024-01-28 1144/week @ 2024-02-04 725/week @ 2024-02-11 1054/week @ 2024-02-18 842/week @ 2024-02-25 813/week @ 2024-03-03 1034/week @ 2024-03-10 595/week @ 2024-03-17 599/week @ 2024-03-24 627/week @ 2024-03-31 600/week @ 2024-04-07 599/week @ 2024-04-14

2,457 downloads per month

MIT license

320KB
8K SLoC

libsecret-rs

The Rust bindings of libsecret.

Documentation


lib.rs:

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?;

Dependencies

~7–17MB
~229K SLoC