diff --git a/src/types/husk_context.rs b/src/types/husk_context.rs index 9efac1d..8e13464 100644 --- a/src/types/husk_context.rs +++ b/src/types/husk_context.rs @@ -36,8 +36,17 @@ pub struct HuskContext<'hc> { impl<'hc> HuskContext<'hc> { - /// Create a new HuskContext instance. pub fn new(config: &HuskConfig) -> anyhow::Result> { + Self::create(config, true) + } + + /// Create a new HuskContext without determine the signing key + pub fn without_signkey(config: &HuskConfig) -> anyhow::Result> { + Self::create(config, false) + } + + /// Create a new HuskContext instance. + pub fn create(config: &HuskConfig, with_signkey: bool) -> anyhow::Result> { let sequoia_home = Home::new(PathBuf::from(&config.sequoia_home))?; let cert_store_base = sequoia_home.data_dir(sequoia_directories::Component::CertD); @@ -48,16 +57,20 @@ impl<'hc> HuskContext<'hc> { let local_trust_root = crypto::get_local_trust_root(&cert_store)?; let introducers = crypto::get_introducers(&cert_store, &policy, local_trust_root.fingerprint()); - let signing_key = match crypto::get_signing_key(sequoia_home, &cert_store, &policy, &local_trust_root) { - Ok(Some(cert)) => Some(cert), - Ok(None) => { - log::warn!("No signing key found"); - None - }, - Err(e) => { - log::error!("Error while fetching signing key: {}", e); - None + let signing_key = if with_signkey { + match crypto::get_signing_key(sequoia_home, &cert_store, &policy, &local_trust_root) { + Ok(Some(cert)) => Some(cert), + Ok(None) => { + log::warn!("No signing key found"); + None + }, + Err(e) => { + log::error!("Error while fetching signing key: {}", e); + None + } } + } else { + None }; Ok(HuskContext {