diff --git a/src/cmd/renc.rs b/src/cmd/renc.rs index c88fadb..9d36ef5 100644 --- a/src/cmd/renc.rs +++ b/src/cmd/renc.rs @@ -11,7 +11,7 @@ use std::{ }; use crate::{ - cmd::stored_sec_path::{HashWithCtx, InCfg, InStore, SecMap, SecPath}, + cmd::stored_sec_path::{InCfg, InStore, SecMap, SecPath}, profile::{MasterIdentity, Profile}, }; use crate::{interop::add_to_store, profile}; @@ -97,11 +97,11 @@ impl Profile { .into_iter() .filter(|(k, v)| { // TODO: extraReceip - let hash = v.get_hash(); + let hash = v; let renc_path = { let mut path = renc_path.clone(); path.push(hash.to_string()); - info!("check {}", path.display()); + trace!("checking {}", path.display()); path }; @@ -115,25 +115,25 @@ impl Profile { !exs }) - .collect::>() + .collect::>() .into_keys() .collect::>(); - // info!("{:?}", sec_need_renc); // TODO: host pub key type safe - data.makeup( + if let Ok(_) = data.makeup( instore_map, sec_need_renc, self.settings.host_pubkey.clone(), decrypt, - ) - - // let o = add_to_store(renc_path)?; - // if !o.status.success() { - // error!("Command executed with failing error code"); - // } - // // Another side, calculate with nix `builtins.path` and pass to when deploy as `storage` - // info!("path added to store: {}", String::from_utf8(o.stdout)?); - // Ok(()) + ) { + let o = add_to_store(renc_path)?; + if !o.status.success() { + error!("Command executed with failing error code"); + } + // Another side, calculate with nix `builtins.path` and pass to when deploy as `storage` + info!("path added to store: {}", String::from_utf8(o.stdout)?); + } + + Ok(()) } } diff --git a/src/cmd/stored_sec_path.rs b/src/cmd/stored_sec_path.rs index ea8caaa..f891d69 100644 --- a/src/cmd/stored_sec_path.rs +++ b/src/cmd/stored_sec_path.rs @@ -7,9 +7,7 @@ use std::{ path::{Path, PathBuf}, }; -use age::Identity; use eyre::{Context, ContextCompat}; -use nom::Err; use spdlog::info; use crate::profile::{self, Profile, SecretSet, Settings}; @@ -81,21 +79,7 @@ macro_rules! impl_from_iterator_for_secmap { }; } -impl_from_iterator_for_secmap!(Vec, HashWithCtx, PathWithCtx); - -pub struct HashWithCtx(blake3::Hash, Vec); - -impl HashWithCtx { - pub fn new(b: blake3::Hash, v: Vec) -> Self { - HashWithCtx(b, v) - } - pub fn get_hash(&self) -> &blake3::Hash { - &self.0 - } - pub fn get_ctx(&self) -> &Vec { - &self.1 - } -} +impl_from_iterator_for_secmap!(Vec, PathWithCtx, blake3::Hash); #[derive(Debug, Clone)] pub struct SecMap

(HashMap); @@ -119,7 +103,7 @@ impl SecMap> { /// hash of encrypted file content /// used in: renc, calc and compare /// deploy, calc and find in store - pub fn calc_renc(self, _host_pubkey: String) -> Result> { + pub fn calc_renc(self, _host_pubkey: String) -> Result> { self.bake_ctx().and_then(|h| { h.inner() .into_iter() @@ -128,9 +112,9 @@ impl SecMap> { hasher.update(v.as_slice()); // hasher.update(host_pubkey.as_bytes()); let hash = hasher.finalize(); - Ok((k, HashWithCtx::new(hash, v))) + Ok((k, hash)) }) - .try_collect::>() + .try_collect::>() }) } } @@ -187,8 +171,6 @@ impl SecMap> { .filter(|(s, _)| target.contains(s)) .collect(); - // let map_path_with_ctx: SecMap = SecMap::>(spm).into(); - // info!("{:?}", map_path_with_ctx); in_store_data.inner().into_iter().try_for_each(|(s, v)| { let enc_ctx = v.read_buffer()?; let target_path = spm @@ -238,20 +220,20 @@ impl PathWithCtx { } } -impl From>> for SecMap { - fn from(value: SecMap>) -> Self { - value - .inner() - .into_iter() - .filter_map(|(s, p)| { - let mut f = p.open_file().ok()?; - let mut buffer = Vec::new(); - f.read_to_end(&mut buffer) - .wrap_err_with(|| eyre!("read secret file error")) - .ok()?; - Some((s, PathWithCtx(p, buffer))) - }) - .collect() - } -} +// impl From>> for SecMap { +// fn from(value: SecMap>) -> Self { +// value +// .inner() +// .into_iter() +// .filter_map(|(s, p)| { +// let mut f = p.open_file().ok()?; +// let mut buffer = Vec::new(); +// f.read_to_end(&mut buffer) +// .wrap_err_with(|| eyre!("read secret file error")) +// .ok()?; +// Some((s, PathWithCtx(p, buffer))) +// }) +// .collect() +// } +// } // impl From> for