From 0d7a8383d7d54e64bb0e1d5f4e06110c1e6a818b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 22 Mar 2024 15:51:34 +0000 Subject: rename from_sk_str -> from_str to reflect new name in rust-nostr --- src/key_handling/encryption.rs | 12 ++++++++---- src/key_handling/users.rs | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/key_handling') 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 @@ +use std::str::FromStr; + use anyhow::{anyhow, bail, ensure, Context, Result}; use chacha20poly1305::{ aead::{rand_core::RngCore, Aead, AeadCore, KeyInit, OsRng, Payload}, @@ -6,6 +8,7 @@ use chacha20poly1305::{ #[cfg(test)] use mockall::*; use nostr::{prelude::*, Keys}; +use nostr_sdk::bech32::{self, FromBase32, ToBase32}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use zeroize::Zeroize; @@ -120,10 +123,11 @@ impl EncryptDecrypt for Encryptor { bail!("invalid encrypted key"); } - let key = Keys::from_sk_str( - std::str::from_utf8(&inner_secret).context("inner secret is not [u8]")?, - ) - .context("incorrect password. Key decrypted with password did not produce a valid nsec.")?; + let key = + Keys::from_str(std::str::from_utf8(&inner_secret).context("inner secret is not [u8]")?) + .context( + "incorrect password. Key decrypted with password did not produce a valid nsec.", + )?; inner_secret.zeroize(); 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 @@ -use std::time::SystemTime; +use std::{str::FromStr, time::SystemTime}; use anyhow::{Context, Result}; use async_trait::async_trait; @@ -59,7 +59,7 @@ impl UserManagement for UserManager { .input(PromptInputParms::default().with_prompt(prompt)) .context("failed to get nsec input from interactor")?, }; - match Keys::from_sk_str(&pk) { + match Keys::from_str(&pk) { Ok(key) => { break key; } @@ -471,7 +471,7 @@ mod tests { .expect_encrypt_key() .once() .withf(|k, p| { - k.eq(&Keys::from_sk_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD) + k.eq(&Keys::from_str(TEST_KEY_1_NSEC).unwrap()) && p.eq(TEST_PASSWORD) }) .returning(|_, _| Ok(TEST_KEY_1_ENCRYPTED.into())); -- cgit v1.2.3