hash

package
v0.2012.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 8 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 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) 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) 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