Code refactoring for tapo source
This commit is contained in:
+5
-4
@@ -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 == "" {
|
||||
|
||||
Reference in New Issue
Block a user