From b77083448f096f01036d3e53dfddf0aee39bcd8c Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 3 Feb 2024 16:25:55 +0100 Subject: change header signature and add block checksumming --- core/crypt.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/crypt.go') diff --git a/core/crypt.go b/core/crypt.go index 6de70e6..f741b8e 100644 --- a/core/crypt.go +++ b/core/crypt.go @@ -1,25 +1,25 @@ package core import ( + "bytes" "crypto/sha256" "fmt" "io" - "os" "strings" ) func calculateStringHash(a string) (string, error) { hash := sha256.New() hash.Write([]byte(a)) - hashInBytes := hash.Sum(nil)[:20] + hashInBytes := hash.Sum(nil)[:32] return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil } -func calculateFileHash(file *os.File) (string, error) { +func CalculateBlockHash(block []byte) (string, error) { hash := sha256.New() - if _, err := io.Copy(hash, file); err != nil { + if _, err := io.Copy(hash, bytes.NewReader(block)); err != nil { return "", err } - hashInBytes := hash.Sum(nil)[:20] + hashInBytes := hash.Sum(nil)[:32] return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil } -- cgit v1.2.3