2022-04-12 12:42:29 +00:00
|
|
|
package checksum
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-09-08 14:15:08 +00:00
|
|
|
"crypto/rand"
|
2022-04-12 12:42:29 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"fmt"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2022-04-12 12:42:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleCalculate() {
|
|
|
|
payload := []byte{0, 1, 2, 3, 4, 5, 6}
|
|
|
|
var cs Checksum
|
|
|
|
|
|
|
|
Calculate(&cs, SHA256, payload)
|
|
|
|
Calculate(&cs, TZ, payload)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleChecksum_WriteToV2() {
|
|
|
|
var (
|
|
|
|
csRaw [sha256.Size]byte
|
|
|
|
csV2 refs.Checksum
|
|
|
|
cs Checksum
|
|
|
|
)
|
|
|
|
|
|
|
|
rand.Read(csRaw[:])
|
|
|
|
cs.SetSHA256(csRaw)
|
|
|
|
|
|
|
|
cs.WriteToV2(&csV2)
|
|
|
|
|
|
|
|
fmt.Println(bytes.Equal(cs.Value(), csV2.GetSum()))
|
|
|
|
// Output: true
|
|
|
|
}
|