hash

package
v0.2103.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 9 Imported by: 44

Documentation

Overview

Package hash implements a cryptographic hash over arbitrary binary data.

Index

Constants

View Source
const Size = 32

Size is the size of the cryptographic hash in bytes.

Variables

View Source
var (
	// ErrMalformed is the error returned when a hash is malformed.
	ErrMalformed = errors.New("hash: malformed hash")
	// ErrTruncateSize is the error returned when trying to truncate a hash to an invalid size.
	ErrTruncateSize = errors.New("hash: invalid truncate size")
)

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a hash builder that can be used to compute hashes iteratively.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new hash builder.

func (*Builder) Build

func (b *Builder) Build() (h Hash)

Build returns the current hash. It does not change the underlying hash state.

func (*Builder) Write

func (b *Builder) Write(p []byte) (int, error)

Write adds more data to the running hash. It never returns an error.

type Hash

type Hash [Size]byte

Hash is a cryptographic hash over arbitrary binary data.

func LoadFromHexBytes added in v0.2103.0

func LoadFromHexBytes(data tmbytes.HexBytes) (h Hash)

LoadFromHexBytes creates a new hash by loading it from the given Tendermint HexBytes byte array.

func NewFrom

func NewFrom(v interface{}) (h Hash)

NewFrom creates a new hash by hashing the CBOR representation of the given type.

func NewFromBytes

func NewFromBytes(data ...[]byte) (h Hash)

NewFromBytes creates a new hash by hashing the provided byte string(s).

func (*Hash) Empty

func (h *Hash) Empty()

Empty sets the hash to that of an empty (0 byte) string.

func (*Hash) Equal

func (h *Hash) Equal(cmp *Hash) bool

Equal compares vs another hash for equality.

func (*Hash) From

func (h *Hash) From(v interface{})

From sets the hash to that of an arbitrary CBOR serializeable interface.

func (*Hash) FromBytes

func (h *Hash) FromBytes(data ...[]byte)

FromBytes sets the hash to that of an arbitrary byte string.

func (Hash) Hex added in v0.2103.0

func (h Hash) Hex() string

Hex returns the hex-encoded representation of a hash.

func (*Hash) IsEmpty

func (h *Hash) IsEmpty() bool

IsEmpty returns true iff the hash is that of an empty (0 byte) string.

func (*Hash) MarshalBinary

func (h *Hash) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a hash into binary form.

func (*Hash) MarshalHex added in v0.2103.0

func (h *Hash) MarshalHex() ([]byte, error)

MarshalHex encodes a Hash into a hexadecimal form.

func (Hash) MarshalText

func (h Hash) MarshalText() (data []byte, err error)

MarshalText encodes a Hash into text form.

func (Hash) String

func (h Hash) String() string

String returns the string representation of a hash.

func (Hash) Truncate

func (h Hash) Truncate(n int) ([]byte, error)

Truncate returns the first n bytes of a hash.

func (*Hash) UnmarshalBinary

func (h *Hash) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a binary marshaled hash.

func (*Hash) UnmarshalHex

func (h *Hash) UnmarshalHex(text string) error

UnmarshalHex deserializes a hexadecimal text string into the given type.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(text []byte) error

UnmarshalText decodes a text marshaled Hash.

Jump to

Keyboard shortcuts

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