From 52d247f102518793bda047693c30002d5e3bd416 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 8 Aug 2021 12:34:06 -0400 Subject: [PATCH] cargo fmt --- src/main.rs | 8 ++++--- steamguard/src/lib.rs | 2 +- steamguard/src/steamapi.rs | 46 +++++++++++++++++++++++-------------- steamguard/src/userlogin.rs | 26 ++++++++++----------- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/main.rs b/src/main.rs index 845cbb7..8ac101f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,9 @@ use std::{ path::Path, sync::{Arc, Mutex}, }; -use steamguard::{steamapi, Confirmation, ConfirmationType, SteamGuardAccount, UserLogin, LoginError}; +use steamguard::{ + steamapi, Confirmation, ConfirmationType, LoginError, SteamGuardAccount, UserLogin, +}; use termion::{ event::{Event, Key}, input::TermRead, @@ -399,12 +401,12 @@ fn do_login(account: &mut SteamGuardAccount) { break; } Err(LoginError::Need2FA) => { - debug!("generating 2fa code and retrying"); + debug!("generating 2fa code and retrying"); let server_time = steamapi::get_server_time(); login.twofactor_code = account.generate_code(server_time); } Err(LoginError::NeedCaptcha { captcha_gid }) => { - debug!("need captcha to log in"); + debug!("need captcha to log in"); login.captcha_text = prompt_captcha_text(&captcha_gid); } Err(LoginError::NeedEmail) => { diff --git a/steamguard/src/lib.rs b/steamguard/src/lib.rs index f602336..e7d6bd2 100644 --- a/steamguard/src/lib.rs +++ b/steamguard/src/lib.rs @@ -1,6 +1,5 @@ use anyhow::Result; pub use confirmation::{Confirmation, ConfirmationType}; -pub use userlogin::{LoginError, UserLogin}; use hmacsha1::hmac_sha1; use log::*; use reqwest::{ @@ -11,6 +10,7 @@ use reqwest::{ use scraper::{Html, Selector}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, convert::TryInto, thread, time}; +pub use userlogin::{LoginError, UserLogin}; #[macro_use] extern crate lazy_static; #[macro_use] diff --git a/steamguard/src/steamapi.rs b/steamguard/src/steamapi.rs index 34c83bf..d60c563 100644 --- a/steamguard/src/steamapi.rs +++ b/steamguard/src/steamapi.rs @@ -6,7 +6,7 @@ use reqwest::{ header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE}, Url, }; -use serde::{Deserialize, Serialize, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize}; use std::iter::FromIterator; use std::str::FromStr; use std::time::{SystemTime, UNIX_EPOCH}; @@ -48,7 +48,7 @@ where { // for some reason, deserializing to &str doesn't work but this does. let s: String = Deserialize::deserialize(deserializer)?; - let data: OAuthData = serde_json::from_str(s.as_str()).map_err(serde::de::Error::custom)?; + let data: OAuthData = serde_json::from_str(s.as_str()).map_err(serde::de::Error::custom)?; Ok(Some(data)) } @@ -294,26 +294,38 @@ impl SteamApiClient { #[test] fn test_oauth_data_parse() { // This example is from a login response that did not contain any transfer URLs. - let oauth: OAuthData = serde_json::from_str("{\"steamid\":\"78562647129469312\",\"account_name\":\"feuarus\",\"oauth_token\":\"fd2fdb3d0717bcd2220d98c7ec61c7bd\",\"wgtoken\":\"72E7013D598A4F68C7E268F6FA3767D89D763732\",\"wgtoken_secure\":\"21061EA13C36D7C29812CAED900A215171AD13A2\",\"webcookie\":\"6298070A226E5DAD49938D78BCF36F7A7118FDD5\"}").unwrap(); + let oauth: OAuthData = serde_json::from_str("{\"steamid\":\"78562647129469312\",\"account_name\":\"feuarus\",\"oauth_token\":\"fd2fdb3d0717bcd2220d98c7ec61c7bd\",\"wgtoken\":\"72E7013D598A4F68C7E268F6FA3767D89D763732\",\"wgtoken_secure\":\"21061EA13C36D7C29812CAED900A215171AD13A2\",\"webcookie\":\"6298070A226E5DAD49938D78BCF36F7A7118FDD5\"}").unwrap(); - assert_eq!(oauth.steamid, "78562647129469312"); - assert_eq!(oauth.oauth_token, "fd2fdb3d0717bcd2220d98c7ec61c7bd"); - assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732"); - assert_eq!(oauth.wgtoken_secure, "21061EA13C36D7C29812CAED900A215171AD13A2"); - assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5"); + assert_eq!(oauth.steamid, "78562647129469312"); + assert_eq!(oauth.oauth_token, "fd2fdb3d0717bcd2220d98c7ec61c7bd"); + assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732"); + assert_eq!( + oauth.wgtoken_secure, + "21061EA13C36D7C29812CAED900A215171AD13A2" + ); + assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5"); } #[test] fn test_login_response_parse() { - let result = serde_json::from_str::(include_str!("fixtures/api-responses/login-response1.json")); + let result = serde_json::from_str::(include_str!( + "fixtures/api-responses/login-response1.json" + )); - assert!(matches!(result, Ok(_)), "got error: {}", result.unwrap_err()); - let resp = result.unwrap(); + assert!( + matches!(result, Ok(_)), + "got error: {}", + result.unwrap_err() + ); + let resp = result.unwrap(); - let oauth = resp.oauth.unwrap(); - assert_eq!(oauth.steamid, "78562647129469312"); - assert_eq!(oauth.oauth_token, "fd2fdb3d0717bad2220d98c7ec61c7bd"); - assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732"); - assert_eq!(oauth.wgtoken_secure, "21061EA13C36D7C29812CAED900A215171AD13A2"); - assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5"); + let oauth = resp.oauth.unwrap(); + assert_eq!(oauth.steamid, "78562647129469312"); + assert_eq!(oauth.oauth_token, "fd2fdb3d0717bad2220d98c7ec61c7bd"); + assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732"); + assert_eq!( + oauth.wgtoken_secure, + "21061EA13C36D7C29812CAED900A215171AD13A2" + ); + assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5"); } diff --git a/steamguard/src/userlogin.rs b/steamguard/src/userlogin.rs index e0fde0d..c120263 100644 --- a/steamguard/src/userlogin.rs +++ b/steamguard/src/userlogin.rs @@ -1,7 +1,7 @@ +use crate::steamapi::{LoginResponse, RsaResponse, Session, SteamApiClient}; use log::*; use rsa::{PublicKey, RsaPublicKey}; use std::time::{SystemTime, UNIX_EPOCH}; -use crate::steamapi::{SteamApiClient, LoginResponse, RsaResponse, Session}; #[derive(Debug)] pub enum LoginError { @@ -77,17 +77,17 @@ impl UserLogin { self.client.update_session()?; } - let params = hashmap!{ - "donotcache" => format!( - "{}", - SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs() - * 1000 - ), - "username" => self.username.clone(), - }; + let params = hashmap! { + "donotcache" => format!( + "{}", + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() + * 1000 + ), + "username" => self.username.clone(), + }; let resp = self .client .post("https://steamcommunity.com/login/getrsakey") @@ -187,4 +187,4 @@ fn test_encrypt_password() { let result = encrypt_password(rsa_resp, &String::from("kelwleofpsm3n4ofc")); assert_eq!(result.len(), 344); assert_eq!(result, "RUo/3IfbkVcJi1q1S5QlpKn1mEn3gNJoc/Z4VwxRV9DImV6veq/YISEuSrHB3885U5MYFLn1g94Y+cWRL6HGXoV+gOaVZe43m7O92RwiVz6OZQXMfAv3UC/jcqn/xkitnj+tNtmx55gCxmGbO2KbqQ0TQqAyqCOOw565B+Cwr2OOorpMZAViv9sKA/G3Q6yzscU6rhua179c8QjC1Hk3idUoSzpWfT4sHNBW/EREXZ3Dkjwu17xzpfwIUpnBVIlR8Vj3coHgUCpTsKVRA3T814v9BYPlvLYwmw5DW3ddx+2SyTY0P5uuog36TN2PqYS7ioF5eDe16gyfRR4Nzn/7wA=="); -} \ No newline at end of file +}