From e181bf2901da8bc433e587092a1835460f5709c2 Mon Sep 17 00:00:00 2001 From: zepatrik Date: Wed, 13 Nov 2024 18:16:29 +0100 Subject: [PATCH] fix: build on 32-bit architectures --- hasherx/hash_comparator.go | 8 ++++---- mapx/type_assert.go | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hasherx/hash_comparator.go b/hasherx/hash_comparator.go index e9abaee2..be2745fe 100644 --- a/hasherx/hash_comparator.go +++ b/hasherx/hash_comparator.go @@ -164,7 +164,7 @@ func decodeArgon2idHash(encodedHash string) (p *Argon2Config, salt, hash []byte, if err != nil { return nil, nil, nil, err } - saltLength := len(salt) + saltLength := uint(len(salt)) if saltLength > math.MaxUint32 { return nil, nil, nil, ErrInvalidHash } @@ -174,7 +174,7 @@ func decodeArgon2idHash(encodedHash string) (p *Argon2Config, salt, hash []byte, if err != nil { return nil, nil, nil, err } - keyLength := len(hash) + keyLength := uint(len(hash)) if keyLength > math.MaxUint32 { return nil, nil, nil, ErrInvalidHash } @@ -207,7 +207,7 @@ func decodePbkdf2Hash(encodedHash string) (p *PBKDF2Config, salt, hash []byte, e if err != nil { return nil, nil, nil, err } - saltLength := len(salt) + saltLength := uint(len(salt)) if saltLength > math.MaxUint32 { return nil, nil, nil, ErrInvalidHash } @@ -217,7 +217,7 @@ func decodePbkdf2Hash(encodedHash string) (p *PBKDF2Config, salt, hash []byte, e if err != nil { return nil, nil, nil, err } - keyLength := len(hash) + keyLength := uint(len(hash)) if keyLength > math.MaxUint32 { return nil, nil, nil, ErrInvalidHash } diff --git a/mapx/type_assert.go b/mapx/type_assert.go index f76de985..5645f3bd 100644 --- a/mapx/type_assert.go +++ b/mapx/type_assert.go @@ -97,10 +97,11 @@ func GetInt64[K comparable](values map[K]any, key K) (int64, error) { case int32: return int64(v), nil case uint: - if v > math.MaxInt64 { + vv := uint64(v) + if vv > math.MaxInt64 { return 0, errors.New("value is out of range") } - return int64(v), nil + return int64(vv), nil case uint32: return int64(v), nil case uint64: