From 1c40a0f9ff0ced652ee8b74f2333000ca47a0692 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 6 Apr 2020 07:20:11 -0400 Subject: a bit more cleanup --- src/actions.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/actions.rs') 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, Vec) { +) -> Result<(Vec, Vec)> { 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) { +pub async fn sync( + access_token: &str, +) -> Result<(String, Vec)> { let client = crate::api::Client::new_self_hosted("https://bitwarden.tozt.net"); - client.sync(access_token).await.unwrap() + client.sync(access_token).await } -- cgit v1.2.3-54-g00ecf