33 lines
351 B
Go
33 lines
351 B
Go
package hash
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"hash"
|
|
)
|
|
|
|
type (
|
|
Sha256 struct {
|
|
d hash.Hash
|
|
}
|
|
)
|
|
|
|
func (s *Sha256) String() string {
|
|
return "sha256"
|
|
}
|
|
|
|
func (s *Sha256) Append(data []byte) {
|
|
if s.d == nil {
|
|
s.d = sha256.New()
|
|
}
|
|
|
|
s.d.Write(data)
|
|
}
|
|
|
|
func (s *Sha256) Finish() []byte {
|
|
if s.d == nil {
|
|
s.d = sha256.New()
|
|
}
|
|
|
|
return s.d.Sum(nil)
|
|
}
|