Documentation ¶
Overview ¶
Package hashpool implements a pool for reusable and registered hash.Hash types.
Index ¶
- func Deregister(name string)
- func Register(name string, hh func() hash.Hash) error
- type Hash64Mock
- type Tank
- func (t Tank) Equal(data []byte, mac []byte) bool
- func (t Tank) EqualPairs(dataPairs ...[]byte) bool
- func (t Tank) EqualReader(r io.Reader, mac []byte) (bool, error)
- func (t Tank) Get() hash.Hash64
- func (t Tank) Put(h hash.Hash64)
- func (t Tank) Sum(data, appendTo []byte) []byte
- func (t Tank) SumHex(data []byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deregister ¶
func Deregister(name string)
Deregister removes a previously registered hash and all its HMAC hashes. Safe for concurrent use.
Types ¶
type Hash64Mock ¶
Hash64Mock allows to use a hash.Hash as an argument to the Hash64 Tank.
type Tank ¶
type Tank struct { // BufferSize used in SumBase64() to append the hashed data to. Default 1024. BufferSize int // contains filtered or unexported fields }
Tank implements a sync.Pool for hash.Hash
func FromRegistry ¶
FromRegistry returns a hash pool for the given name, otherwise a NotFound error behaviour. Safe for concurrent use.
func FromRegistryHMAC ¶
FromRegisterHMAC returns a pool with a HMAC hash from a previously registered hash. Key aka. password. The newly generated hash pool will be internally cached with the identifier of name plus key.
func MustFromRegistry ¶
MustFromRegistry same as FromRegistry but panics when the name does not exists in the internal map. Safe for concurrent use.
func (Tank) Equal ¶
Equal hashes data and compares it with MAC for equality without leaking timing information.
func (Tank) EqualPairs ¶
EqualPairs compares data pairs for equality via constant time. Returns true only if all pairs are equal and one data item length is at least greater than zero. Use case: Compare username and password from database with a username and password from an outside input form.
func (Tank) EqualReader ¶
EqualReader hashes io.Reader and compares it with MAC for equality without leaking timing information. The internal buffer to read into data from io.Reader can be adjusted via field BufferSize.
func (Tank) Put ¶
Put empties the hash and returns it back to the pool.
hp := New(fnv.New64) hsh := hp.Get() defer hp.Put(hsh) // your code return hsh.Sum([]byte{})