diff options
author | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-07-01 22:16:05 +0800 |
---|---|---|
committer | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-07-01 22:16:05 +0800 |
commit | 29f613ef84ed39ccc1929dd1069f3576ade889f1 (patch) | |
tree | 0c12e6fe9e0214989401bb47a6d4503081fd47bc /ethutil/bytes.go | |
parent | 550407b0ec78b7026737d1abe28127da8c0c9063 (diff) | |
parent | ff5703fd9b089de67811af61de05637c62dc7a2c (diff) | |
download | go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar.gz go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar.bz2 go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar.lz go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar.xz go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.tar.zst go-tangerine-29f613ef84ed39ccc1929dd1069f3576ade889f1.zip |
Merge pull request #28 from ethersphere/feature/keys
Feature/keys
Diffstat (limited to 'ethutil/bytes.go')
-rw-r--r-- | ethutil/bytes.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 5e3ee4a6f..c2817946b 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -3,6 +3,7 @@ package ethutil import ( "bytes" "encoding/binary" + "encoding/hex" "fmt" "math/big" "strings" @@ -91,9 +92,18 @@ func IsHex(str string) bool { return l >= 4 && l%2 == 0 && str[0:2] == "0x" } +func Bytes2Hex(d []byte) string { + return hex.EncodeToString(d) +} + +func Hex2Bytes(str string) []byte { + h, _ := hex.DecodeString(str) + return h +} + func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { - ret = FromHex(str[2:]) + ret = Hex2Bytes(str[2:]) } else { ret = cb(str) } @@ -110,7 +120,7 @@ func FormatData(data string) []byte { if data[0:1] == "\"" && data[len(data)-1:] == "\"" { d.SetBytes([]byte(data[1 : len(data)-1])) } else if len(data) > 1 && data[:2] == "0x" { - d.SetBytes(FromHex(data[2:])) + d.SetBytes(Hex2Bytes(data[2:])) } else { d.SetString(data, 0) } |