Merge pull request #568 from trheyi/main
Add algorithm parameter to HmacWith function
This commit is contained in:
commit
658da9bcf9
2 changed files with 26 additions and 2 deletions
|
|
@ -166,6 +166,7 @@ func TestHmacWith(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
option *hmacOption
|
option *hmacOption
|
||||||
hash crypto.Hash
|
hash crypto.Hash
|
||||||
|
algo string
|
||||||
value string
|
value string
|
||||||
key string
|
key string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
|
|
@ -178,6 +179,7 @@ func TestHmacWith(t *testing.T) {
|
||||||
outputEncoding: "hex",
|
outputEncoding: "hex",
|
||||||
},
|
},
|
||||||
hash: crypto.SHA256,
|
hash: crypto.SHA256,
|
||||||
|
algo: "SHA256",
|
||||||
value: valuehex,
|
value: valuehex,
|
||||||
key: keyhex,
|
key: keyhex,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
|
|
@ -192,6 +194,7 @@ func TestHmacWith(t *testing.T) {
|
||||||
hash: crypto.SHA256,
|
hash: crypto.SHA256,
|
||||||
value: valuebase64,
|
value: valuebase64,
|
||||||
key: keybase64,
|
key: keybase64,
|
||||||
|
algo: "SHA1",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -221,4 +224,25 @@ func TestHmacWith(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
option := map[string]interface{}{}
|
||||||
|
if tt.option != nil {
|
||||||
|
option = map[string]interface{}{
|
||||||
|
"key": tt.option.keyEncoding,
|
||||||
|
"value": tt.option.valueEncoding,
|
||||||
|
"output": tt.option.outputEncoding,
|
||||||
|
"algo": tt.algo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args := []interface{}{option, tt.value, tt.key}
|
||||||
|
_, err := process.New("crypto.HmacWith", args...).Exec()
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("HmacWith() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ func ProcessHmac(process *process.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessHmacWith yao.crypto.hmac Crypto the Keyed-Hash Message Authentication Code (HMAC) Hash
|
// ProcessHmacWith yao.crypto.hmac Crypto the Keyed-Hash Message Authentication Code (HMAC) Hash
|
||||||
// Args[0] map: option {"key": "base64", "value": "base64", "output": "base64"} // hex/base64
|
// Args[0] map: option {"key": "base64", "value": "base64", "output": "base64", "algo": "SHA256"} // hex/base64
|
||||||
// Args[1] string: value
|
// Args[1] string: value
|
||||||
// Args[2] string: key
|
// Args[2] string: key
|
||||||
func ProcessHmacWith(process *process.Process) interface{} {
|
func ProcessHmacWith(process *process.Process) interface{} {
|
||||||
|
|
@ -94,7 +94,7 @@ func ProcessHmacWith(process *process.Process) interface{} {
|
||||||
if v, has := option["output"].(string); has {
|
if v, has := option["output"].(string); has {
|
||||||
o.outputEncoding = v
|
o.outputEncoding = v
|
||||||
}
|
}
|
||||||
if v, has := option["type"].(string); has {
|
if v, has := option["algo"].(string); has && v != "" {
|
||||||
typ = v
|
typ = v
|
||||||
}
|
}
|
||||||
h, has := HashTypes[typ]
|
h, has := HashTypes[typ]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue