From 0380952a8358b7d17da11aa9cbba146a8d0bd53c Mon Sep 17 00:00:00 2001 From: Dinculescu Date: Sun, 17 Dec 2023 20:01:09 +0000 Subject: [PATCH] Return the more specific InvalidCredentials error Fixes #138. --- CHANGELOG.md | 8 ++++++++ tapo/src/api/protocol/klap_protocol.rs | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 296ea0b..cdd10ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,16 @@ file. This change log follows the conventions of ## [Rust Unreleased][Unreleased] +### Changed + +- The `anyhow::anyhow!("Local hash does not match server hash")` error has been replaced with the more specific `tapo::TapoResponseError::InvalidCredentials` error. + ## [Python Unreleased][Unreleased] +### Changed + +- The `anyhow::anyhow!("Local hash does not match server hash")` error has been replaced with the more specific `tapo::TapoResponseError::InvalidCredentials` error. + ## [Rust v0.7.6][v0.7.6] - 2023-11-25 ### Added diff --git a/tapo/src/api/protocol/klap_protocol.rs b/tapo/src/api/protocol/klap_protocol.rs index f5859da..f6b339b 100644 --- a/tapo/src/api/protocol/klap_protocol.rs +++ b/tapo/src/api/protocol/klap_protocol.rs @@ -4,14 +4,14 @@ use async_trait::async_trait; use isahc::cookies::CookieJar; use isahc::prelude::Configurable; use isahc::{AsyncReadResponseExt, HttpClient, Request}; -use log::debug; +use log::{debug, warn}; use rand::rngs::StdRng; use rand::{RngCore, SeedableRng}; use serde::de::DeserializeOwned; use crate::requests::TapoRequest; use crate::responses::{validate_response, TapoResponse, TapoResponseExt}; -use crate::Error; +use crate::{Error, TapoResponseError}; use super::discovery_protocol::DiscoveryProtocol; use super::klap_cipher::KlapCipher; @@ -157,7 +157,8 @@ impl KlapProtocol { let local_hash = KlapCipher::sha256(&[local_seed, remote_seed, auth_hash].concat()); if local_hash != server_hash { - return Err(anyhow::anyhow!("Local hash does not match server hash").into()); + warn!("Local hash does not match server hash"); + return Err(Error::Tapo(TapoResponseError::InvalidCredentials)); } debug!("Handshake1 OK");