hash

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright (c) 2020 Blockwatch Data Inc. Author: alex@blockwatch.cc

Index

Constants

View Source
const HashSize = 32

HashSize of array used to store hashes. See Hash.

View Source
const MaxHashStringSize = HashSize * 2

MaxHashStringSize is the maximum length of a Hash hash string.

Variables

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

Functions

This section is empty.

Types

type Hash

type Hash [HashSize]byte

Hash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.

func NewHash

func NewHash(buf []byte) (Hash, error)

NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func NewHashFromStr

func NewHashFromStr(hash string) (Hash, error)

NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (Hash) CloneBytes

func (hash Hash) CloneBytes() []byte

CloneBytes returns a copy of the bytes which represent the hash as a byte slice.

NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.

func (Hash) IsEqual

func (hash Hash) IsEqual(target Hash) bool

IsEqual returns true if target is the same as hash.

func (Hash) IsValid

func (hash Hash) IsValid() bool

func (Hash) MarshalBinary

func (hash Hash) MarshalBinary() ([]byte, error)

func (Hash) MarshalText

func (hash Hash) MarshalText() ([]byte, error)

func (*Hash) SetBytes

func (hash *Hash) SetBytes(buf []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (Hash) String

func (hash Hash) String() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

func (*Hash) UnmarshalBinary

func (hash *Hash) UnmarshalBinary(buf []byte) error

func (*Hash) UnmarshalText

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

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

type InlineFNV64a

type InlineFNV64a uint64

InlineFNV64a is an alloc-free port of the standard library's fnv64a. See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

func NewInlineFNV64a

func NewInlineFNV64a() InlineFNV64a

NewInlineFNV64a returns a new instance of InlineFNV64a.

func (*InlineFNV64a) Sum

func (s *InlineFNV64a) Sum() []byte

func (*InlineFNV64a) Sum64

func (s *InlineFNV64a) Sum64() uint64

Sum64 returns the uint64 of the current resulting hash.

func (*InlineFNV64a) Write

func (s *InlineFNV64a) Write(data []byte) error

Write adds data to the running hash.

func (*InlineFNV64a) WriteByte

func (s *InlineFNV64a) WriteByte(b byte) error

Write adds a single byte b to the running hash.

func (*InlineFNV64a) WriteString

func (s *InlineFNV64a) WriteString(data string) error

Write adds data to the running hash.

Directories

Path Synopsis
Package blake256 implements BLAKE-256 and BLAKE-224 hash functions (SHA-3 candidate).
Package blake256 implements BLAKE-256 and BLAKE-224 hash functions (SHA-3 candidate).
Package murmur3 implements Austin Appleby's non-cryptographic MurmurHash3.
Package murmur3 implements Austin Appleby's non-cryptographic MurmurHash3.
Package xxHash32 implements the very fast xxHash hashing algorithm (32 bits version).
Package xxHash32 implements the very fast xxHash hashing algorithm (32 bits version).
Package xxhash implements the 64-bit variant of xxHash (XXH64) as described at http://cyan4973.github.io/xxHash/.
Package xxhash implements the 64-bit variant of xxHash (XXH64) as described at http://cyan4973.github.io/xxHash/.

Jump to

Keyboard shortcuts

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