mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-09 09:23:07 +00:00
26 lines
355 B
Go
26 lines
355 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"hash"
|
|
"sync"
|
|
)
|
|
|
|
var sha256Pool = sync.Pool{New: func() interface{} {
|
|
return sha256.New()
|
|
}}
|
|
|
|
func SHA256(data []byte) []byte {
|
|
h, ok := sha256Pool.Get().(hash.Hash)
|
|
if !ok {
|
|
h = sha256.New()
|
|
}
|
|
defer sha256Pool.Put(h)
|
|
h.Reset()
|
|
|
|
var result [32]byte
|
|
h.Write(data)
|
|
h.Sum(result[:0])
|
|
return result[:]
|
|
}
|