github.com/onflow/flow-go/crypto@v0.24.8/hash/hash.go (about) 1 package hash 2 3 import ( 4 "bytes" 5 "fmt" 6 "io" 7 ) 8 9 // Hash is the hash algorithms output types 10 type Hash []byte 11 12 // Equal checks if a hash is equal to a given hash 13 func (h Hash) Equal(input Hash) bool { 14 return bytes.Equal(h, input) 15 } 16 17 // Hex returns the hex string representation of the hash. 18 func (h Hash) Hex() string { 19 return fmt.Sprintf("%#x", []byte(h)) 20 } 21 22 // String returns the hex string representation of the hash. 23 func (h Hash) String() string { 24 return h.Hex() 25 } 26 27 // Hasher interface 28 type Hasher interface { 29 // Algorithm returns the hashing algorithm of the hasher. 30 Algorithm() HashingAlgorithm 31 // Size returns the hash output length in bytes. 32 Size() int 33 // ComputeHash returns the hash output regardless of the existing hash state. 34 // It may update the state or not depending on the implementation. Thread safety 35 // also depends on the implementation. 36 ComputeHash([]byte) Hash 37 // Write([]bytes) (using the io.Writer interface) adds more bytes to the 38 // current hash state. 39 io.Writer 40 // SumHash returns the hash output. 41 // It may update the state or not depending on the implementation. 42 SumHash() Hash 43 // Reset resets the hash state. 44 Reset() 45 }