{"modulePath":"github.com/weiwolves/pkg","version":"v0.0.0-20200322065615-581c8d33cff6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package hashpool\n\nPackage hashpool implements a pool for reusable and registered hash.Hash types.\n\n## Functions\n\n```go\nfunc Deregister(name string)\n```\nDeregister removes a previously registered hash and all its HMAC hashes. Safe for concurrent use.\n\n```go\nfunc Register(name string, hh func() hash.Hash) error\n```\nRegister registers a new hash function in the global map. Returns an error behaviour of AlreadyExists if you try to register the same name twice. Safe for concurrent use.\n\n## Types\n\n```go\ntype Hash64Mock struct {\n\thash.Hash\n}\n```\nHash64Mock allows to use a hash.Hash as an argument to the Hash64 Tank.\n\n```go\nfunc (d Hash64Mock) Sum64() uint64\n```\nSum64 returns always zero.\n\n```go\ntype Tank struct {\n\n\t// BufferSize used in SumBase64() to append the hashed data to. Default 1024.\n\tBufferSize int\n\t// contains filtered or unexported fields\n}\n```\nTank implements a sync.Pool for hash.Hash\n\n```go\nfunc FromRegistry(name string) (Tank, error)\n```\nFromRegistry returns a hash pool for the given name, otherwise a NotFound error behaviour. Safe for concurrent use.\n\n```go\nfunc FromRegistryHMAC(name string, key []byte) (Tank, error)\n```\nFromRegisterHMAC 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.\n\n```go\nfunc MustFromRegistry(name string) Tank\n```\nMustFromRegistry same as FromRegistry but panics when the name does not exists in the internal map. Safe for concurrent use.\n\n```go\nfunc New(h func() hash.Hash) Tank\n```\nNew instantiates a new hash pool with a custom pre-allocated hash.Hash.\n\n```go\nfunc New64(h func() hash.Hash64) Tank\n```\nNew64 instantiates a new hash pool with a custom pre-allocated hash.Hash64.\n\n```go\nfunc (t Tank) Equal(data []byte, mac []byte) bool\n```\nEqual hashes data and compares it with MAC for equality without leaking timing information.\n\n```go\nfunc (t Tank) EqualPairs(dataPairs ...[]byte) bool\n```\nEqualPairs 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.\n\n```go\nfunc (t Tank) EqualReader(r io.Reader, mac []byte) (bool, error)\n```\nEqualReader 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.\n\n```go\nfunc (t Tank) Get() hash.Hash64\n```\nGet returns type safe a hash.\n\n```go\nfunc (t Tank) Put(h hash.Hash64)\n```\nPut empties the hash and returns it back to the pool.\n\n\thp := New(fnv.New64)\n\thsh := hp.Get()\n\tdefer hp.Put(hsh)\n\t// your code\n\treturn hsh.Sum([]byte{})\n\n```go\nfunc (t Tank) Sum(data, appendTo []byte) (ret []byte)\n```\nSum calculates the hash of data and appends the current hash to appendTo and returns the resulting slice. It does not change the underlying hash state. It fetches a hash from the pool and returns it after writing the sum. No need to call Get() and Put().\n\n```go\nfunc (t Tank) SumHex(data []byte) string\n```\nSumHex writes the hashed data into the hex encoder.\n\n","path":"github.com/weiwolves/pkg/util/hashpool","name":"hashpool","synopsis":"Package hashpool implements a pool for reusable and registered hash.Hash types.","isRedistributable":true}
