smart-password-manager-cli 0.1.0

Command line interface for smart password management built on smartpasslib. Generate deterministic passwords from secret phrases without storing them.
use anyhow::Result;
use smartpasslib::SmartPasswordManager;

use crate::output;
use crate::secret;

use super::find_entry;

pub fn run(
    key: Option<String>,
    description: Option<String>,
    secret_arg: Option<String>,
    secret_stdin: bool,
) -> Result<()> {
    let manager = SmartPasswordManager::new()?;
    let entry = find_entry(&manager, key, description)?;

    let secret_phrase = secret::resolve_secret(secret_arg, secret_stdin, "Secret phrase: ")?;

    let valid = smartpasslib::verify_secret(&secret_phrase, &entry.public_key)?;

    if valid {
        output::success(&format!("Secret matches entry '{}'", entry.description));
        std::process::exit(0);
    } else {
        output::error("Secret does NOT match");
        std::process::exit(1);
    }
}