diff --git a/hash/hash.go b/hash/hash.go index 953a426..cf5b00d 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -13,10 +13,13 @@ import ( "github.com/cespare/xxhash/v2" "github.com/charlienet/go-mixed/bytesconv" + "github.com/charlienet/go-mixed/crypto" "github.com/spaolacci/murmur3" "github.com/tjfoc/gmsm/sm3" ) +var _ crypto.Signer = &hashComparer{} + type HashFunc func([]byte) bytesconv.BytesResult var hashFuncs = map[string]HashFunc{ @@ -44,6 +47,11 @@ func New(fname string) (*hashComparer, error) { }, nil } +func (c *hashComparer) Sign(msg []byte) ([]byte, error) { + ret := c.hashFunc(msg) + return ret.Bytes(), nil +} + func (c *hashComparer) Verify(msg, target []byte) bool { ret := c.hashFunc(msg) ret.Bytes() diff --git a/hmac/hmac.go b/hmac/hmac.go index 2d677a2..c9eae3d 100644 --- a/hmac/hmac.go +++ b/hmac/hmac.go @@ -12,9 +12,12 @@ import ( "strings" "github.com/charlienet/go-mixed/bytesconv" + "github.com/charlienet/go-mixed/crypto" "github.com/tjfoc/gmsm/sm3" ) +var _ crypto.Signer = &hashComparer{} + type HMacFunc func(key, msg []byte) bytesconv.BytesResult var hmacFuncs = map[string]HMacFunc{ @@ -44,6 +47,11 @@ func New(fname string, key []byte) (*hashComparer, error) { }, nil } +func (c *hashComparer) Sign(msg []byte) ([]byte, error) { + ret := c.hashFunc(c.key, msg) + return ret.Bytes(), nil +} + func (c *hashComparer) Verify(msg, target []byte) bool { ret := c.hashFunc(c.key, msg)