diff --git a/src/accountmanager.rs b/src/accountmanager.rs index f9d89ec..9726454 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -7,7 +7,7 @@ use std::fs::File; use std::io::{BufReader, Read, Write}; use std::path::Path; use std::sync::{Arc, Mutex}; -use steamguard::{SteamGuardAccount, ExposeSecret}; +use steamguard::{ExposeSecret, SteamGuardAccount}; use thiserror::Error; #[derive(Debug, Serialize, Deserialize)] @@ -169,7 +169,10 @@ impl Manifest { pub fn add_account(&mut self, account: SteamGuardAccount) { debug!("adding account to manifest: {}", account.account_name); - let steamid = account.session.as_ref().map_or(0, |s| s.expose_secret().steam_id); + let steamid = account + .session + .as_ref() + .map_or(0, |s| s.expose_secret().steam_id); self.entries.push(ManifestEntry { filename: format!("{}.maFile", &account.account_name), steam_id: steamid, @@ -373,7 +376,7 @@ impl From for ManifestAccountLoadError { mod tests { use super::*; use steamguard::ExposeSecret; -use tempdir::TempDir; + use tempdir::TempDir; #[test] fn test_should_save_new_manifest() { @@ -420,7 +423,8 @@ use tempdir::TempDir; .get_account(&account_name)? .lock() .unwrap() - .revocation_code.expose_secret(), + .revocation_code + .expose_secret(), "R12345" ); assert_eq!( @@ -480,7 +484,8 @@ use tempdir::TempDir; .get_account(&account_name)? .lock() .unwrap() - .revocation_code.expose_secret(), + .revocation_code + .expose_secret(), "R12345" ); assert_eq!( @@ -540,7 +545,8 @@ use tempdir::TempDir; .get_account(&account_name)? .lock() .unwrap() - .revocation_code.expose_secret(), + .revocation_code + .expose_secret(), "R12345" ); assert_eq!( @@ -604,7 +610,8 @@ use tempdir::TempDir; .get_account(&account_name)? .lock() .unwrap() - .revocation_code.expose_secret(), + .revocation_code + .expose_secret(), "R12345" ); assert_eq!( @@ -675,7 +682,14 @@ use tempdir::TempDir; let account = manifest.get_account(&account_name)?; assert_eq!(account_name, account.lock().unwrap().account_name); assert_eq!( - account.lock().unwrap().session.as_ref().unwrap().expose_secret().web_cookie, + account + .lock() + .unwrap() + .session + .as_ref() + .unwrap() + .expose_secret() + .web_cookie, None ); Ok(()) @@ -691,18 +705,38 @@ use tempdir::TempDir; let account_name = manifest.entries[0].account_name.clone(); let account = manifest.get_account(&account_name)?; assert_eq!(account_name, account.lock().unwrap().account_name); - assert_eq!(account.lock().unwrap().revocation_code.expose_secret(), "R12345"); assert_eq!( - account.lock().unwrap().session.as_ref().unwrap().expose_secret().steam_id, + account.lock().unwrap().revocation_code.expose_secret(), + "R12345" + ); + assert_eq!( + account + .lock() + .unwrap() + .session + .as_ref() + .unwrap() + .expose_secret() + .steam_id, 1234 ); let account_name = manifest.entries[1].account_name.clone(); let account = manifest.get_account(&account_name)?; assert_eq!(account_name, account.lock().unwrap().account_name); - assert_eq!(account.lock().unwrap().revocation_code.expose_secret(), "R56789"); assert_eq!( - account.lock().unwrap().session.as_ref().unwrap().expose_secret().steam_id, + account.lock().unwrap().revocation_code.expose_secret(), + "R56789" + ); + assert_eq!( + account + .lock() + .unwrap() + .session + .as_ref() + .unwrap() + .expose_secret() + .steam_id, 5678 ); Ok(()) diff --git a/src/main.rs b/src/main.rs index 03753be..c457bc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,8 @@ use std::{ sync::{Arc, Mutex}, }; use steamguard::{ - steamapi, AccountLinkError, AccountLinker, Confirmation, FinalizeLinkError, LoginError, - SteamGuardAccount, UserLogin, ExposeSecret, + steamapi, AccountLinkError, AccountLinker, Confirmation, ExposeSecret, FinalizeLinkError, + LoginError, SteamGuardAccount, UserLogin, }; use crate::accountmanager::ManifestAccountLoadError; diff --git a/steamguard/src/lib.rs b/steamguard/src/lib.rs index 903e4f2..f380053 100644 --- a/steamguard/src/lib.rs +++ b/steamguard/src/lib.rs @@ -11,9 +11,9 @@ use reqwest::{ Url, }; use scraper::{Html, Selector}; +pub use secrecy::{ExposeSecret, SecretString}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, convert::TryInto}; -pub use secrecy::{ExposeSecret, SecretString}; use steamapi::SteamApiClient; pub use userlogin::{LoginError, UserLogin}; #[macro_use] @@ -25,10 +25,10 @@ extern crate maplit; mod accountlinker; mod confirmation; +mod secret_string; pub mod steamapi; pub mod token; mod userlogin; -mod secret_string; // const STEAMAPI_BASE: String = "https://api.steampowered.com"; // const COMMUNITY_BASE: String = "https://steamcommunity.com"; @@ -41,7 +41,6 @@ extern crate base64; extern crate cookie; extern crate hmacsha1; - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SteamGuardAccount { pub account_name: String, @@ -240,8 +239,9 @@ impl SteamGuardAccount { "Revocation code not provided." ); let client: SteamApiClient = SteamApiClient::new(self.session.clone()); - let resp = - client.remove_authenticator(revocation_code.unwrap_or(self.revocation_code.expose_secret().to_owned()))?; + let resp = client.remove_authenticator( + revocation_code.unwrap_or(self.revocation_code.expose_secret().to_owned()), + )?; Ok(resp.success) } } diff --git a/steamguard/src/secret_string.rs b/steamguard/src/secret_string.rs index b409f8f..02361e5 100644 --- a/steamguard/src/secret_string.rs +++ b/steamguard/src/secret_string.rs @@ -1,13 +1,19 @@ -use serde::{Deserialize, Serialize, Serializer, Deserializer}; -use secrecy::{SecretString, ExposeSecret}; +use secrecy::{ExposeSecret, SecretString}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Helper to allow serializing a [secrecy::SecretString] as a [String] -pub(crate) fn serialize(secret_string: &SecretString, serializer: S) -> Result where S: Serializer { +pub(crate) fn serialize(secret_string: &SecretString, serializer: S) -> Result +where + S: Serializer, +{ serializer.serialize_str(secret_string.expose_secret()) } /// Helper to allow deserializing a [String] as a [secrecy::SecretString] -pub(crate) fn deserialize<'de, D>(d: D) -> Result where D: Deserializer<'de> { +pub(crate) fn deserialize<'de, D>(d: D) -> Result +where + D: Deserializer<'de>, +{ let s = String::deserialize(d)?; Ok(SecretString::new(s)) } diff --git a/steamguard/src/steamapi.rs b/steamguard/src/steamapi.rs index adf0551..7ddebd7 100644 --- a/steamguard/src/steamapi.rs +++ b/steamguard/src/steamapi.rs @@ -8,13 +8,13 @@ use reqwest::{ header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE}, Url, }; -use secrecy::{SerializableSecret, CloneableSecret, DebugSecret, ExposeSecret}; -use zeroize::Zeroize; +use secrecy::{CloneableSecret, DebugSecret, ExposeSecret, SerializableSecret}; use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; use std::iter::FromIterator; use std::str::FromStr; use std::time::{SystemTime, UNIX_EPOCH}; +use zeroize::Zeroize; lazy_static! { static ref STEAM_COOKIE_URL: Url = "https://steamcommunity.com".parse::().unwrap(); diff --git a/steamguard/src/userlogin.rs b/steamguard/src/userlogin.rs index f285b41..4400f61 100644 --- a/steamguard/src/userlogin.rs +++ b/steamguard/src/userlogin.rs @@ -155,7 +155,13 @@ impl UserLogin { self.client.transfer_login(login_resp)?; } - return Ok(self.client.session.as_ref().unwrap().expose_secret().to_owned()); + return Ok(self + .client + .session + .as_ref() + .unwrap() + .expose_secret() + .to_owned()); } }