use std::{ env, io::{stdin, stdout}, path::PathBuf, process::ExitCode, str::FromStr, }; use keyfork_shard::{combine, discover_certs, parse_messages, openpgp::Cert}; type Result> = std::result::Result; fn validate(threshold: &str, key_discovery: &str) -> Result<(u8, Vec)> { let threshold = u8::from_str(threshold)?; let key_discovery = PathBuf::from(key_discovery); // Verify path exists std::fs::metadata(&key_discovery)?; // Load certs from path let certs = discover_certs(key_discovery)?; Ok((threshold, certs)) } fn run() -> Result<()> { let mut args = env::args(); let program_name = args.next().expect("program name"); let args = args.collect::>(); let (threshold, cert_list) = match args.as_slice() { [threshold, key_discovery] => validate(threshold, key_discovery)?, _ => panic!("Usage: {program_name} threshold key_discovery"), }; let mut encrypted_messages = parse_messages(stdin())?; let encrypted_metadata = encrypted_messages .pop_front() .expect("any pgp encrypted message"); combine( threshold, cert_list, encrypted_metadata, encrypted_messages.into(), stdout(), )?; Ok(()) } fn main() -> ExitCode { let result = run(); if let Err(e) = result { eprintln!("Error: {e}"); return ExitCode::FAILURE; } ExitCode::SUCCESS }