summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-11-03 08:16:08 +0000
committerArne Juul <arnej@yahooinc.com>2022-11-03 08:16:08 +0000
commitbe114c8d0502b31fc5ef5b2514b20646ed6aa698 (patch)
treedda505beeb302e7a1326b5326dfa9d8715893f83 /client
parent37e61132b52f4d198caf37142023c84051253a7f (diff)
add wrapper for simple MD5 hash
Diffstat (limited to 'client')
-rw-r--r--client/go/util/md5.go17
-rw-r--r--client/go/util/md5_test.go13
2 files changed, 30 insertions, 0 deletions
diff --git a/client/go/util/md5.go b/client/go/util/md5.go
new file mode 100644
index 00000000000..84c7d5d5e1d
--- /dev/null
+++ b/client/go/util/md5.go
@@ -0,0 +1,17 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Author: arnej
+
+package util
+
+import (
+ "crypto/md5"
+ "fmt"
+ "io"
+)
+
+func Md5Hex(text string) string {
+ hasher := md5.New()
+ io.WriteString(hasher, text)
+ hash := hasher.Sum(nil)
+ return fmt.Sprintf("%x", hash)
+}
diff --git a/client/go/util/md5_test.go b/client/go/util/md5_test.go
new file mode 100644
index 00000000000..6c9302e18cf
--- /dev/null
+++ b/client/go/util/md5_test.go
@@ -0,0 +1,13 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package util
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestMD5SimpleInputs(t *testing.T) {
+ assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", Md5Hex(""))
+ assert.Equal(t, "4044e8209f286312a68bbb54f8714922", Md5Hex("admin/cluster-controllers/0\n"))
+}