From f1524db2c9d935daabd3b1557caf54fbdd63dde5 Mon Sep 17 00:00:00 2001 From: axtloss Date: Mon, 5 Feb 2024 15:29:21 +0100 Subject: verifysetup storage reader --- verifysetup/core/crypt.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 verifysetup/core/crypt.go (limited to 'verifysetup/core/crypt.go') 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 +} -- cgit v1.2.3