diff options
Diffstat (limited to 'src/key_handling/encryption.rs')
| -rw-r--r-- | src/key_handling/encryption.rs | 12 |
1 files changed, 8 insertions, 4 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 @@ | |||
| 1 | use std::str::FromStr; | ||
| 2 | |||
| 1 | use anyhow::{anyhow, bail, ensure, Context, Result}; | 3 | use anyhow::{anyhow, bail, ensure, Context, Result}; |
| 2 | use chacha20poly1305::{ | 4 | use 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)] |
| 7 | use mockall::*; | 9 | use mockall::*; |
| 8 | use nostr::{prelude::*, Keys}; | 10 | use nostr::{prelude::*, Keys}; |
| 11 | use nostr_sdk::bech32::{self, FromBase32, ToBase32}; | ||
| 9 | use rand::{distributions::Alphanumeric, thread_rng, Rng}; | 12 | use rand::{distributions::Alphanumeric, thread_rng, Rng}; |
| 10 | use zeroize::Zeroize; | 13 | use 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 | ||