getfrompass 0.2.0

Get secret from Pass key-value store
Documentation

getfrompass

A thin wrapper around the Pass password manager for Rust programs. Secrets returned by read functions are wrapped in Zeroizing and zeroed from memory when dropped.

Installation

cargo add getfrompass

Requirements

Pass and GnuPG must be installed and Pass must be initialised with your GPG key.

sudo apt-get install -y pass gnupg
pass init your_gpg_key_id

Usage

Reading a secret

use getfrompass::try_get_from_pass;

fn main() {
    match try_get_from_pass("my/api_token") {
        Some(token) => println!("Got token: {token}"),
        None => println!("Key not found"),
    }
}

Returns Option<Zeroizing<String>>. Zeroizing<String> behaves like String in most contexts via Deref, so existing code rarely needs changes. If you need an explicit type annotation, add zeroize as a dependency (cargo add zeroize).

If you'd rather panic on a missing key, get_from_pass does that.

Storing a known value

use getfrompass::store_in_pass;

fn main() {
    if store_in_pass("my/api_token", "s3cr3t") {
        println!("Stored.");
    } else {
        println!("Key already exists, nothing written.");
    }
}

To overwrite an existing entry, use force_store_in_pass.

Generating a random password

use getfrompass::insert_to_pass;

fn main() {
    let password = insert_to_pass("my/generated_key", 16);
    println!("Generated: {password}");
}

Deleting an entry

use getfrompass::remove_from_pass;

fn main() {
    remove_from_pass("my/api_token");
}

This deletes without confirmation.