github.com/koko1123/flow-go-1@v0.29.6/model/hash/hash.go (about)

     1  package hash
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/onflow/flow-go/crypto/hash"
     7  )
     8  
     9  // DefaultHasher is the default hasher used by Flow.
    10  var DefaultHasher hash.Hasher
    11  
    12  type defaultHasher struct {
    13  	hash.Hasher
    14  	sync.Mutex
    15  }
    16  
    17  func (h *defaultHasher) ComputeHash(b []byte) hash.Hash {
    18  	h.Lock()
    19  	defer h.Unlock()
    20  	return h.Hasher.ComputeHash(b)
    21  }
    22  
    23  func init() {
    24  	DefaultHasher = &defaultHasher{
    25  		hash.NewSHA3_256(),
    26  		sync.Mutex{},
    27  	}
    28  }