diff --git a/keyfork-shard/src/bin/keyfork-shard-remote.rs b/keyfork-shard/src/bin/keyfork-shard-remote.rs index d03cf9d..437da9f 100644 --- a/keyfork-shard/src/bin/keyfork-shard-remote.rs +++ b/keyfork-shard/src/bin/keyfork-shard-remote.rs @@ -16,7 +16,9 @@ fn run() -> Result<()> { _ => panic!("Usage: {program_name}"), }; - remote_decrypt()?; + let mut bytes = vec![]; + remote_decrypt(&mut bytes)?; + print!("{}", smex::encode(&bytes)); Ok(()) } diff --git a/keyfork-shard/src/lib.rs b/keyfork-shard/src/lib.rs index ae4db50..416224c 100644 --- a/keyfork-shard/src/lib.rs +++ b/keyfork-shard/src/lib.rs @@ -1,5 +1,5 @@ use std::{ - io::{stdin, stdout}, + io::{stdin, stdout, Write}, str::FromStr, }; @@ -39,7 +39,7 @@ pub(crate) const HUNK_OFFSET: usize = 2; /// /// The function may panic if it is given payloads generated using a version of Keyfork that is /// incompatible with the currently running version. -pub fn remote_decrypt() -> Result<(), Box> { +pub fn remote_decrypt(w: &mut impl Write) -> Result<(), Box> { let mut pm = PromptManager::new(stdin(), stdout())?; let wordlist = Wordlist::default(); @@ -143,7 +143,7 @@ pub fn remote_decrypt() -> Result<(), Box> { } */ - print!("{}", smex::encode(&secret)); + w.write_all(&secret)?; Ok(()) } diff --git a/keyfork/src/cli/recover.rs b/keyfork/src/cli/recover.rs index 474faca..649c9a2 100644 --- a/keyfork/src/cli/recover.rs +++ b/keyfork/src/cli/recover.rs @@ -1,53 +1,12 @@ use super::Keyfork; -use clap::{builder::PossibleValue, Parser, Subcommand, ValueEnum}; +use clap::{Parser, Subcommand}; use std::path::PathBuf; use keyfork_mnemonic_util::Mnemonic; -use keyfork_shard::openpgp::{combine, discover_certs, parse_messages}; +use keyfork_shard::{remote_decrypt, openpgp::{combine, discover_certs, parse_messages}}; type Result> = std::result::Result; -trait IntoSeed { - fn retrieve_seed(&self) -> Result>; -} - -#[derive(Clone, Debug)] -pub struct Shard; - -impl IntoSeed for Shard { - fn retrieve_seed(&self) -> Result> { - todo!() - } -} - -#[derive(Clone, Debug)] -pub struct RemoteShard; - -impl IntoSeed for RemoteShard { - fn retrieve_seed(&self) -> Result> { - todo!() - } -} - -#[derive(Clone, Debug)] -pub enum SeedFormat { - Shard(Shard), - RemoteShard(RemoteShard), -} - -impl ValueEnum for SeedFormat { - fn value_variants<'a>() -> &'a [Self] { - &[Self::Shard(Shard), Self::RemoteShard(RemoteShard)] - } - - fn to_possible_value(&self) -> Option { - Some(match self { - SeedFormat::Shard(_) => PossibleValue::new("shard"), - SeedFormat::RemoteShard(_) => PossibleValue::new("remote-shard"), - }) - } -} - #[derive(Subcommand, Clone, Debug)] pub enum RecoverSubcommands { /// Decrypt a shard file using keys available on the local system. @@ -78,12 +37,17 @@ impl RecoverSubcommands { let metadata = messages.pop_front().expect("any pgp encrypted message"); let mut seed = vec![]; combine(certs, &metadata, messages.into(), &mut seed)?; - return Ok(seed); + Ok(seed) + } else { + panic!("unknown format of shard file"); } } - RecoverSubcommands::RemoteShard {} => todo!(), + RecoverSubcommands::RemoteShard {} => { + let mut seed = vec![]; + remote_decrypt(&mut seed)?; + Ok(seed) + }, } - todo!() } }