1 Star 0 Fork 63

墨城/dongle

forked from dromara/dongle 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sm3_test.go 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
kuafuRace 提交于 2022-12-07 09:04 +08:00 . 统一单元测试格式
package dongle
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
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())
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/qdmc/dongle.git
git@gitee.com:qdmc/dongle.git
qdmc
dongle
dongle
master

搜索帮助