frostfs-sdk-go/object/transformer/hasher.go

39 lines
749 B
Go
Raw Permalink Normal View History

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")
}
}