checksum

package
v0.0.0-...-5e759bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 6 Imported by: 5

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

This section is empty.

Variables

This section is empty.

Functions

func Calculate

func Calculate(c *Checksum, t Type, v []byte)

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

type Checksum refs.Checksum

Checksum represents checksum of some digital data.

Checksum is mutually compatible with github.com/TrueCloudLab/frostfs-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

func (*Checksum) ReadFromV2

func (c *Checksum) ReadFromV2(m refs.Checksum) error

ReadFromV2 reads Checksum from the refs.Checksum message. Checks if the message conforms to FrostFS API V2 protocol.

See also WriteToV2.

func (*Checksum) SetSHA256

func (c *Checksum) SetSHA256(v [sha256.Size]byte)

SetSHA256 sets checksum to SHA256 hash.

See also Calculate.

func (*Checksum) SetTillichZemor

func (c *Checksum) SetTillichZemor(v [tz.Size]byte)

SetTillichZemor sets checksum to Tillich-Zémor hash.

See also Calculate.

func (Checksum) String

func (c Checksum) String() string

String implements fmt.Stringer.

String is designed to be human-readable, and its format MAY differ between SDK versions.

func (Checksum) Type

func (c Checksum) Type() Type

Type returns checksum type.

Zero Checksum has Unknown checksum type.

See also SetTillichZemor and SetSHA256.

func (Checksum) Value

func (c Checksum) Value() []byte

Value returns checksum bytes. Return value MUST NOT be mutated.

Zero Checksum has nil sum.

See also SetTillichZemor and SetSHA256.

func (Checksum) WriteToV2

func (c Checksum) WriteToV2(m *refs.Checksum)

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

type Type

type Type uint8

Type represents the enumeration of checksum types.

const (
	// Unknown is an undefined checksum type.
	Unknown Type = iota

	// SHA256 is a SHA256 checksum type.
	SHA256

	// TZ is a Tillich-Zémor checksum type.
	TZ
)

func (Type) String

func (m Type) String() string

String implements fmt.Stringer.

String is designed to be human-readable, and its format MAY differ between SDK versions.

Directories

Path Synopsis
Package checksumtest provides functions for convenient testing of checksum package API.
Package checksumtest provides functions for convenient testing of checksum package API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL