From ad2cdd2a7e1879aa4d0330b828e4bb342f31c630 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 9 Aug 2021 22:00:49 -0400 Subject: [PATCH] fix parsing for add authenticator response --- .../api-responses/add-authenticator-1.json | 1 + steamguard/src/steamapi.rs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 steamguard/src/fixtures/api-responses/add-authenticator-1.json diff --git a/steamguard/src/fixtures/api-responses/add-authenticator-1.json b/steamguard/src/fixtures/api-responses/add-authenticator-1.json new file mode 100644 index 0000000..536f196 --- /dev/null +++ b/steamguard/src/fixtures/api-responses/add-authenticator-1.json @@ -0,0 +1 @@ +{"response":{"shared_secret":"wGwZx=sX5MmTxi6QgA3Gi","serial_number":"72016503753671","revocation_code":"R123456","uri":"otpauth://totp/Steam:hydrastar2?secret=JRX7DZIF4JNA3QE3UMS4BDACDISZTRWA&issuer=Steam","server_time":"1628559846","account_name":"hydrastar2","token_gid":"fe12390348285d7f4","identity_secret":"soo58ouTUV+5=KhRKDVK","secret_1":"Me7ngFQsY9R=x3EQyOU","status":1}} \ No newline at end of file diff --git a/steamguard/src/steamapi.rs b/steamguard/src/steamapi.rs index 919f6a2..eff5460 100644 --- a/steamguard/src/steamapi.rs +++ b/steamguard/src/steamapi.rs @@ -513,6 +513,7 @@ pub struct AddAuthenticatorResponse { /// URI for QR code generation pub uri: String, /// Current server time + #[serde(deserialize_with = "parse_json_string_as_number")] pub server_time: u64, /// Account name to display on token client pub account_name: String, @@ -552,3 +553,30 @@ pub struct FinalizeAddAuthenticatorResponse { pub want_more: bool, pub success: bool, } + +fn parse_json_string_as_number<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + // for some reason, deserializing to &str doesn't work but this does. + let s: String = Deserialize::deserialize(deserializer)?; + Ok(s.parse().unwrap()) +} + +#[test] +fn test_parse_add_auth_response() { + let result = serde_json::from_str::>(include_str!( + "fixtures/api-responses/add-authenticator-1.json" + )); + + assert!( + matches!(result, Ok(_)), + "got error: {}", + result.unwrap_err() + ); + let resp = result.unwrap().response; + + assert_eq!(resp.server_time, 1628559846); + assert_eq!(resp.shared_secret, "wGwZx=sX5MmTxi6QgA3Gi"); + assert_eq!(resp.revocation_code, "R123456"); +} \ No newline at end of file