aboutsummaryrefslogtreecommitdiff
path: root/verifysetup/core/crypt.go
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2024-02-05 15:29:21 +0100
committeraxtloss <axtlos@getcryst.al>2024-02-05 15:29:21 +0100
commitf1524db2c9d935daabd3b1557caf54fbdd63dde5 (patch)
tree04dc65245855f5975ab3002e9749ba666ea1af37 /verifysetup/core/crypt.go
parenta215d3358f35e3331b4ce6c7f5a03b4544e04d43 (diff)
downloadfsverify-f1524db2c9d935daabd3b1557caf54fbdd63dde5.tar.gz
fsverify-f1524db2c9d935daabd3b1557caf54fbdd63dde5.tar.bz2
verifysetup storage reader
Diffstat (limited to '')
-rw-r--r--verifysetup/core/crypt.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/verifysetup/core/crypt.go b/verifysetup/core/crypt.go
new file mode 100644
index 0000000..81130a3
--- /dev/null
+++ b/verifysetup/core/crypt.go
@@ -0,0 +1,18 @@
+package core
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "fmt"
+ "io"
+ "strings"
+)
+
+func CalculateBlockHash(block []byte) (string, error) {
+ hash := sha256.New()
+ if _, err := io.Copy(hash, bytes.NewReader(block)); err != nil {
+ return "", err
+ }
+ hashInBytes := hash.Sum(nil)[:32]
+ return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
+}