11 releases (6 breaking)

✓ Uses Rust 2018 edition

0.8.0 Jan 31, 2020
0.7.1 Aug 15, 2019
0.7.0 Apr 20, 2019
0.6.1 Sep 25, 2018
0.1.0 Feb 10, 2016

#48 in Cryptography

Download history 283/week @ 2019-12-10 271/week @ 2019-12-17 245/week @ 2019-12-24 226/week @ 2019-12-31 693/week @ 2020-01-07 333/week @ 2020-01-14 474/week @ 2020-01-21 308/week @ 2020-01-28 478/week @ 2020-02-04 545/week @ 2020-02-11 564/week @ 2020-02-18 798/week @ 2020-02-25 716/week @ 2020-03-03 560/week @ 2020-03-10 546/week @ 2020-03-17 4075/week @ 2020-03-24

1,424 downloads per month
Used in 11 crates

MIT/Apache

22KB
357 lines

Keyring-rs

Linux and Mac Build Status Windows Build status Crates.io API Documentation on docs.rs

A cross-platorm library and utility to manage passwords.

Online docs are currently limited to linux, as cross-platform autogenerated docs are not a thing yet. For osx or windows, try cargo doc -p keyring --open.

Published on crates.io

Usage

Currently supports Linux, macOS, and Windows. Please file issues if you have any problems or bugs!

To use this library in your project add the following to your Cargo.toml file:

[dependencies]
keyring = "0.8.0"

This will give you access to the keyring crate in your code. Now you can use the new function to get an instance of the Keyring struct. The new function expects a service name and an username with which it accesses the password.

You can get a password from the OS keyring with the get_password function.

extern crate keyring;

use std::error::Error;

fn main() -> Result<(), Box<Error>> {
  let service = "my_application_name";
  let username = "username";

  let keyring = keyring::Keyring::new(&service, &username);

  let password = keyring.get_password()?;
  println!("The password is '{}'", password);

  Ok(())
}

Passwords can also be added to the keyring using the set_password function.

extern crate keyring;

use std::error::Error;

fn main() -> Result<(), Box<Error>> {
  let service = "my_application_name";
  let username = "username";

  let keyring = keyring::Keyring::new(&service, &username);

  let password = "topS3cr3tP4$$w0rd";
  keyring.set_password(&password)?;

  let password = keyring.get_password()?;
  println!("The password is '{}'", password);

  Ok(())
}

And they can be deleted with the delete_password function.

extern crate keyring;

use std::error::Error;

fn main() -> Result<(), Box<Error>> {
  let service = "my_application_name";
  let username = "username";

  let keyring = keyring::Keyring::new(&service, &username);

  keyring.delete_password()?;

  println!("The password has been deleted");

  Ok(())
}

Errors

The get_password, set_password and delete_password functions return a Result which, if the operation was unsuccessful, can yield a KeyringError.

The KeyringError struct implements the error::Error and fmt::Display traits, so it can be queried for a cause and an description using methods of the same name.

Caveats

Linux

  • The application name is hardcoded to be rust-keyring.

Dev Notes

  • If you're running tests, please use RUST_TEST_THREADS=1 cargo test
  • for TravisCI, osx builds and tests, but linux only builds. Need to figure out how to mock secret service.

License

Licensed under either of

at your option.

Contributors

Thanks to the following for helping make this library better, whether through contributing code, discussion, or bug reports!

  • @dario23
  • @dten
  • @jasikpark
  • @jonathanmorley
  • @lexxvir
  • @Phrohdoh
  • @Rukenshia
  • @samuela
  • @stankec
  • @steveatinfincia
  • @bhkaminski
  • @MaikKlein

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–460KB