From 110f3f7438a98b1bcd100024ac4c5927a49cc06a Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 20 Oct 2023 18:19:49 +0200 Subject: [PATCH 1/2] Switch from from_str to parse --- crates/bitwarden/src/auth/login/access_token.rs | 6 ++---- crates/bitwarden/src/auth/login/api_key.rs | 6 ++---- crates/bitwarden/src/auth/login/password.rs | 7 ++----- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/bitwarden/src/auth/login/access_token.rs b/crates/bitwarden/src/auth/login/access_token.rs index 46fa35779..63fd86ebb 100644 --- a/crates/bitwarden/src/auth/login/access_token.rs +++ b/crates/bitwarden/src/auth/login/access_token.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use base64::Engine; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -23,13 +21,13 @@ pub(crate) async fn access_token_login( //info!("api key logging in"); //debug!("{:#?}, {:#?}", client, input); - let access_token = AccessToken::from_str(&input.access_token)?; + let access_token: AccessToken = input.access_token.parse()?; let response = request_access_token(client, &access_token).await?; if let IdentityTokenResponse::Payload(r) = &response { // Extract the encrypted payload and use the access token encryption key to decrypt it - let payload = EncString::from_str(&r.encrypted_payload)?; + let payload: EncString = r.encrypted_payload.parse()?; let decrypted_payload = payload.decrypt_with_key(&access_token.encryption_key)?; diff --git a/crates/bitwarden/src/auth/login/api_key.rs b/crates/bitwarden/src/auth/login/api_key.rs index a9fa954d7..b16e525ef 100644 --- a/crates/bitwarden/src/auth/login/api_key.rs +++ b/crates/bitwarden/src/auth/login/api_key.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -46,8 +44,8 @@ pub(crate) async fn api_key_login( }), ); - let user_key = EncString::from_str(r.key.as_deref().unwrap()).unwrap(); - let private_key = EncString::from_str(r.private_key.as_deref().unwrap()).unwrap(); + let user_key: EncString = r.key.unwrap().parse().unwrap(); + let private_key: EncString = r.private_key.unwrap().parse().unwrap(); client.initialize_user_crypto(&input.password, user_key, private_key)?; } diff --git a/crates/bitwarden/src/auth/login/password.rs b/crates/bitwarden/src/auth/login/password.rs index 33f7ea338..520c01631 100644 --- a/crates/bitwarden/src/auth/login/password.rs +++ b/crates/bitwarden/src/auth/login/password.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "internal")] -use std::str::FromStr; - #[cfg(feature = "internal")] use log::{debug, info}; use schemars::JsonSchema; @@ -49,8 +46,8 @@ pub(crate) async fn password_login( }), ); - let user_key = EncString::from_str(r.key.as_deref().unwrap()).unwrap(); - let private_key = EncString::from_str(r.private_key.as_deref().unwrap()).unwrap(); + let user_key: EncString = r.key.unwrap().parse().unwrap(); + let private_key: EncString = r.private_key.unwrap().parse().unwrap(); client.initialize_user_crypto(&input.password, user_key, private_key)?; } From ffc18373307054cf42bbeaf16c90b3fb6aecc4ed Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 20 Oct 2023 18:30:18 +0200 Subject: [PATCH 2/2] Fix tests --- crates/bitwarden/src/auth/login/api_key.rs | 4 ++-- crates/bitwarden/src/auth/login/password.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bitwarden/src/auth/login/api_key.rs b/crates/bitwarden/src/auth/login/api_key.rs index b16e525ef..cdbc383ba 100644 --- a/crates/bitwarden/src/auth/login/api_key.rs +++ b/crates/bitwarden/src/auth/login/api_key.rs @@ -44,8 +44,8 @@ pub(crate) async fn api_key_login( }), ); - let user_key: EncString = r.key.unwrap().parse().unwrap(); - let private_key: EncString = r.private_key.unwrap().parse().unwrap(); + let user_key: EncString = r.key.as_deref().unwrap().parse().unwrap(); + let private_key: EncString = r.private_key.as_deref().unwrap().parse().unwrap(); client.initialize_user_crypto(&input.password, user_key, private_key)?; } diff --git a/crates/bitwarden/src/auth/login/password.rs b/crates/bitwarden/src/auth/login/password.rs index 520c01631..c86f7019f 100644 --- a/crates/bitwarden/src/auth/login/password.rs +++ b/crates/bitwarden/src/auth/login/password.rs @@ -46,8 +46,8 @@ pub(crate) async fn password_login( }), ); - let user_key: EncString = r.key.unwrap().parse().unwrap(); - let private_key: EncString = r.private_key.unwrap().parse().unwrap(); + let user_key: EncString = r.key.as_deref().unwrap().parse().unwrap(); + let private_key: EncString = r.private_key.as_deref().unwrap().parse().unwrap(); client.initialize_user_crypto(&input.password, user_key, private_key)?; }