diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-06 07:20:11 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-06 07:20:11 -0400 |
commit | 1c40a0f9ff0ced652ee8b74f2333000ca47a0692 (patch) | |
tree | a0be3e77060d7f267596d70e4ce14b4604f9bb25 /src/actions.rs | |
parent | bc18bca5c67b4a678a31198877e39d57d97b1e0c (diff) | |
download | rbw-1c40a0f9ff0ced652ee8b74f2333000ca47a0692.tar.gz rbw-1c40a0f9ff0ced652ee8b74f2333000ca47a0692.zip |
a bit more cleanup
Diffstat (limited to 'src/actions.rs')
-rw-r--r-- | src/actions.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/actions.rs b/src/actions.rs index d7f3103..0998abc 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,20 +1,21 @@ -// TODO api needs to be async +use crate::prelude::*; -pub async fn login(email: &str, password: &str) -> (String, u32, String) { +pub async fn login( + email: &str, + password: &str, +) -> Result<(String, u32, String)> { let client = crate::api::Client::new_self_hosted("https://bitwarden.tozt.net"); - let iterations = client.prelogin(&email).await.unwrap(); + let iterations = client.prelogin(&email).await?; let identity = - crate::identity::Identity::new(&email, &password, iterations) - .unwrap(); + crate::identity::Identity::new(&email, &password, iterations)?; let (access_token, _refresh_token, protected_key) = client .login(&identity.email, &identity.master_password_hash) - .await - .unwrap(); + .await?; - (access_token, iterations, protected_key) + Ok((access_token, iterations, protected_key)) } pub async fn unlock( @@ -22,25 +23,25 @@ pub async fn unlock( password: &str, iterations: u32, protected_key: String, -) -> (Vec<u8>, Vec<u8>) { +) -> Result<(Vec<u8>, Vec<u8>)> { let identity = - crate::identity::Identity::new(&email, &password, iterations) - .unwrap(); + crate::identity::Identity::new(&email, &password, iterations)?; let protected_key = - crate::cipherstring::CipherString::new(&protected_key).unwrap(); - let master_key = protected_key - .decrypt(&identity.enc_key, &identity.mac_key) - .unwrap(); + crate::cipherstring::CipherString::new(&protected_key)?; + let master_key = + protected_key.decrypt(&identity.enc_key, &identity.mac_key)?; let enc_key = &master_key[0..32]; let mac_key = &master_key[32..64]; - (enc_key.to_vec(), mac_key.to_vec()) + Ok((enc_key.to_vec(), mac_key.to_vec())) } -pub async fn sync(access_token: &str) -> (String, Vec<crate::api::Cipher>) { +pub async fn sync( + access_token: &str, +) -> Result<(String, Vec<crate::api::Cipher>)> { let client = crate::api::Client::new_self_hosted("https://bitwarden.tozt.net"); - client.sync(access_token).await.unwrap() + client.sync(access_token).await } |