diff --git a/proxmox-login/src/lib.rs b/proxmox-login/src/lib.rs index 6fbccd9f..f5f95933 100644 --- a/proxmox-login/src/lib.rs +++ b/proxmox-login/src/lib.rs @@ -128,10 +128,17 @@ impl Login { /// /// On success, this will either yield an [`Authentication`] or a [`SecondFactorChallenge`] if /// Two-Factor-Authentication is required. - pub fn response(&self, body: &str) -> Result { + pub fn response>( + &self, + body: &T, + ) -> Result { + self.response_bytes(body.as_ref()) + } + + fn response_bytes(&self, body: &[u8]) -> Result { use ticket::TicketResponse; - let response: api::ApiResponse = serde_json::from_str(body)?; + let response: api::ApiResponse = serde_json::from_slice(body)?; let response = response.data.ok_or("missing response data")?; if response.username != self.userid { @@ -271,8 +278,15 @@ impl SecondFactorChallenge { } /// Deal with the API's response object to extract the ticket. - pub fn response(&self, body: &str) -> Result { - let response: api::ApiResponse = serde_json::from_str(body)?; + pub fn response>( + &self, + body: &T, + ) -> Result { + self.response_bytes(body.as_ref()) + } + + fn response_bytes(&self, body: &[u8]) -> Result { + let response: api::ApiResponse = serde_json::from_slice(body)?; let response = response.data.ok_or("missing response data")?; if response.username != self.userid {