hash

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHash = sha256.New

DefaultHash is a default hashing algorithm - "sha256".

Functions

This section is empty.

Types

type Digest

type Digest struct {
	hash.Hash
}

Digest represents the partial evaluation of a checksum.

func New

func New() *Digest

New returns new hash from a given integer.

func (*Digest) Sum

func (d *Digest) Sum(b []byte) Hash

Sum appends the current checksum to b and returns the Hash.

func (*Digest) WriteObject

func (d *Digest) WriteObject(v interface{}) (int, error)

WriteObject adds an interface data to the running hash. It never retruns an error.

type Hash

type Hash []byte

A Hash is a type for representing common hash.

func Decode

func Decode(h string) (Hash, error)

Decode decodes the base58 encoded hash. It returns error when a hash isn't base58,encoded or hash length is invalid.

func DecodeFromBytes added in v0.18.0

func DecodeFromBytes(data []byte) (Hash, error)

DecodeFromBytes decodes hash and checks it length. It returns empty hash on nil slice of bytes.

func Dump

func Dump(v interface{}) Hash

Dump takes an interface and returns its hash representation.

func Int

func Int(h int) Hash

Int returns a new hash from a given integer. NOTE: This method is for tests purpose only.

func Random

func Random() (Hash, error)

Random returns a new random hash.

func (Hash) Equal

func (h Hash) Equal(h1 Hash) bool

Equal returns a boolean reporting whether h and h1 are the same hashes.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero reports whethere h represents empty hash.

func (Hash) MarshalJSON added in v0.14.0

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON mashals hash into encoded json string.

func (Hash) String

func (h Hash) String() string

String returns the hash hex representation.

func (*Hash) UnmarshalJSON added in v0.14.0

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

UnmarshalJSON unmashals hex encoded json string into hash.

func (Hash) Valid added in v0.17.0

func (h Hash) Valid() bool

Valid checks if service hash length is valid. It treats empty hash as valid one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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