summaryrefslogtreecommitdiff
path: root/utils/blake2b-hasher.go
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
commit82d5136c1b03efbb99931884dd75ab1160689ceb (patch)
tree3095f344055c4ad54a8238599839fa0088054fbd /utils/blake2b-hasher.go
parenta3ead3d67520704eda55a74841b00d5766728fab (diff)
Refactoring project - Introducing handlers,models and utils- Updating previous hasher and idgen func + formatting
Diffstat (limited to 'utils/blake2b-hasher.go')
-rw-r--r--utils/blake2b-hasher.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/blake2b-hasher.go b/utils/blake2b-hasher.go
new file mode 100644
index 0000000..38d13a1
--- /dev/null
+++ b/utils/blake2b-hasher.go
@@ -0,0 +1,20 @@
+package utils
+
+import (
+ "fmt"
+ "io"
+
+ "golang.org/x/crypto/blake2b"
+)
+
+func GenerateHash(file io.Reader) (string, error) {
+ //hasher is an instance hash writer provided by the blake2b, nil - no key provided
+ hasher, err := blake2b.New256(nil)
+ if err != nil {
+ return "", err
+ }
+ if _, err := io.Copy(hasher, file); err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("%x", hasher.Sum(nil)), nil
+}