From 79a5d3c935f3b4e48655359a3122dc3f16c7d877 Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Thu, 23 Jun 2022 15:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=85=E8=A3=85=E7=AD=BE=E5=90=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hash/hash.go | 8 ++++++++ hmac/hmac.go | 8 ++++++++ 2 files changed, 16 insertions(+) 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)