ussd/common/hex.go

32 lines
486 B
Go
Raw Permalink Normal View History

2024-10-30 01:59:59 +01:00
package common
import (
"encoding/hex"
2024-11-02 16:46:46 +01:00
"strings"
2024-10-30 01:59:59 +01:00
)
func NormalizeHex(s string) (string, error) {
if len(s) >= 2 {
if s[:2] == "0x" {
s = s[2:]
}
}
r, err := hex.DecodeString(s)
if err != nil {
return "", err
}
return hex.EncodeToString(r), nil
}
2024-11-02 16:46:46 +01:00
func IsSameHex(left string, right string) bool {
bl, err := NormalizeHex(left)
if err != nil {
return false
}
br, err := NormalizeHex(left)
if err != nil {
return false
}
return strings.Compare(bl, br) == 0
}