forked from TrueCloudLab/frostfs-sdk-go
Evgenii Stratonikov
e45647de3c
Slower, but more correct. ``` name old time/op new time/op delta Transformer/small-8 72.4µs ± 8% 74.8µs ±11% ~ (p=0.278 n=9+10) Transformer/big-8 1.31s ± 8% 1.38s ±11% +5.50% (p=0.035 n=10+10) name old alloc/op new alloc/op delta Transformer/small-8 7.39kB ± 0% 7.69kB ± 0% +4.04% (p=0.000 n=10+10) Transformer/big-8 46.9kB ± 0% 49.2kB ± 0% +4.87% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Transformer/small-8 94.6 ± 1% 102.0 ± 0% +7.82% (p=0.000 n=10+9) Transformer/big-8 560 ± 0% 620 ± 1% +10.66% (p=0.000 n=10+10) ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
38 lines
731 B
Go
38 lines
731 B
Go
package transformer
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"hash"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/checksum"
|
|
objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object"
|
|
"github.com/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")
|
|
}
|
|
}
|