cargo fmt

This commit is contained in:
Carson McManus 2022-06-19 14:44:18 -04:00
parent eeded86641
commit 1a6ad62a2e
6 changed files with 72 additions and 26 deletions

View file

@ -7,7 +7,7 @@ use std::fs::File;
use std::io::{BufReader, Read, Write}; use std::io::{BufReader, Read, Write};
use std::path::Path; use std::path::Path;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use steamguard::{SteamGuardAccount, ExposeSecret}; use steamguard::{ExposeSecret, SteamGuardAccount};
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -169,7 +169,10 @@ impl Manifest {
pub fn add_account(&mut self, account: SteamGuardAccount) { pub fn add_account(&mut self, account: SteamGuardAccount) {
debug!("adding account to manifest: {}", account.account_name); 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 { self.entries.push(ManifestEntry {
filename: format!("{}.maFile", &account.account_name), filename: format!("{}.maFile", &account.account_name),
steam_id: steamid, steam_id: steamid,
@ -373,7 +376,7 @@ impl From<std::io::Error> for ManifestAccountLoadError {
mod tests { mod tests {
use super::*; use super::*;
use steamguard::ExposeSecret; use steamguard::ExposeSecret;
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
fn test_should_save_new_manifest() { fn test_should_save_new_manifest() {
@ -420,7 +423,8 @@ use tempdir::TempDir;
.get_account(&account_name)? .get_account(&account_name)?
.lock() .lock()
.unwrap() .unwrap()
.revocation_code.expose_secret(), .revocation_code
.expose_secret(),
"R12345" "R12345"
); );
assert_eq!( assert_eq!(
@ -480,7 +484,8 @@ use tempdir::TempDir;
.get_account(&account_name)? .get_account(&account_name)?
.lock() .lock()
.unwrap() .unwrap()
.revocation_code.expose_secret(), .revocation_code
.expose_secret(),
"R12345" "R12345"
); );
assert_eq!( assert_eq!(
@ -540,7 +545,8 @@ use tempdir::TempDir;
.get_account(&account_name)? .get_account(&account_name)?
.lock() .lock()
.unwrap() .unwrap()
.revocation_code.expose_secret(), .revocation_code
.expose_secret(),
"R12345" "R12345"
); );
assert_eq!( assert_eq!(
@ -604,7 +610,8 @@ use tempdir::TempDir;
.get_account(&account_name)? .get_account(&account_name)?
.lock() .lock()
.unwrap() .unwrap()
.revocation_code.expose_secret(), .revocation_code
.expose_secret(),
"R12345" "R12345"
); );
assert_eq!( assert_eq!(
@ -675,7 +682,14 @@ use tempdir::TempDir;
let account = manifest.get_account(&account_name)?; let account = manifest.get_account(&account_name)?;
assert_eq!(account_name, account.lock().unwrap().account_name); assert_eq!(account_name, account.lock().unwrap().account_name);
assert_eq!( 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 None
); );
Ok(()) Ok(())
@ -691,18 +705,38 @@ use tempdir::TempDir;
let account_name = manifest.entries[0].account_name.clone(); let account_name = manifest.entries[0].account_name.clone();
let account = manifest.get_account(&account_name)?; let account = manifest.get_account(&account_name)?;
assert_eq!(account_name, account.lock().unwrap().account_name); assert_eq!(account_name, account.lock().unwrap().account_name);
assert_eq!(account.lock().unwrap().revocation_code.expose_secret(), "R12345");
assert_eq!( 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 1234
); );
let account_name = manifest.entries[1].account_name.clone(); let account_name = manifest.entries[1].account_name.clone();
let account = manifest.get_account(&account_name)?; let account = manifest.get_account(&account_name)?;
assert_eq!(account_name, account.lock().unwrap().account_name); assert_eq!(account_name, account.lock().unwrap().account_name);
assert_eq!(account.lock().unwrap().revocation_code.expose_secret(), "R56789");
assert_eq!( 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 5678
); );
Ok(()) Ok(())

View file

@ -7,8 +7,8 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use steamguard::{ use steamguard::{
steamapi, AccountLinkError, AccountLinker, Confirmation, FinalizeLinkError, LoginError, steamapi, AccountLinkError, AccountLinker, Confirmation, ExposeSecret, FinalizeLinkError,
SteamGuardAccount, UserLogin, ExposeSecret, LoginError, SteamGuardAccount, UserLogin,
}; };
use crate::accountmanager::ManifestAccountLoadError; use crate::accountmanager::ManifestAccountLoadError;

View file

@ -11,9 +11,9 @@ use reqwest::{
Url, Url,
}; };
use scraper::{Html, Selector}; use scraper::{Html, Selector};
pub use secrecy::{ExposeSecret, SecretString};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{collections::HashMap, convert::TryInto}; use std::{collections::HashMap, convert::TryInto};
pub use secrecy::{ExposeSecret, SecretString};
use steamapi::SteamApiClient; use steamapi::SteamApiClient;
pub use userlogin::{LoginError, UserLogin}; pub use userlogin::{LoginError, UserLogin};
#[macro_use] #[macro_use]
@ -25,10 +25,10 @@ extern crate maplit;
mod accountlinker; mod accountlinker;
mod confirmation; mod confirmation;
mod secret_string;
pub mod steamapi; pub mod steamapi;
pub mod token; pub mod token;
mod userlogin; mod userlogin;
mod secret_string;
// const STEAMAPI_BASE: String = "https://api.steampowered.com"; // const STEAMAPI_BASE: String = "https://api.steampowered.com";
// const COMMUNITY_BASE: String = "https://steamcommunity.com"; // const COMMUNITY_BASE: String = "https://steamcommunity.com";
@ -41,7 +41,6 @@ extern crate base64;
extern crate cookie; extern crate cookie;
extern crate hmacsha1; extern crate hmacsha1;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SteamGuardAccount { pub struct SteamGuardAccount {
pub account_name: String, pub account_name: String,
@ -240,8 +239,9 @@ impl SteamGuardAccount {
"Revocation code not provided." "Revocation code not provided."
); );
let client: SteamApiClient = SteamApiClient::new(self.session.clone()); let client: SteamApiClient = SteamApiClient::new(self.session.clone());
let resp = let resp = client.remove_authenticator(
client.remove_authenticator(revocation_code.unwrap_or(self.revocation_code.expose_secret().to_owned()))?; revocation_code.unwrap_or(self.revocation_code.expose_secret().to_owned()),
)?;
Ok(resp.success) Ok(resp.success)
} }
} }

View file

@ -1,13 +1,19 @@
use serde::{Deserialize, Serialize, Serializer, Deserializer}; use secrecy::{ExposeSecret, SecretString};
use secrecy::{SecretString, ExposeSecret}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// Helper to allow serializing a [secrecy::SecretString] as a [String] /// Helper to allow serializing a [secrecy::SecretString] as a [String]
pub(crate) fn serialize<S>(secret_string: &SecretString, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer { pub(crate) fn serialize<S>(secret_string: &SecretString, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(secret_string.expose_secret()) serializer.serialize_str(secret_string.expose_secret())
} }
/// Helper to allow deserializing a [String] as a [secrecy::SecretString] /// Helper to allow deserializing a [String] as a [secrecy::SecretString]
pub(crate) fn deserialize<'de, D>(d: D) -> Result<secrecy::SecretString, D::Error> where D: Deserializer<'de> { pub(crate) fn deserialize<'de, D>(d: D) -> Result<secrecy::SecretString, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(d)?; let s = String::deserialize(d)?;
Ok(SecretString::new(s)) Ok(SecretString::new(s))
} }

View file

@ -8,13 +8,13 @@ use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE}, header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE},
Url, Url,
}; };
use secrecy::{SerializableSecret, CloneableSecret, DebugSecret, ExposeSecret}; use secrecy::{CloneableSecret, DebugSecret, ExposeSecret, SerializableSecret};
use zeroize::Zeroize;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value; use serde_json::Value;
use std::iter::FromIterator; use std::iter::FromIterator;
use std::str::FromStr; use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use zeroize::Zeroize;
lazy_static! { lazy_static! {
static ref STEAM_COOKIE_URL: Url = "https://steamcommunity.com".parse::<Url>().unwrap(); static ref STEAM_COOKIE_URL: Url = "https://steamcommunity.com".parse::<Url>().unwrap();

View file

@ -155,7 +155,13 @@ impl UserLogin {
self.client.transfer_login(login_resp)?; 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());
} }
} }