zhash

package
v0.0.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknown      = errors.New("zhash: unknown hash algorithm")
	ErrNotAvailable = errors.New("zhash: hash function not available")
	ErrNotMatch     = errors.New("zhash: hashed value not match")
)

Functions

func RegisterHash

func RegisterHash(h Hash, f func() hash.Hash)

RegisterHash registers a hash function. It panics ErrUnknown when unknown hash was given.

Types

type Hash

type Hash uint

Hash identifies a 'Non Cryptographic' hash function that is implemented in another package. Note that this identifies NON CRYPTOGRAPHIC hash. Use crypto.Hash for cryptographic hash.

const (
	FNV32           Hash = offset + iota // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	FNV32a                               // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	FNV64                                // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	FNV64a                               // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	FNV128                               // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	FNV128a                              // Non cryptographic. import github.com/aileron-projects/go/zhash/zfnv
	CRC32IEEE                            // Non cryptographic. import github.com/aileron-projects/go/zhash/zcrc32
	CRC32Castagnoli                      // Non cryptographic. import github.com/aileron-projects/go/zhash/zcrc32
	CRC32Koopman                         // Non cryptographic. import github.com/aileron-projects/go/zhash/zcrc32
	CRC64ISO                             // Non cryptographic. import github.com/aileron-projects/go/zhash/zcrc64
	CRC64ECMA                            // Non cryptographic. import github.com/aileron-projects/go/zhash/zcrc64

)

func (Hash) Available

func (h Hash) Available() bool

Available reports whether the given hash algorithm is linked into the binary.

func (Hash) Compare

func (h Hash) Compare(hashed, value []byte) (err error)

Compare compares the hashed value and the non-hashed value. Compare may return following errors:

  • ErrNotMatch: hashed value does not match.
  • ErrNotAvailable: hash function specified by h is not available.
  • Any errors returned from the hash function.

func (Hash) Equal

func (h Hash) Equal(hashed, value []byte) bool

Equal returns if the two hashed value and non-hashed value are equal or not. To know why hashes are not matched, use [Compare] instead.

func (Hash) New

func (h Hash) New() hash.Hash

New returns a new hash instance. It panics with ErrNotAvailable if hash function is not available.

func (Hash) NewFunc

func (h Hash) NewFunc() func() hash.Hash

NewFunc returns a function to generate new hash instances. It panics with ErrNotAvailable if hash function is not available.

func (Hash) Size

func (h Hash) Size() int

Size returns the digest size of the hash. It panics with ErrUnknown when unknown hash was given.

func (Hash) String

func (h Hash) String() string

func (Hash) Sum

func (h Hash) Sum(value []byte) []byte

Sum returns hash sum of the given value. It panics with ErrNotAvailable if hash function is not available.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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