aboutsummaryrefslogtreecommitdiff
path: root/core/crypt.go
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2024-02-03 16:25:55 +0100
committeraxtloss <axtlos@getcryst.al>2024-02-03 16:25:55 +0100
commitb77083448f096f01036d3e53dfddf0aee39bcd8c (patch)
tree97bcf591bb986369343a89325ae1fe371b1b54ba /core/crypt.go
parent57e3add2f90ad1900be2e9d1cd8019f6aa5ad440 (diff)
downloadfsverify-b77083448f096f01036d3e53dfddf0aee39bcd8c.tar.gz
fsverify-b77083448f096f01036d3e53dfddf0aee39bcd8c.tar.bz2
change header signature and add block checksumming
Diffstat (limited to '')
-rw-r--r--core/crypt.go10
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
}