cleanup use of keyfork-shard deprecated functions

This commit is contained in:
Ryan Heywood 2024-02-12 09:09:00 -05:00
parent 6093cf9be4
commit 3c1d8e9784
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 10 additions and 49 deletions

View File

@ -32,9 +32,7 @@ fn run() -> Result<()> {
}; };
let openpgp = OpenPGP; let openpgp = OpenPGP;
let bytes = openpgp.decrypt_all_shards_to_secret(key_discovery, messages_file)?; let bytes = openpgp.decrypt_all_shards_to_secret(key_discovery, messages_file)?;
print!("{}", smex::encode(&bytes)); print!("{}", smex::encode(&bytes));
Ok(()) Ok(())

View File

@ -3,10 +3,7 @@ use clap::{Parser, Subcommand};
use std::path::PathBuf; use std::path::PathBuf;
use keyfork_mnemonic_util::{English, Mnemonic}; use keyfork_mnemonic_util::{English, Mnemonic};
use keyfork_shard::{ use keyfork_shard::{remote_decrypt, Format};
openpgp::{combine, discover_certs, parse_messages},
remote_decrypt,
};
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
@ -37,15 +34,10 @@ impl RecoverSubcommands {
} => { } => {
let content = std::fs::read_to_string(shard_file)?; let content = std::fs::read_to_string(shard_file)?;
if content.contains("BEGIN PGP MESSAGE") { if content.contains("BEGIN PGP MESSAGE") {
let certs = key_discovery let openpgp = keyfork_shard::openpgp::OpenPGP;
.as_ref() // TODO: remove .clone() by making handle() consume self
.map(discover_certs) let seed = openpgp
.transpose()? .decrypt_all_shards_to_secret(key_discovery.clone(), content.as_bytes())?;
.unwrap_or(vec![]);
let mut messages = parse_messages(content.as_bytes())?;
let metadata = messages.pop_front().expect("any pgp encrypted message");
let mut seed = vec![];
combine(certs, &metadata, messages.into(), &mut seed)?;
Ok(seed) Ok(seed)
} else { } else {
panic!("unknown format of shard file"); panic!("unknown format of shard file");

View File

@ -1,5 +1,6 @@
use super::Keyfork; use super::Keyfork;
use clap::{builder::PossibleValue, Parser, Subcommand, ValueEnum}; use clap::{builder::PossibleValue, Parser, Subcommand, ValueEnum};
use keyfork_shard::Format as _;
use std::{ use std::{
io::{stdin, stdout, Read, Write}, io::{stdin, stdout, Read, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -86,25 +87,8 @@ impl ShardExec for OpenPGP {
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let certs = key_discovery let openpgp = keyfork_shard::openpgp::OpenPGP;
.map(|kd| keyfork_shard::openpgp::discover_certs(kd.as_ref())) let bytes = openpgp.decrypt_all_shards_to_secret(key_discovery, input)?;
.transpose()?
.unwrap_or(vec![]);
let mut encrypted_messages = keyfork_shard::openpgp::parse_messages(input)?;
let encrypted_metadata = encrypted_messages
.pop_front()
.expect("any pgp encrypted message");
let mut bytes = vec![];
keyfork_shard::openpgp::combine(
certs,
&encrypted_metadata,
encrypted_messages.into(),
&mut bytes,
)?;
write!(output, "{}", smex::encode(&bytes))?; write!(output, "{}", smex::encode(&bytes))?;
Ok(()) Ok(())
@ -118,21 +102,8 @@ impl ShardExec for OpenPGP {
where where
T: AsRef<Path>, T: AsRef<Path>,
{ {
let certs = key_discovery let openpgp = keyfork_shard::openpgp::OpenPGP;
.map(|kd| keyfork_shard::openpgp::discover_certs(kd.as_ref())) openpgp.decrypt_one_shard_for_transport(key_discovery, input)?;
.transpose()?
.unwrap_or(vec![]);
let mut encrypted_messages = keyfork_shard::openpgp::parse_messages(input)?;
let encrypted_metadata = encrypted_messages
.pop_front()
.expect("any pgp encrypted message");
keyfork_shard::openpgp::decrypt(
&certs,
&encrypted_metadata,
encrypted_messages.make_contiguous(),
)?;
Ok(()) Ok(())
} }
} }