2023-08-01 16:27:27 +08:00
|
|
|
package hash
|
2023-08-01 15:32:05 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|