aboutsummaryrefslogtreecommitdiff
path: root/verify/core/crypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'verify/core/crypt.go')
-rw-r--r--verify/core/crypt.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/verify/core/crypt.go b/verify/core/crypt.go
new file mode 100644
index 0000000..067a0b3
--- /dev/null
+++ b/verify/core/crypt.go
@@ -0,0 +1,27 @@
+package core
+
+import (
+ "bytes"
+ "crypto/sha1"
+ "fmt"
+ "io"
+ "strings"
+)
+
+// calculateStringHash calculates the sha1 checksum of a given string a.
+func calculateStringHash(a string) (string, error) {
+ hash := sha1.New()
+ hash.Write([]byte(a))
+ hashInBytes := hash.Sum(nil)[:20]
+ return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
+}
+
+// CalculateBlockHash calculates the sha1 checksum of a given byte slice b.
+func CalculateBlockHash(b []byte) (string, error) {
+ hash := sha1.New()
+ if _, err := io.Copy(hash, bytes.NewReader(b)); err != nil {
+ return "", err
+ }
+ hashInBytes := hash.Sum(nil)[:20]
+ return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
+}