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 return "", err
} }
hash := md5.New() hash := md5.Sum([]byte(utf16le))
hash.Write([]byte(utf16le)) md5hash := hex.EncodeToString(hash[:])
md5hash := hex.EncodeToString(hash.Sum(nil))
return challenge + "-" + md5hash, 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) { func (v *Identity) Login(user, password string) (int64, error) {
hash := md5.New() hash := md5.Sum([]byte(password))
hash.Write([]byte(password)) v.hash = hex.EncodeToString(hash[:])
v.user = user v.user = user
v.hash = hex.EncodeToString(hash.Sum(nil))
var res User var res User

View file

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

View file

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