#keyring #credentials #cross-platform #password #keychain #api-key

keyring-lib

High-level API for keyring-rs, a cross-platform library to manage secrets

8 unstable releases (3 breaking)

0.4.2 Apr 8, 2024
0.4.1 Apr 6, 2024
0.4.0 Mar 14, 2024
0.3.2 Dec 31, 2023
0.1.0 Aug 27, 2023

#317 in Database interfaces

Download history 70/week @ 2023-12-22 166/week @ 2023-12-29 78/week @ 2024-01-05 71/week @ 2024-01-12 41/week @ 2024-01-19 50/week @ 2024-01-26 42/week @ 2024-02-02 58/week @ 2024-02-09 70/week @ 2024-02-16 113/week @ 2024-02-23 78/week @ 2024-03-01 259/week @ 2024-03-08 190/week @ 2024-03-15 70/week @ 2024-03-22 141/week @ 2024-03-29 537/week @ 2024-04-05

1,037 downloads per month
Used in 9 crates (6 directly)

MIT license

20KB
224 lines

🔐 keyring-lib

Manage credentials using OS-specific keyrings: Secret Service on Linux, Security Framework on MacOS and Security Credentials on Windows.

This library aims to be a High-level API for keyring, a cross-platform library to manage credentials, and can be seen as a convenient wrapper around it:

  • Made the lib async using tokio.
  • Simplified cargo features: tokio by default, tokio-openssl, async-io and async-io-openssl available.
  • Added the cargo feature serde that enables serialization and deserialization of a keyring entry from and to a String.
  • Changed the way the service name is declared: instead of declaring it everytime you declare a keyring entry, you just need to declare it once at the beginning of you program, using the function keyring::set_global_service_name.
  • Added new function find_secret that returns a Result<Option<String>>.
  • Enabled logging using the log crate.
  • Added keyring cache based on the linux keyutils keyring (only works on Linux machines).

See the full API documentation and some examples.

use keyring::{set_global_service_name, KeyringEntry};

#[tokio::main]
async fn main() {
    // define the global keyring service name once
    set_global_service_name("example");

    // create a keyring entry from a key string
    let entry = KeyringEntry::try_new("key").unwrap();

	// define a secret
    entry.set_secret("secret").await.unwrap();

	// get a secret
	entry.get_secret().await.unwrap();

	// find a secret
	entry.find_secret().await.unwrap();

	// deletea secret
    entry.delete_secret().await.unwrap();
}

Development

The development environment is managed by Nix. Running nix-shell will spawn a shell with everything you need to get started with the lib: cargo, cargo-watch, rust-bin, rust-analyzer

# Start a Nix shell
$ nix-shell

# then build the lib
$ cargo build -p keyring-lib

Contributing

A bug tracker is available on SourceHut. [send an email]

A mailing list is available on SourceHut. [send an email] [subscribe] [unsubscribe]

If you want to report a bug, please send an email at ~soywod/pimalaya@todo.sr.ht.

If you want to propose a feature or fix a bug, please send a patch at ~soywod/pimalaya@lists.sr.ht. The simplest way to send a patch is to use git send-email, follow this guide to configure git properly.

If you just want to discuss about the project, feel free to join the Matrix workspace #pimalaya or contact me directly @soywod. You can also use the mailing list.

Sponsoring

nlnet

Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from:

If you appreciate the project, feel free to donate using one of the following providers:

GitHub PayPal Ko-fi Buy Me a Coffee Liberapay

Dependencies

~3–17MB
~189K SLoC