Documentation ¶
Overview ¶
Package checksum provides primitives to work with checksums.
Checksum is a basic type of data checksums.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Calculate ¶
Calculate calculates checksum and sets it to the passed checksum. Checksum must not be nil.
Does nothing if the passed type is not one of the:
- SHA256;
- TZ.
Does not mutate the passed value.
See also SetSHA256, SetTillichZemor.
Example ¶
payload := []byte{0, 1, 2, 3, 4, 5, 6} var checksum Checksum // checksum contains SHA256 hash of the payload Calculate(&checksum, SHA256, payload) // checksum contains TZ hash of the payload Calculate(&checksum, TZ, payload)
Output:
Types ¶
type Checksum ¶
Checksum represents checksum of some digital data.
Checksum is mutually compatible with github.com/epicchainlabs/epicchain-api-go/v2/refs.Checksum message. See ReadFromV2 / WriteToV2 methods.
Instances can be created using built-in var declaration.
Note that direct typecast is not safe and may result in loss of compatibility:
_ = Checksum(refs.Checksum{}) // not recommended
Example (Marshalling) ¶
Instances can be also used to process NeoFS API V2 protocol messages with [https://github.com/nspcc-dev/neofs-api] package.
var ( csRaw [sha256.Size]byte csV2 refs.Checksum cs Checksum ) //nolint:staticcheck rand.Read(csRaw[:]) cs.SetSHA256(csRaw) // On the client side. cs.WriteToV2(&csV2) fmt.Println(bytes.Equal(cs.Value(), csV2.GetSum())) // Example output: true // *send message* // On the server side. _ = cs.ReadFromV2(csV2)
Output:
func (*Checksum) ReadFromV2 ¶
ReadFromV2 reads Checksum from the refs.Checksum message. Checks if the message conforms to NeoFS API V2 protocol.
See also WriteToV2.
func (*Checksum) SetTillichZemor ¶
SetTillichZemor sets checksum to Tillich-Zémor hash.
See also Calculate.
func (Checksum) String ¶
String implements fmt.Stringer.
String is designed to be human-readable, and its format MAY differ between SDK versions.
func (Checksum) Type ¶
Type returns checksum type.
Zero Checksum has Unknown checksum type.
See also SetTillichZemor and SetSHA256.