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
//! Keep secrets under a Nitrokey 3, or any FIDO2 key with `hmac-secret`.
//!
//! The first run creates a credential (one touch) and prints a connection
//! string; keep it and pass it back in `CRYPTEX_NITROKEY`. Each `set` and
//! `get` asks for a touch.
//!
//! ```bash
//! cargo run --example nitrokey --no-default-features --features nitrokey
//! CRYPTEX_NITROKEY="credential=<hex> service=example" \
//!     cargo run --example nitrokey --no-default-features --features nitrokey
//! ```

#[cfg(feature = "nitrokey")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    use cryptex::nitrokey::NitrokeyKeyRing;
    use cryptex::{KeyRing, NewKeyRing};

    let Ok(conn) = std::env::var("CRYPTEX_NITROKEY") else {
        eprintln!("Touch your security key to create a credential.");
        let credential = NitrokeyKeyRing::setup("")?;
        println!(
            "CRYPTEX_NITROKEY=\"credential={} service=example\"",
            credential
        );
        return Ok(());
    };

    let mut keyring = NitrokeyKeyRing::new(&conn)?;
    keyring.set_secret("example", b"kept under the security key")?;
    let secret = keyring.get_secret("example")?;
    println!("example: {}", String::from_utf8_lossy(secret.as_slice()));
    for entry in keyring.list_secrets()? {
        println!("{:?}", entry);
    }
    keyring.delete_secret("example")?;
    Ok(())
}

#[cfg(not(feature = "nitrokey"))]
fn main() {
    eprintln!("Run with --features nitrokey");
}