upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/key_handling
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-03-22 15:51:34 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-03-22 15:51:34 +0000
commit0d7a8383d7d54e64bb0e1d5f4e06110c1e6a818b (patch)
treef60b44afd7c3d4c6dea6332926aac7400996cf5b /src/key_handling
parentf7d520e9ccb6084144a3e963516e40a322add0c8 (diff)
rename from_sk_str -> from_str
to reflect new name in rust-nostr
Diffstat (limited to 'src/key_handling')
-rw-r--r--src/key_handling/encryption.rs12
-rw-r--r--src/key_handling/users.rs6
2 files changed, 11 insertions, 7 deletions
diff --git a/src/key_handling/encryption.rs b/src/key_handling/encryption.rs
index 0ef7f69..54002fa 100644
--- a/src/key_handling/encryption.rs
+++ b/src/key_handling/encryption.rs
@@ -1,3 +1,5 @@
1use std::str::FromStr;
2
1use anyhow::{anyhow, bail, ensure, Context, Result}; 3use anyhow::{anyhow, bail, ensure, Context, Result};
2use chacha20poly1305::{ 4use chacha20poly1305::{
3 aead::{rand_core::RngCore, Aead, AeadCore, KeyInit, OsRng, Payload}, 5 aead::{rand_core::RngCore, Aead, AeadCore, KeyInit, OsRng, Payload},
@@ -6,6 +8,7 @@ use chacha20poly1305::{
6#[cfg(test)] 8#[cfg(test)]
7use mockall::*; 9use mockall::*;
8use nostr::{prelude::*, Keys}; 10use nostr::{prelude::*, Keys};
11use nostr_sdk::bech32::{self, FromBase32, ToBase32};
9use rand::{distributions::Alphanumeric, thread_rng, Rng}; 12use rand::{distributions::Alphanumeric, thread_rng, Rng};
10use zeroize::Zeroize; 13use zeroize::Zeroize;
11 14
@@ -120,10 +123,11 @@ impl EncryptDecrypt for Encryptor {
120 bail!("invalid encrypted key"); 123 bail!("invalid encrypted key");
121 } 124 }
122 125
123 let key = Keys::from_sk_str( 126 let key =
124 std::str::from_utf8(&inner_secret).context("inner secret is not [u8]")?, 127 Keys::from_str(std::str::from_utf8(&inner_secret).context("inner secret is not [u8]")?)
125 ) 128 .context(
126 .context("incorrect password. Key decrypted with password did not produce a valid nsec.")?; 129 "incorrect password. Key decrypted with password did not produce a valid nsec.",
130 )?;
127 131
128 inner_secret.zeroize(); 132 inner_secret.zeroize();
129 133
diff --git a/src/key_handling/users.rs b/src/key_handling/users.rs
index 2e88fba..c061cd3 100644
--- a/src/key_handling/users.rs
+++ b/src/key_handling/users.rs
@@ -1,4 +1,4 @@
1use std::time::SystemTime; 1use std::{str::FromStr, time::SystemTime};
2 2
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use async_trait::async_trait; 4use async_trait::async_trait;
@@ -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 }
@@ -471,7 +471,7 @@ mod tests {
471 .expect_encrypt_key() 471 .expect_encrypt_key()
472 .once() 472 .once()
473 .withf(|k, p| { 473 .withf(|k, p| {
474 k.eq(&Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD) 474 k.eq(&Keys::from_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD)
475 }) 475 })
476 .returning(|_, _| Ok(TEST_KEY_1_ENCRYPTED.into())); 476 .returning(|_, _| Ok(TEST_KEY_1_ENCRYPTED.into()));
477 477