diff --git a/Cargo.lock b/Cargo.lock index d7adaff1b77..f96bd6d8f05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2926,11 +2926,12 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "pbkdf2" -version = "0.11.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest", + "hmac", ] [[package]] @@ -4663,12 +4664,10 @@ dependencies = [ [[package]] name = "tiny-bip39" -version = "1.0.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62cc94d358b5a1e84a5cb9109f559aa3c4d634d2b1b4de3d0fa4adc7c78e2861" +checksum = "a30fd743a02bf35236f6faf99adb03089bb77e91c998dac2c2ad76bb424f668c" dependencies = [ - "anyhow", - "hmac", "once_cell", "pbkdf2", "rand 0.8.5", diff --git a/crates/atuin-client/Cargo.toml b/crates/atuin-client/Cargo.toml index 568de4e0839..9cafa73aa29 100644 --- a/crates/atuin-client/Cargo.toml +++ b/crates/atuin-client/Cargo.toml @@ -65,7 +65,7 @@ reqwest = { workspace = true, optional = true } hex = { version = "0.4", optional = true } sha2 = { version = "0.10", optional = true } indicatif = "0.17.7" -tiny-bip39 = "=1.0.0" +tiny-bip39 = "2.0.0" # theme crossterm = { version = "0.28.1", features = ["serde"] } diff --git a/crates/atuin-client/src/login.rs b/crates/atuin-client/src/login.rs index 78168c7e754..ff994c1c373 100644 --- a/crates/atuin-client/src/login.rs +++ b/crates/atuin-client/src/login.rs @@ -23,24 +23,16 @@ pub async fn login( let key = match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) { Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?, Err(err) => { - match err.downcast_ref::() { - Some(err) => { - match err { - // assume they copied in the base64 key - bip39::ErrorKind::InvalidWord => key, - bip39::ErrorKind::InvalidChecksum => { - bail!("key mnemonic was not valid") - } - bip39::ErrorKind::InvalidKeysize(_) - | bip39::ErrorKind::InvalidWordLength(_) - | bip39::ErrorKind::InvalidEntropyLength(_, _) => { - bail!("key was not the correct length") - } - } + match err { + // assume they copied in the base64 key + bip39::ErrorKind::InvalidWord(_) => key, + bip39::ErrorKind::InvalidChecksum => { + bail!("key mnemonic was not valid") } - _ => { - // unknown error. assume they copied the base64 key - key + bip39::ErrorKind::InvalidKeysize(_) + | bip39::ErrorKind::InvalidWordLength(_) + | bip39::ErrorKind::InvalidEntropyLength(_, _) => { + bail!("key was not the correct length") } } } diff --git a/crates/atuin/Cargo.toml b/crates/atuin/Cargo.toml index 5288c10e683..26cd051a6fa 100644 --- a/crates/atuin/Cargo.toml +++ b/crates/atuin/Cargo.toml @@ -70,7 +70,7 @@ rpassword = "7.0" semver = { workspace = true } rustix = { workspace = true } runtime-format = "0.1.3" -tiny-bip39 = "1" +tiny-bip39 = "2" futures-util = "0.3" fuzzy-matcher = "0.3.7" colored = "2.0.4" diff --git a/crates/atuin/src/command/client/account/login.rs b/crates/atuin/src/command/client/account/login.rs index f569fe25e92..4514796ba51 100644 --- a/crates/atuin/src/command/client/account/login.rs +++ b/crates/atuin/src/command/client/account/login.rs @@ -77,24 +77,16 @@ impl Cmd { match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) { Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?, Err(err) => { - match err.downcast_ref::() { - Some(err) => { - match err { - // assume they copied in the base64 key - bip39::ErrorKind::InvalidWord => key, - bip39::ErrorKind::InvalidChecksum => { - bail!("key mnemonic was not valid") - } - bip39::ErrorKind::InvalidKeysize(_) - | bip39::ErrorKind::InvalidWordLength(_) - | bip39::ErrorKind::InvalidEntropyLength(_, _) => { - bail!("key was not the correct length") - } - } + match err { + // assume they copied in the base64 key + bip39::ErrorKind::InvalidWord(_) => key, + bip39::ErrorKind::InvalidChecksum => { + bail!("key mnemonic was not valid") } - _ => { - // unknown error. assume they copied the base64 key - key + bip39::ErrorKind::InvalidKeysize(_) + | bip39::ErrorKind::InvalidWordLength(_) + | bip39::ErrorKind::InvalidEntropyLength(_, _) => { + bail!("key was not the correct length") } } } diff --git a/crates/atuin/src/command/client/store/rekey.rs b/crates/atuin/src/command/client/store/rekey.rs index ec41cc2b861..4c537a48652 100644 --- a/crates/atuin/src/command/client/store/rekey.rs +++ b/crates/atuin/src/command/client/store/rekey.rs @@ -20,33 +20,23 @@ impl Rekey { let key = if let Some(key) = self.key.clone() { println!("Re-encrypting store with specified key"); - let key = match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) { + match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) { Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?, Err(err) => { - match err.downcast_ref::() { - Some(err) => { - match err { - // assume they copied in the base64 key - bip39::ErrorKind::InvalidWord => key, - bip39::ErrorKind::InvalidChecksum => { - bail!("key mnemonic was not valid") - } - bip39::ErrorKind::InvalidKeysize(_) - | bip39::ErrorKind::InvalidWordLength(_) - | bip39::ErrorKind::InvalidEntropyLength(_, _) => { - bail!("key was not the correct length") - } - } + match err { + // assume they copied in the base64 key + bip39::ErrorKind::InvalidWord(_) => key, + bip39::ErrorKind::InvalidChecksum => { + bail!("key mnemonic was not valid") } - _ => { - // unknown error. assume they copied the base64 key - key + bip39::ErrorKind::InvalidKeysize(_) + | bip39::ErrorKind::InvalidWordLength(_) + | bip39::ErrorKind::InvalidEntropyLength(_, _) => { + bail!("key was not the correct length") } } } - }; - - key + } } else { println!("Re-encrypting store with freshly-generated key"); let (_, encoded) = generate_encoded_key()?;