Skip to content

Commit

Permalink
Switch from from_str to parse (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton authored Oct 23, 2023
1 parent 9ff37c7 commit 1601ecd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 2 additions & 4 deletions crates/bitwarden/src/auth/login/access_token.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use base64::Engine;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -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)?;

Expand Down
6 changes: 2 additions & 4 deletions crates/bitwarden/src/auth/login/api_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -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.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)?;
}
Expand Down
7 changes: 2 additions & 5 deletions crates/bitwarden/src/auth/login/password.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "internal")]
use std::str::FromStr;

#[cfg(feature = "internal")]
use log::{debug, info};
use schemars::JsonSchema;
Expand Down Expand Up @@ -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.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)?;
}
Expand Down

0 comments on commit 1601ecd

Please sign in to comment.