diff --git a/src/config.rs b/src/config.rs index 64a223e7..004bf33d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ use std::{ collections::{BTreeSet, HashSet}, fs, io, - path::PathBuf, + path::{Path, PathBuf}, time::SystemTime, }; @@ -53,6 +53,9 @@ pub struct Config { policy_inline: Option>, cipher_suite: Option, key_servers: Option>, + + /// The location of the backend server executables. + servers_path: Option, } impl Default for Config { @@ -66,6 +69,7 @@ impl Default for Config { policy_inline: None, cipher_suite: None, key_servers: None, + servers_path: None, } } } @@ -206,6 +210,11 @@ impl Config { as Box>, } } + + /// Returns the path to the backend servers. + pub fn servers_path(&self) -> Option<&Path> { + self.servers_path.as_ref().map(|p| p.as_path()) + } } /// Holds the document tree of the configuration file. @@ -234,6 +243,9 @@ impl ConfigFile { [network] #keyservers = +[servers] +#path = + [policy] #path = @@ -250,6 +262,7 @@ impl ConfigFile { "", "", "", + "", "", "", ]; @@ -282,6 +295,11 @@ impl ConfigFile { &format!("{:?}", cli::key::CipherSuite::default(). to_possible_value().unwrap().get_name()), &format!("{:?}", cli::network::keyserver::DEFAULT_KEYSERVERS), + &format!("{:?}", { + sequoia_keystore::sequoia_ipc::Context::configure().build() + .map(|c| c.lib().display().to_string()) + .unwrap_or_else(|_| "".into()) + }), &format!("{:?}", std::env::var(ConfiguredStandardPolicy::ENV_VAR) .unwrap_or_else( @@ -625,6 +643,7 @@ const TOP_LEVEL_SCHEMA: Schema = &[ ("key", apply_key), ("network", apply_network), ("policy", apply_policy), + ("servers", apply_servers), ("ui", apply_ui), ]; @@ -915,3 +934,35 @@ fn apply_policy_path(config: &mut Option<&mut Config>, Ok(()) } + +/// Schema for the `servers` section. +const SERVERS_SCHEMA: Schema = &[ + ("path", apply_servers_path), +]; + +/// Validates the `servers` section. +fn apply_servers(config: &mut Option<&mut Config>, cli: &mut Option<&mut Augmentations>, + path: &str, item: &Item) + -> Result<()> +{ + let section = item.as_table_like() + .ok_or_else(|| Error::bad_item_type(path, item, "table"))?; + apply_schema(config, cli, Some(path), section.iter(), SERVERS_SCHEMA)?; + Ok(()) +} + +/// Validates the `servers.path` value. +fn apply_servers_path(config: &mut Option<&mut Config>, + _: &mut Option<&mut Augmentations>, + path: &str, item: &Item) + -> Result<()> +{ + let path = item.as_str() + .ok_or_else(|| Error::bad_item_type(path, item, "string"))?; + + if let Some(config) = config { + config.servers_path = Some(path.into()); + } + + Ok(()) +} diff --git a/src/sq.rs b/src/sq.rs index 03cd05ab..983aa44e 100644 --- a/src/sq.rs +++ b/src/sq.rs @@ -429,9 +429,14 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> { self.key_store .get_or_try_init(|| { - let c = keystore::Context::configure() - .home(self.key_store_path_or_else()?) - .build()?; + let mut c = keystore::Context::configure() + .home(self.key_store_path_or_else()?); + + if let Some(p) = self.config.servers_path() { + c = c.lib(p); + } + + let c = c.build()?; let ks = keystore::Keystore::connect(&c) .context("Connecting to key store")?;