加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sm3_test.go 990 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-11-11 17:53 . 统一单元测试格式
package dongle
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
var sm3Tests = []struct {
input string
toHex string
toBase64 string
}{
{"", "", ""},
{"hello world", "44f0061e69fa6fdfc290c494654a05dc0c053da7e5c52b84ef93a9d67d3fff88", "RPAGHmn6b9/CkMSUZUoF3AwFPaflxSuE75Op1n0//4g="},
}
func TestSm3_Encrypt_String(t *testing.T) {
for index, test := range sm3Tests {
e := Encrypt.FromString(test.input).BySm3()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, test.toHex, e.ToHexString())
assert.Equal(t, test.toBase64, e.ToBase64String())
})
}
}
func TestSm3_Encrypt_Bytes(t *testing.T) {
for index, test := range sm3Tests {
e := Encrypt.FromBytes([]byte(test.input)).BySm3()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.toHex), e.ToHexBytes())
assert.Equal(t, []byte(test.toBase64), e.ToBase64Bytes())
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化