Documentation ¶
Overview ¶
Package checksum provides primitives to work with checksums.
Checksum is a basic type of data checksums. For example, calculating checksums:
// retrieving any payload for hashing var sha256Sum Checksum Calculate(&sha256Sum, SHA256, payload) // sha256Sum contains SHA256 hash of the payload var tzSum Checksum Calculate(&tzSum, TZ, payload) // tzSum contains TZ hash of the payload
Using package types in an application is recommended to potentially work with different protocol versions with which these types are compatible.
Index ¶
Examples ¶
Constants ¶
const ( // Unknown is an undefined checksum type. Unknown Type = Type(refs.UnknownChecksum) // SHA256 is a SHA256 checksum type. SHA256 = Type(refs.SHA256) // TZ is a Tillich-Zémor checksum type. TZ = Type(refs.TillichZemor) )
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 cs Checksum Calculate(&cs, SHA256, payload) Calculate(&cs, TZ, payload)
Output:
Types ¶
type Checksum ¶
Checksum represents checksum of some digital data.
Checksum is mutually compatible with git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/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
func (*Checksum) ReadFromV2 ¶
ReadFromV2 reads Checksum from the refs.Checksum message. Checks if the message conforms to FrostFS 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.
func (Checksum) Value ¶
Value returns checksum bytes. Return value MUST NOT be mutated.
Zero Checksum has nil sum.
See also SetTillichZemor and SetSHA256.
func (Checksum) WriteToV2 ¶
WriteToV2 writes Checksum to the refs.Checksum message. The message must not be nil.
See also ReadFromV2.
Example ¶
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