aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/bytes.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-02 02:08:48 +0800
committerobscuren <geffobscura@gmail.com>2014-07-02 02:08:48 +0800
commit28ef7d228c4e8e24315eb585e4e0d03a4c652ccb (patch)
tree32829303dc232cb78f2a5b1dc59ee756e3896eb1 /ethutil/bytes.go
parent6151ae7db5251436e9ece190eb3569d4aa882671 (diff)
downloadgo-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar.gz
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar.bz2
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar.lz
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar.xz
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.tar.zst
go-tangerine-28ef7d228c4e8e24315eb585e4e0d03a4c652ccb.zip
Added Left and Right padding utility functions
Diffstat (limited to 'ethutil/bytes.go')
-rw-r--r--ethutil/bytes.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index c2817946b..5737a75c9 100644
--- a/ethutil/bytes.go
+++ b/ethutil/bytes.go
@@ -118,7 +118,8 @@ func FormatData(data string) []byte {
// Simple stupid
d := new(big.Int)
if data[0:1] == "\"" && data[len(data)-1:] == "\"" {
- d.SetBytes([]byte(data[1 : len(data)-1]))
+ return RightPadBytes([]byte(data), 32)
+ //d.SetBytes([]byte(data[1 : len(data)-1]))
} else if len(data) > 1 && data[:2] == "0x" {
d.SetBytes(Hex2Bytes(data[2:]))
} else {
@@ -127,3 +128,25 @@ func FormatData(data string) []byte {
return BigToBytes(d, 256)
}
+
+func LeftPadBytes(slice []byte, l int) []byte {
+ if l <= len(slice) {
+ return slice
+ }
+
+ padded := make([]byte, l)
+ copy(padded[0:len(slice)], slice)
+
+ return padded
+}
+
+func RightPadBytes(slice []byte, l int) []byte {
+ if l <= len(slice) {
+ return slice
+ }
+
+ padded := make([]byte, l)
+ copy(padded[l-len(slice):], slice)
+
+ return padded
+}