//! use std::{ env, fs::File, path::{Path, PathBuf}, process::ExitCode, }; use keyfork_prompt::{DefaultTerminal, default_terminal}; use keyfork_shard::{Format, openpgp::OpenPGP}; type Result> = std::result::Result; fn validate( shard: impl AsRef, key_discovery: Option<&str>, ) -> Result<(File, Option)> { let key_discovery = key_discovery.map(PathBuf::from); key_discovery.as_ref().map(std::fs::metadata).transpose()?; Ok((File::open(shard)?, key_discovery)) } fn run() -> Result<()> { let mut args = env::args(); let program_name = args.next().expect("program name"); let args = args.collect::>(); let (messages_file, key_discovery) = match args.as_slice() { [shard, key_discovery] => validate(shard, Some(key_discovery))?, [shard] => validate(shard, None)?, _ => panic!("Usage: {program_name} [key_discovery]"), }; let openpgp = OpenPGP::::new(); let prompt_handler = default_terminal()?; openpgp.decrypt_one_shard_for_transport(key_discovery.as_deref(), messages_file, prompt_handler)?; Ok(()) } fn main() -> ExitCode { let result = run(); if let Err(e) = result { eprintln!("Error: {e}"); let mut source = e.source(); while let Some(new_error) = source.take() { eprintln!("Source: {new_error}"); source = new_error.source(); } return ExitCode::FAILURE; } ExitCode::SUCCESS }