From 7254bd4fbc53b2dd7fc1bf9de05be2e975e4b672 Mon Sep 17 00:00:00 2001 From: Alex X Date: Fri, 24 Oct 2025 17:54:55 +0300 Subject: [PATCH] Code refactoring for tapo source --- pkg/tapo/client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/tapo/client.go b/pkg/tapo/client.go index 0652140e..be669eb5 100644 --- a/pkg/tapo/client.go +++ b/pkg/tapo/client.go @@ -164,8 +164,9 @@ func (c *Client) newDectypter(res *http.Response, brand, username, password stri cbc.CryptBlocks(b, b) // unpad - padSize := int(b[len(b)-1]) - return b[:len(b)-padSize] + n := len(b) + padSize := int(b[n-1]) + return b[:n-padSize] } } @@ -298,12 +299,12 @@ func dial(req *http.Request, brand, username, password string) (net.Conn, *http. return nil, nil, err } _, _ = io.Copy(io.Discard, res.Body) // discard leftovers - _ = res.Body.Close() // ignore response body + _ = res.Body.Close() // ignore response body auth := res.Header.Get("WWW-Authenticate") if res.StatusCode != http.StatusUnauthorized || !strings.HasPrefix(auth, "Digest") { - return nil, nil, fmt.Errorf("Expected StatusCode to be %d, received %d", http.StatusUnauthorized, res.StatusCode) + return nil, nil, errors.New("tapo: wrond status: " + res.Status) } if brand == "tapo" && password == "" {