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.
This commit is contained in:
Ellie Huxtable 2024-01-30 14:01:20 +00:00 committed by GitHub
parent 9597080825
commit 335f2220c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,6 +32,11 @@ pub struct EncryptedHistory {
pub fn new_key(settings: &Settings) -> Result<Key> { pub fn new_key(settings: &Settings) -> Result<Key> {
let path = settings.key_path.as_str(); 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 key = XSalsa20Poly1305::generate_key(&mut OsRng);
let encoded = encode_key(&key)?; let encoded = encode_key(&key)?;