chore: simplify

This commit is contained in:
andig 2026-02-04 09:24:51 +01:00
parent 64b415c36d
commit f3de6d63f2
4 changed files with 8 additions and 13 deletions

View file

@ -181,9 +181,8 @@ func createChallengeResponse(challenge, pass string) (string, error) {
return "", err
}
hash := md5.New()
hash.Write([]byte(utf16le))
hash := md5.Sum([]byte(utf16le))
md5hash := hex.EncodeToString(hash[:])
md5hash := hex.EncodeToString(hash.Sum(nil))
return challenge + "-" + md5hash, nil
}

View file

@ -30,11 +30,9 @@ func NewIdentity(log *util.Logger) *Identity {
}
func (v *Identity) Login(user, password string) (int64, error) {
hash := md5.New()
hash.Write([]byte(password))
hash := md5.Sum([]byte(password))
v.hash = hex.EncodeToString(hash[:])
v.user = user
v.hash = hex.EncodeToString(hash.Sum(nil))
var res User

View file

@ -69,9 +69,8 @@ func NewNiuFromConfig(other map[string]any) (api.Vehicle, error) {
// login implements the Niu oauth2 api
func (v *Niu) login() error {
hash := md5.New()
hash.Write([]byte(v.password))
md5hash := hex.EncodeToString(hash.Sum(nil))
hash := md5.Sum([]byte(v.password))
md5hash := hex.EncodeToString(hash[:])
data := url.Values{
"account": {v.user},

View file

@ -25,9 +25,8 @@ func createSignature(method, path string, params url.Values, body io.Reader) (st
return "", "", "", err
}
hash := md5.New()
hash.Write(bytes)
md5Hash = base64.StdEncoding.EncodeToString(hash.Sum(nil))
hash := md5.Sum(bytes)
md5Hash = base64.StdEncoding.EncodeToString(hash[:])
}
payload := fmt.Sprintf(`application/json;responseformat=3