diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/go/util/md5.go | 17 | ||||
-rw-r--r-- | client/go/util/md5_test.go | 13 |
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")) +} |