1 Star 0 Fork 50

dtbsky/dongle

forked from golang-module/dongle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hmac_sha384_test.go 3.32 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-05-30 08:43 . v0.1.1 统一单元测试格式
package dongle
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
var (
hmacSha384Input, hmacSha384Key = "hello world", "dongle"
hmacSha384HexExpected = "421fcaa740216a31bbcd1f86f2212e0c68aa4b156a8ebc2ae55b3e75c4ee0509ea0325a0570ae739006b61d91d817fe8"
hmacSha384Base32Expected = "IIP4VJ2AEFVDDO6ND6DPEIJOBRUKUSYVNKHLYKXFLM7HLRHOAUE6UAZFUBLQVZZZABVWDWI5QF76Q==="
hmacSha384Base64Expected = "Qh/Kp0AhajG7zR+G8iEuDGiqSxVqjrwq5Vs+dcTuBQnqAyWgVwrnOQBrYdkdgX/o"
)
func TestEncrypt_ByHmacSha384_FromStringToString(t *testing.T) {
hexTests := []struct {
input1 string // 输入值1
input2 string // 输入值2
expected string // 期望值
}{
{"", "", ""},
{hmacSha384Input, hmacSha384Key, hmacSha384HexExpected},
}
for index, test := range hexTests {
e := Encrypt.FromString(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexString(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input1 string // 输入值1
input2 string // 输入值2
expected string // 期望值
}{
{"", "", ""},
{hmacSha384Input, hmacSha384Key, hmacSha384Base32Expected},
}
for index, test := range base32Tests {
e := Encrypt.FromString(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32String(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input1 string // 输入值1
input2 string // 输入值2
expected string // 期望值
}{
{"", "", ""},
{hmacSha384Input, hmacSha384Key, hmacSha384Base64Expected},
}
for index, test := range base64Tests {
e := Encrypt.FromString(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64String(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_ByHmacSha384_FromBytesToBytes(t *testing.T) {
hexTests := []struct {
input1 []byte // 输入值1
input2 []byte // 输入值2
expected []byte // 期望值
}{
{[]byte(""), []byte(""), []byte("")},
{[]byte(hmacSha384Input), []byte(hmacSha384Key), []byte(hmacSha384HexExpected)},
}
for index, test := range hexTests {
e := Encrypt.FromBytes(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexBytes(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input1 []byte // 输入值1
input2 []byte // 输入值2
expected []byte // 期望值
}{
{[]byte(""), []byte(""), []byte("")},
{[]byte(hmacSha384Input), []byte(hmacSha384Key), []byte(hmacSha384Base32Expected)},
}
for index, test := range base32Tests {
e := Encrypt.FromBytes(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32Bytes(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input1 []byte // 输入值1
input2 []byte // 输入值2
expected []byte // 期望值
}{
{[]byte(""), []byte(""), []byte("")},
{[]byte(hmacSha384Input), []byte(hmacSha384Key), []byte(hmacSha384Base64Expected)},
}
for index, test := range base64Tests {
e := Encrypt.FromBytes(test.input1).ByHmacSha384(test.input2)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64Bytes(), "Current test index is "+strconv.Itoa(index))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/daoker/dongle.git
git@gitee.com:daoker/dongle.git
daoker
dongle
dongle
master

搜索帮助