diff options
author | axtloss <axtlos@getcryst.al> | 2024-02-03 16:25:55 +0100 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-02-03 16:25:55 +0100 |
commit | b77083448f096f01036d3e53dfddf0aee39bcd8c (patch) | |
tree | 97bcf591bb986369343a89325ae1fe371b1b54ba /core/crypt.go | |
parent | 57e3add2f90ad1900be2e9d1cd8019f6aa5ad440 (diff) | |
download | fsverify-b77083448f096f01036d3e53dfddf0aee39bcd8c.tar.gz fsverify-b77083448f096f01036d3e53dfddf0aee39bcd8c.tar.bz2 |
change header signature and add block checksumming
Diffstat (limited to 'core/crypt.go')
-rw-r--r-- | core/crypt.go | 10 |
1 files changed, 5 insertions, 5 deletions
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 } |