From 335f2220c3199055c68a444a84e452d95824e764 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 30 Jan 2024 14:01:20 +0000 Subject: fix: never overwrite the key (#1657) Now that local history is stored encrypted, new_key should not overwrite an existing one. This may be frustrating, but will remove the risk of Atuin generating a new key and the user losing their old one. --- atuin-client/src/encryption.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/atuin-client/src/encryption.rs b/atuin-client/src/encryption.rs index 3c9f3d06..f4031059 100644 --- a/atuin-client/src/encryption.rs +++ b/atuin-client/src/encryption.rs @@ -32,6 +32,11 @@ pub struct EncryptedHistory { pub fn new_key(settings: &Settings) -> Result { let path = settings.key_path.as_str(); + let path = PathBuf::from(path); + + if path.exists() { + bail!("key already exists! cannot overwrite"); + } let key = XSalsa20Poly1305::generate_key(&mut OsRng); let encoded = encode_key(&key)?; -- cgit v1.3.1