cryptex 3.0.0

Store and retrieve secrets in OS keyrings, encrypted SQLite or Turso files, in-memory and browser keyrings, or under a YubiHSM 2 or Nitrokey 3
#![cfg(any(
    all(target_os = "macos", feature = "macos-keychain"),
    all(target_os = "windows", feature = "windows-credentials"),
    all(target_os = "linux", feature = "linux-secret-service"),
))]

use cryptex::{DynKeyRing, get_os_keyring};

#[test]
#[ignore = "requires a running OS keyring service"]
fn put_in_box() {
    let mut keyring: Box<dyn DynKeyRing> =
        Box::new(get_os_keyring("cryptex_put_in_box_test").unwrap());
    let res = keyring.set_secret("put_in_box_id", b"put_in_box_value");
    assert!(res.is_ok());
    let res = keyring.get_secret("put_in_box_id");
    assert!(res.is_ok());
    let put_in_box_value = res.unwrap();
    assert_eq!(put_in_box_value.0.as_slice(), b"put_in_box_value");
    let res = keyring.delete_secret("put_in_box_id");
    assert!(res.is_ok());
}

#[test]
#[ignore = "requires a running OS keyring service"]
fn overwrite_then_delete() {
    let mut keyring = get_os_keyring("cryptex_overwrite_test").unwrap();
    assert!(keyring.set_secret("overwrite_id", b"first").is_ok());
    assert!(keyring.set_secret("overwrite_id", b"second").is_ok());
    let res = keyring.get_secret("overwrite_id");
    assert_eq!(res.unwrap().0.as_slice(), b"second");
    assert!(keyring.delete_secret("overwrite_id").is_ok());
    assert!(keyring.get_secret("overwrite_id").is_err());
    assert!(keyring.delete_secret("overwrite_id").is_err());
}