use clap::{Parser, Subcommand};
mod utils;
pub use utils::{decrypt_files, encrypt_files};
use utils::{
generate_encryption_key_with_options, get_password_or_prompt, inspect_files, Credentials,
};
#[derive(Debug, Subcommand)]
enum Command {
Encrypt {
path: Vec<String>,
#[arg(short, long)]
password: Option<String>,
#[arg(short, long)]
key: Option<String>,
#[arg(short, long)]
wipe: bool,
},
Decrypt {
path: Vec<String>,
#[arg(short, long)]
password: Option<String>,
#[arg(short, long)]
key: Option<String>,
#[arg(short, long)]
wipe: bool,
},
Key {
#[arg(short, long)]
password: Option<String>,
#[arg(short, long, default_value = "900000")]
iterations: usize,
#[arg(short, long)]
salt: Option<String>,
},
Inspect {
path: Vec<String>,
},
}
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[command(subcommand)]
command: Command,
}
fn main() {
let args = Args::parse();
match args.command {
Command::Encrypt {
path,
password,
key,
wipe,
} => match key {
Some(key) => encrypt_files(&Credentials::HexKey(key), path, wipe),
None => {
let password = get_password_or_prompt(password, true);
encrypt_files(&Credentials::Password(password), path, wipe);
}
},
Command::Decrypt {
path,
password,
key,
wipe,
} => match key {
Some(key) => decrypt_files(&Credentials::HexKey(key), path, wipe),
None => {
let password = get_password_or_prompt(password, false);
decrypt_files(&Credentials::Password(password), path, wipe);
}
},
Command::Key {
password,
iterations,
salt,
} => {
let password = get_password_or_prompt(password, true);
generate_encryption_key_with_options(&password, iterations, salt);
}
Command::Inspect { path } => inspect_files(path),
}
}