|
|
@ -43,11 +43,9 @@ func ToHexArray(b [][]byte) []string { |
|
|
|
// FromHex returns the bytes represented by the hexadecimal string s.
|
|
|
|
// FromHex returns the bytes represented by the hexadecimal string s.
|
|
|
|
// s may be prefixed with "0x".
|
|
|
|
// s may be prefixed with "0x".
|
|
|
|
func FromHex(s string) []byte { |
|
|
|
func FromHex(s string) []byte { |
|
|
|
if len(s) > 1 { |
|
|
|
if has0xPrefix(s) { |
|
|
|
if s[0:2] == "0x" || s[0:2] == "0X" { |
|
|
|
|
|
|
|
s = s[2:] |
|
|
|
s = s[2:] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if len(s)%2 == 1 { |
|
|
|
if len(s)%2 == 1 { |
|
|
|
s = "0" + s |
|
|
|
s = "0" + s |
|
|
|
} |
|
|
|
} |
|
|
@ -65,8 +63,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// hasHexPrefix validates str begins with '0x' or '0X'.
|
|
|
|
// has0xPrefix validates str begins with '0x' or '0X'.
|
|
|
|
func hasHexPrefix(str string) bool { |
|
|
|
func has0xPrefix(str string) bool { |
|
|
|
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') |
|
|
|
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|