mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-17 08:02:40 +08:00
包装签名函数
This commit is contained in:
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user