From f18e773332d19382423b0e79bb2051975c29118d Mon Sep 17 00:00:00 2001 From: Gabriela Moldovan Date: Tue, 18 Jul 2023 14:06:58 +0100 Subject: [PATCH] arti-client: Use a default keystore config if `experimental-api` is disabled. The `experimental-api` was only meant to apply to the use of the unstable `ArtiNativeKeystoreConfig` in the Arti config. `experimental-api` was _not_ supposed to be used for enabling/disabling the keystore (that's what the `enabled` flag is for). --- crates/arti-client/src/client.rs | 31 ++++++++++++++----------------- crates/arti-client/src/config.rs | 6 +++--- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/crates/arti-client/src/client.rs b/crates/arti-client/src/client.rs index e7d0a497a..bdd6b102d 100644 --- a/crates/arti-client/src/client.rs +++ b/crates/arti-client/src/client.rs @@ -600,30 +600,27 @@ impl TorClient { HsClientConnector::new(runtime.clone(), circpool, config, housekeeping)? }; - let keymgr = if let Some(keystore) = config.storage.keystore() { + let keystore = config.storage.keystore(); + // If enabled is true or set to "auto", initialize the keystore + // + // In this case "auto" means true, because experimental-api is enabled + // (otherwise, config.storage.keystore() would've returned None). + let keymgr = if keystore.enabled.as_bool().unwrap_or(true) { + let mut stores: Vec> = vec![]; // TODO HSS: `expand_keystore_dir` shouldn't be escaping into a crate API boundary. // The keystore_dir should probably be expanded at `build()` time. let key_store_dir = keystore.expand_keystore_dir()?; let permissions = config.storage.permissions(); - // If enabled is true or set to "auto", initialize the keystore - // - // In this case "auto" means true, because experimental-api is enabled - // (otherwise, config.storage.keystore() would've returned None). - if keystore.enabled.as_bool().unwrap_or(true) { - let mut stores: Vec> = vec![]; - let arti_store = - ArtiNativeKeystore::from_path_and_mistrust(&key_store_dir, permissions)?; - info!("Using keystore from {key_store_dir:?}"); - stores.push(Box::new(arti_store)); + let arti_store = + ArtiNativeKeystore::from_path_and_mistrust(&key_store_dir, permissions)?; + info!("Using keystore from {key_store_dir:?}"); + stores.push(Box::new(arti_store)); - // TODO hs: add support for the C Tor key store - Some(Arc::new(KeyMgr::new(stores))) - } else { - info!("Running without a keystore"); - None - } + // TODO hs: add support for the C Tor key store + Some(Arc::new(KeyMgr::new(stores))) } else { + info!("Running without a keystore"); None }; diff --git a/crates/arti-client/src/config.rs b/crates/arti-client/src/config.rs index a0dc9cd58..33ce82152 100644 --- a/crates/arti-client/src/config.rs +++ b/crates/arti-client/src/config.rs @@ -222,15 +222,15 @@ impl StorageConfig { } /// Return the keystore config #[allow(clippy::unnecessary_wraps)] - pub(crate) fn keystore(&self) -> Option<&ArtiNativeKeystoreConfig> { + pub(crate) fn keystore(&self) -> ArtiNativeKeystoreConfig { #[cfg(feature = "experimental-api")] { - Some(&self.keystore) + self.keystore.clone() } #[cfg(not(feature = "experimental-api"))] { - None + Default::default() } } /// Return the FS permissions to use for state and cache directories.