Documentation ¶
Overview ¶
Package hash implements a cryptographic hash over arbitrary binary data.
Index ¶
- Constants
- Variables
- type Builder
- type Hash
- func (h *Hash) Empty()
- func (h *Hash) Equal(cmp *Hash) bool
- func (h *Hash) From(v interface{})
- func (h *Hash) FromBytes(data ...[]byte)
- func (h Hash) Hex() string
- func (h *Hash) IsEmpty() bool
- func (h *Hash) MarshalBinary() (data []byte, err error)
- func (h *Hash) MarshalHex() ([]byte, error)
- func (h Hash) MarshalText() (data []byte, err error)
- func (h Hash) String() string
- func (h Hash) Truncate(n int) ([]byte, error)
- func (h *Hash) UnmarshalBinary(data []byte) error
- func (h *Hash) UnmarshalHex(text string) error
- func (h *Hash) UnmarshalText(text []byte) error
Constants ¶
const Size = 32
Size is the size of the cryptographic hash in bytes.
Variables ¶
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.
type Hash ¶
Hash is a cryptographic hash over arbitrary binary data.
func LoadFromHexBytes ¶ added in v0.2103.0
LoadFromHexBytes creates a new hash by loading it from the given CometBFT HexBytes byte array.
func NewFrom ¶
func NewFrom(v interface{}) (h Hash)
NewFrom creates a new hash by hashing the CBOR representation of the given type.
func NewFromBytes ¶
NewFromBytes creates a new hash by hashing the provided byte string(s).
func NewFromReader ¶ added in v0.2403.0
NewFromReader creates a new hash by hashing data from the provided reader until EOF.
func (*Hash) Empty ¶
func (h *Hash) Empty()
Empty sets the hash to that of an empty (0 byte) string.
func (*Hash) From ¶
func (h *Hash) From(v interface{})
From sets the hash to that of an arbitrary CBOR serializeable interface.
func (*Hash) MarshalBinary ¶
MarshalBinary encodes a hash into binary form.
func (*Hash) MarshalHex ¶ added in v0.2103.0
MarshalHex encodes a Hash into a hexadecimal form.
func (Hash) MarshalText ¶
MarshalText encodes a Hash into text form.
func (*Hash) UnmarshalBinary ¶
UnmarshalBinary decodes a binary marshaled hash.
func (*Hash) UnmarshalHex ¶
UnmarshalHex deserializes a hexadecimal text string into the given type.
func (*Hash) UnmarshalText ¶
UnmarshalText decodes a text marshaled Hash.