Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加参数校验 #1

Closed
sh7ning opened this issue Sep 15, 2021 · 3 comments
Closed

增加参数校验 #1

sh7ning opened this issue Sep 15, 2021 · 3 comments

Comments

@sh7ning
Copy link

sh7ning commented Sep 15, 2021

Feature Request

AES 加解密的时候,key的长度是有要求的,不然随便一个key可能会有问题,加解密出的结果不对应,可以考虑增加参数校验或则增加错误输出,不然使用者无感知得到一个错误的结果(空字符串)

另外,文档readme中对AES解密的demo是有问题的,应该是 dongle.Decrypt.FromString 而不是 dongle.Encrypt.FromString

@gouguoyin
Copy link
Collaborator

感谢你的反馈,欢迎一块完善

@gouguoyin
Copy link
Collaborator

image
这里已经对key进行了校验,判断Error是否为nil即可

@sh7ning
Copy link
Author

sh7ning commented Sep 15, 2021

如果是参考readme的链式调用到最后的ToString就感知不到错误

加上encrypt不是指针,所以调用的时候要写的很严谨才行,比如下边这样调用也不能获取到错误

e := dongle.Encrypt
e.FromString(text).ByAes(cipher)
if e.Error != nil {
        return "", e.Error
}
return e.ToString(), nil

下边这样才能感知到错误

e := dongle.Encrypt.FromString(text).ByAes(cipher)
if e.Error != nil {
        return "", e.Error
}
return e.ToString(), nil

不过问题不大,我已经能按照你上边说的用法处理了错误了,谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants