From 168b3ee7a4798e13e0eae65e6886849d65a0cf34 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 12 Apr 2022 15:42:29 +0300 Subject: [PATCH] [#170] checksum: Add examples Signed-off-by: Pavel Karpy --- checksum/example_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 checksum/example_test.go diff --git a/checksum/example_test.go b/checksum/example_test.go new file mode 100644 index 0000000..42239f2 --- /dev/null +++ b/checksum/example_test.go @@ -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 +}