From d6546733aabd7c681ea7050cadc8ec4f32ec1b9f Mon Sep 17 00:00:00 2001 From: glyph Date: Wed, 11 May 2022 14:14:03 +0200 Subject: [PATCH] add keystore selector for initialising sbot --- src/sbot.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/sbot.rs b/src/sbot.rs index 40b958d..fdf1771 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -12,6 +12,16 @@ use kuska_ssb::{ use crate::error::GolgiError; +/// Keystore selector to specify the location of the secret file. +/// +/// This enum is used when initiating a connection with an sbot instance. +pub enum Keystore { + /// Patchwork default keystore path: `.ssb/secret` in the user's home directory. + Patchwork, + /// GoSbot default keystore path: `.ssb-go/secret` in the user's home directory. + GoSbot, +} + /// A struct representing a connection with a running sbot. /// A client and an rpc_reader can together be used to make requests to the sbot /// and read the responses. @@ -39,7 +49,11 @@ impl Sbot { /// Initiate a connection with an sbot instance. Define the IP address, /// port and network key for the sbot, then retrieve the public key, /// private key (secret) and identity from the `.ssb-go/secret` file. - pub async fn init(ip_port: Option, net_id: Option) -> Result { + pub async fn init( + keystore: Keystore, + ip_port: Option, + net_id: Option, + ) -> Result { let address = if ip_port.is_none() { "127.0.0.1:8008".to_string() } else { @@ -52,9 +66,14 @@ impl Sbot { auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap() }; - let OwnedIdentity { pk, sk, id } = keystore::from_gosbot_local() - .await - .expect("couldn't read local secret"); + let OwnedIdentity { pk, sk, id } = match keystore { + Keystore::Patchwork => keystore::from_patchwork_local() + .await + .expect("couldn't read local secret"), + Keystore::GoSbot => keystore::from_gosbot_local() + .await + .expect("couldn't read local secret"), + }; Ok(Self { id,