diff options
author | axtloss <axtlos@getcryst.al> | 2024-02-28 23:42:26 +0100 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-02-28 23:42:26 +0100 |
commit | 3341bd0e945341528033ec6ebaef4f611f654ebe (patch) | |
tree | f82d4557ac097d08583e56152352cbd5abd335ea /verify/core/crypt.go | |
parent | 91d58f9ae9e9d9adc2e19a0b56d2b9757f6696d6 (diff) | |
download | fsverify-3341bd0e945341528033ec6ebaef4f611f654ebe.tar.gz fsverify-3341bd0e945341528033ec6ebaef4f611f654ebe.tar.bz2 |
restructure repository layout
Diffstat (limited to 'verify/core/crypt.go')
-rw-r--r-- | verify/core/crypt.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/verify/core/crypt.go b/verify/core/crypt.go new file mode 100644 index 0000000..067a0b3 --- /dev/null +++ b/verify/core/crypt.go @@ -0,0 +1,27 @@ +package core + +import ( + "bytes" + "crypto/sha1" + "fmt" + "io" + "strings" +) + +// calculateStringHash calculates the sha1 checksum of a given string a. +func calculateStringHash(a string) (string, error) { + hash := sha1.New() + hash.Write([]byte(a)) + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} + +// CalculateBlockHash calculates the sha1 checksum of a given byte slice b. +func CalculateBlockHash(b []byte) (string, error) { + hash := sha1.New() + if _, err := io.Copy(hash, bytes.NewReader(b)); err != nil { + return "", err + } + hashInBytes := hash.Sum(nil)[:20] + return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil +} |