Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from from_str to parse #299

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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