[#170] checksum: Add examples
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
caa055236b
commit
168b3ee7a4
1 changed files with 34 additions and 0 deletions
34
checksum/example_test.go
Normal file
34
checksum/example_test.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package checksum
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue