summaryrefslogtreecommitdiffstats
path: root/lib/hex.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-12-05 20:37:33 -0500
committerrsiddharth <s@ricketyspace.net>2020-12-05 20:37:33 -0500
commitea9f4e4e3aeaa78826ee54a52f4ffd273024a3a3 (patch)
treecd7c766709c50b05ddb6aee00053c0fc06f3d8e2 /lib/hex.go
parent425ed8a3a89a829ba456a0d877d3871820a88216 (diff)
lib/hex: add HexStrToBytes
Diffstat (limited to 'lib/hex.go')
-rw-r--r--lib/hex.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/hex.go b/lib/hex.go
index d680a28..e5540ce 100644
--- a/lib/hex.go
+++ b/lib/hex.go
@@ -44,6 +44,25 @@ func HexStrToAsciiStr(h string) string {
return a
}
+// 'h' must be hex encoded string.
+func HexStrToBytes(h string) []byte {
+ lh := len(h)
+
+ if lh < 1 {
+ return []byte{}
+ }
+ if lh == 1 {
+ return []byte{byte(HexCharToDec(h[0]))}
+ }
+
+ bs := make([]byte, 0)
+ for i := 0; i < lh; i += 2 {
+ b := HexCharToDec(h[i])<<4 | HexCharToDec(h[i+1])
+ bs = append(bs, byte(b))
+ }
+ return bs
+}
+
func AsciiStrToHexStr(as string) string {
hs := ""
if len(as) < 1 {