Refactor HuskContext
- Provide a way to initialize a `HuskContext` without determine the signing key. This saves startup time for commands which do not need the signing key.
This commit is contained in:
+23
-10
@@ -36,8 +36,17 @@ pub struct HuskContext<'hc> {
|
||||
|
||||
impl<'hc> HuskContext<'hc> {
|
||||
|
||||
/// Create a new HuskContext instance.
|
||||
pub fn new(config: &HuskConfig) -> anyhow::Result<HuskContext<'hc>> {
|
||||
Self::create(config, true)
|
||||
}
|
||||
|
||||
/// Create a new HuskContext without determine the signing key
|
||||
pub fn without_signkey(config: &HuskConfig) -> anyhow::Result<HuskContext<'hc>> {
|
||||
Self::create(config, false)
|
||||
}
|
||||
|
||||
/// Create a new HuskContext instance.
|
||||
pub fn create(config: &HuskConfig, with_signkey: bool) -> anyhow::Result<HuskContext<'hc>> {
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user