Documentation ¶
Overview ¶
Package chainhash provides abstracted hash functionality.
This package provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
Index ¶
Constants ¶
const HashSize = 32
HashSize of array used to store hashes. See Hash. NOTE(cedric): If you change this value, you'll also need to update the GenesisHash field of the type wire.MsgVersion type to match.
const MaxHashStringSize = HashSize * 2
MaxHashStringSize is the maximum length of a Hash hash string.
Variables ¶
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 ¶
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func DoubleHashB ¶
DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
Types ¶
type Hash ¶
Hash is used in several of the soter messages and common structures. It typically represents the double sha256 of data.
func DoubleHashH ¶
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
func NewHash ¶
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 ¶
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 ¶
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) CloneBytes32 ¶
CloneBytes32 returns a copy of bytes representing the hash, as [HashSize]byte slice.
This is used when creating version messages, for the GenesisHash field. [HashSize]byte instead of chainhash.Hash is used in version messages to avoid a circular import dependency between wire and chaincfg packages.