frostfs-sdk-go/object/transformer/hasher.go
Denis Kirillov d589d51509 [#19] transformer: Fix dependencies
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-03-16 09:51:03 +03:00

38 lines
749 B
Go

package transformer
import (
"crypto/sha256"
"hash"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"git.frostfs.info/TrueCloudLab/tzhash/tz"
)
type payloadChecksumHasher struct {
hasher hash.Hash
typ checksum.Type
}
func (h payloadChecksumHasher) writeChecksum(obj *objectSDK.Object) {
switch h.typ {
case checksum.SHA256:
csSHA := [sha256.Size]byte{}
h.hasher.Sum(csSHA[:0])
var cs checksum.Checksum
cs.SetSHA256(csSHA)
obj.SetPayloadChecksum(cs)
case checksum.TZ:
csTZ := [tz.Size]byte{}
h.hasher.Sum(csTZ[:0])
var cs checksum.Checksum
cs.SetTillichZemor(csTZ)
obj.SetPayloadHomomorphicHash(cs)
default:
panic("unreachable")
}
}