diff options
author | axtloss <axtlos@getcryst.al> | 2024-01-27 19:07:09 +0100 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-01-27 19:07:09 +0100 |
commit | 158e9d6eb8a74bc6ce3c3f2a9709de081568dc02 (patch) | |
tree | 607a25db5c5764fe7f10a746aee1a4e9420e8d81 /core/crypt.go | |
parent | 1b50046a214d81fe98c94a1220f7cbc1eeac669b (diff) | |
download | fsverify-158e9d6eb8a74bc6ce3c3f2a9709de081568dc02.tar.gz fsverify-158e9d6eb8a74bc6ce3c3f2a9709de081568dc02.tar.bz2 |
Add go project
Signed-off-by: axtloss <axtlos@getcryst.al>
Diffstat (limited to 'core/crypt.go')
-rw-r--r-- | core/crypt.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/crypt.go b/core/crypt.go new file mode 100644 index 0000000..6de70e6 --- /dev/null +++ b/core/crypt.go @@ -0,0 +1,25 @@ +package core + +import ( + "crypto/sha256" + "fmt" + "io" + "os" + "strings" +) + +func calculateStringHash(a string) (string, error) { + hash := sha256.New() + hash.Write([]byte(a)) + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} + +func calculateFileHash(file *os.File) (string, error) { + hash := sha256.New() + if _, err := io.Copy(hash, file); err != nil { + return "", err + } + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} |