diff --git a/src/accountmanager/legacy.rs b/src/accountmanager/legacy.rs index 3b8e637..63202a9 100644 --- a/src/accountmanager/legacy.rs +++ b/src/accountmanager/legacy.rs @@ -142,15 +142,15 @@ pub struct SdaAccount { #[zeroize(drop)] #[deprecated(note = "this is not used anymore, the closest equivalent is `Tokens`")] pub struct Session { - #[serde(rename = "SessionID")] + #[serde(default, rename = "SessionID")] pub session_id: String, - #[serde(rename = "SteamLogin")] + #[serde(default, rename = "SteamLogin")] pub steam_login: String, - #[serde(rename = "SteamLoginSecure")] + #[serde(default, rename = "SteamLoginSecure")] pub steam_login_secure: String, #[serde(default, rename = "WebCookie")] pub web_cookie: Option, - #[serde(rename = "OAuthToken")] + #[serde(default, rename = "OAuthToken")] pub token: String, #[serde(rename = "SteamID")] pub steam_id: u64, diff --git a/src/accountmanager/migrate.rs b/src/accountmanager/migrate.rs index 9141cad..55b6a7d 100644 --- a/src/accountmanager/migrate.rs +++ b/src/accountmanager/migrate.rs @@ -1,6 +1,3 @@ -// notes for migration: -// account names must be made lowercase - use std::{fs::File, io::Read, path::Path}; use log::debug; diff --git a/src/commands/debug.rs b/src/commands/debug.rs index 70b608c..8110294 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -1,7 +1,7 @@ use log::*; use steamguard::{Confirmation, ConfirmationType}; -use crate::tui; +use crate::{debug::parse_json_stripped, tui}; use super::*; @@ -16,6 +16,12 @@ pub struct DebugCommand { pub demo_prompt_char: bool, #[clap(long, help = "Show an example confirmation menu using dummy data.")] pub demo_conf_menu: bool, + + #[clap( + long, + help = "Read the specified file, parse it, strip values, and print the result." + )] + pub print_stripped_json: Option, } impl ConstCommand for DebugCommand { @@ -32,6 +38,9 @@ impl ConstCommand for DebugCommand { if self.demo_conf_menu { demo_confirmation_menu(); } + if let Some(path) = self.print_stripped_json.as_ref() { + debug_print_json(path)?; + } Ok(()) } } @@ -96,3 +105,11 @@ pub fn demo_confirmation_menu() { .expect("confirmation menu demo failed"); println!("accept: {}, deny: {}", accept.len(), deny.len()); } + +fn debug_print_json(path: &str) -> anyhow::Result<()> { + let json = std::fs::read_to_string(path)?; + let v = parse_json_stripped(&json)?; + println!("{}", serde_json::to_string_pretty(&v)?); + + Ok(()) +} diff --git a/src/debug.rs b/src/debug.rs new file mode 100644 index 0000000..0f7a7f4 --- /dev/null +++ b/src/debug.rs @@ -0,0 +1,27 @@ +/// Parses a JSON string and prints it in a readable format, with all values stripped and replaced with their types. +pub fn parse_json_stripped(json: &str) -> anyhow::Result { + let v: serde_json::Value = serde_json::from_str(json)?; + let v = strip_json_value(v); + Ok(v) +} + +pub fn strip_json_value(v: serde_json::Value) -> serde_json::Value { + match v { + serde_json::Value::Object(mut map) => { + for (_, v) in map.iter_mut() { + *v = strip_json_value(v.clone()); + } + serde_json::Value::Object(map) + } + serde_json::Value::Array(mut arr) => { + for v in arr.iter_mut() { + *v = strip_json_value(v.clone()); + } + serde_json::Value::Array(arr) + } + serde_json::Value::String(_) => serde_json::Value::String("string".into()), + serde_json::Value::Number(_) => serde_json::Value::Number(0.into()), + serde_json::Value::Bool(_) => serde_json::Value::Bool(false), + serde_json::Value::Null => serde_json::Value::Null, + } +} diff --git a/src/main.rs b/src/main.rs index 43fc26e..ddb9bf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ extern crate proptest; extern crate ring; mod accountmanager; mod commands; +mod debug; mod encryption; mod errors; mod secret_string;