diff options
Diffstat (limited to 'src/key_handling/users.rs')
| -rw-r--r-- | src/key_handling/users.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/key_handling/users.rs b/src/key_handling/users.rs index 2e88fba..1dd75a8 100644 --- a/src/key_handling/users.rs +++ b/src/key_handling/users.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use std::time::SystemTime; | 1 | use std::{str::FromStr, time::SystemTime}; |
| 2 | 2 | ||
| 3 | use anyhow::{Context, Result}; | 3 | use anyhow::{Context, Result}; |
| 4 | use async_trait::async_trait; | 4 | use async_trait::async_trait; |
| @@ -32,13 +32,13 @@ pub trait UserManagement { | |||
| 32 | &self, | 32 | &self, |
| 33 | #[cfg(test)] client: &MockConnect, | 33 | #[cfg(test)] client: &MockConnect, |
| 34 | #[cfg(not(test))] client: &Client, | 34 | #[cfg(not(test))] client: &Client, |
| 35 | public_key: &XOnlyPublicKey, | 35 | public_key: &PublicKey, |
| 36 | after: u64, | 36 | after: u64, |
| 37 | ) -> Result<UserRef>; | 37 | ) -> Result<UserRef>; |
| 38 | fn get_user_from_cache(&self, public_key: &XOnlyPublicKey) -> Result<UserRef>; | 38 | fn get_user_from_cache(&self, public_key: &PublicKey) -> Result<UserRef>; |
| 39 | fn add_user_to_config( | 39 | fn add_user_to_config( |
| 40 | &self, | 40 | &self, |
| 41 | public_key: XOnlyPublicKey, | 41 | public_key: PublicKey, |
| 42 | encrypted_secret_key: Option<String>, | 42 | encrypted_secret_key: Option<String>, |
| 43 | overwrite: bool, | 43 | overwrite: bool, |
| 44 | ) -> Result<()>; | 44 | ) -> Result<()>; |
| @@ -59,7 +59,7 @@ impl UserManagement for UserManager { | |||
| 59 | .input(PromptInputParms::default().with_prompt(prompt)) | 59 | .input(PromptInputParms::default().with_prompt(prompt)) |
| 60 | .context("failed to get nsec input from interactor")?, | 60 | .context("failed to get nsec input from interactor")?, |
| 61 | }; | 61 | }; |
| 62 | match Keys::from_sk_str(&pk) { | 62 | match Keys::from_str(&pk) { |
| 63 | Ok(key) => { | 63 | Ok(key) => { |
| 64 | break key; | 64 | break key; |
| 65 | } | 65 | } |
| @@ -99,7 +99,7 @@ impl UserManagement for UserManager { | |||
| 99 | 99 | ||
| 100 | fn add_user_to_config( | 100 | fn add_user_to_config( |
| 101 | &self, | 101 | &self, |
| 102 | public_key: XOnlyPublicKey, | 102 | public_key: PublicKey, |
| 103 | encrypted_secret_key: Option<String>, | 103 | encrypted_secret_key: Option<String>, |
| 104 | overwrite: bool, | 104 | overwrite: bool, |
| 105 | ) -> Result<()> { | 105 | ) -> Result<()> { |
| @@ -129,7 +129,7 @@ impl UserManagement for UserManager { | |||
| 129 | .context("failed to save application configuration with new user details in") | 129 | .context("failed to save application configuration with new user details in") |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | fn get_user_from_cache(&self, public_key: &XOnlyPublicKey) -> Result<UserRef> { | 132 | fn get_user_from_cache(&self, public_key: &PublicKey) -> Result<UserRef> { |
| 133 | let cfg = self | 133 | let cfg = self |
| 134 | .config_manager | 134 | .config_manager |
| 135 | .load() | 135 | .load() |
| @@ -148,7 +148,7 @@ impl UserManagement for UserManager { | |||
| 148 | &self, | 148 | &self, |
| 149 | #[cfg(test)] client: &MockConnect, | 149 | #[cfg(test)] client: &MockConnect, |
| 150 | #[cfg(not(test))] client: &Client, | 150 | #[cfg(not(test))] client: &Client, |
| 151 | public_key: &XOnlyPublicKey, | 151 | public_key: &PublicKey, |
| 152 | use_cache_unless_checked_more_than_x_secs_ago: u64, | 152 | use_cache_unless_checked_more_than_x_secs_ago: u64, |
| 153 | ) -> Result<UserRef> { | 153 | ) -> Result<UserRef> { |
| 154 | let cfg = self | 154 | let cfg = self |
| @@ -249,7 +249,11 @@ impl UserManagement for UserManager { | |||
| 249 | relays: new_relays_event | 249 | relays: new_relays_event |
| 250 | .tags | 250 | .tags |
| 251 | .iter() | 251 | .iter() |
| 252 | .filter(|t| t.kind().eq(&nostr::TagKind::R)) | 252 | .filter(|t| { |
| 253 | t.kind().eq(&nostr::TagKind::SingleLetter( | ||
| 254 | SingleLetterTag::lowercase(Alphabet::R), | ||
| 255 | )) | ||
| 256 | }) | ||
| 253 | .map(|t| UserRelayRef { | 257 | .map(|t| UserRelayRef { |
| 254 | url: t.as_vec()[1].clone(), | 258 | url: t.as_vec()[1].clone(), |
| 255 | read: t.as_vec().len() == 2 || t.as_vec()[2].eq("read"), | 259 | read: t.as_vec().len() == 2 || t.as_vec()[2].eq("read"), |
| @@ -471,7 +475,7 @@ mod tests { | |||
| 471 | .expect_encrypt_key() | 475 | .expect_encrypt_key() |
| 472 | .once() | 476 | .once() |
| 473 | .withf(|k, p| { | 477 | .withf(|k, p| { |
| 474 | k.eq(&Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD) | 478 | k.eq(&Keys::from_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD) |
| 475 | }) | 479 | }) |
| 476 | .returning(|_, _| Ok(TEST_KEY_1_ENCRYPTED.into())); | 480 | .returning(|_, _| Ok(TEST_KEY_1_ENCRYPTED.into())); |
| 477 | 481 | ||