加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
verifier.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-11-21 23:08 . 移除中文注释
package dongle
type Verifier struct {
dongle
sign []byte
}
// newVerifier returns a new Verifier instance.
func newVerifier() Verifier {
return Verifier{}
}
// FromRawString verify signature from raw string.
func (v Verifier) FromRawString(signature, message string) Verifier {
v.src = string2bytes(message)
v.sign = string2bytes(signature)
return v
}
// FromHexString decrypts from string with hex encoding.
func (v Verifier) FromHexString(signature, message string) Verifier {
d := Decode.FromString(signature).ByHex()
if d.Error != nil {
v.Error = NewDecodeError().ModeError("hex")
return v
}
v.sign = d.ToBytes()
v.src = string2bytes(message)
return v
}
// FromBase64String decrypts from string with base64 encoding.
func (v Verifier) FromBase64String(signature, message string) Verifier {
d := Decode.FromString(signature).ByBase64()
if d.Error != nil {
v.Error = NewDecodeError().ModeError("base64")
return v
}
v.sign = d.ToBytes()
v.src = string2bytes(message)
return v
}
// FromRawBytes verify signature from raw byte slice.
func (v Verifier) FromRawBytes(signature, message []byte) Verifier {
v.sign = signature
v.src = message
return v
}
// FromHexBytes verify from byte slice with hex encoding.
func (v Verifier) FromHexBytes(signature, message []byte) Verifier {
d := Decode.FromBytes(signature).ByHex()
if d.Error != nil {
v.Error = NewDecodeError().ModeError("hex")
return v
}
v.sign = d.ToBytes()
v.src = message
return v
}
// FromBase64Bytes verify from byte slice with base64 encoding.
func (v Verifier) FromBase64Bytes(signature, message []byte) Verifier {
d := Decode.FromBytes(signature).ByBase64()
if d.Error != nil {
v.Error = NewDecodeError().ModeError("base64")
return v
}
v.sign = d.ToBytes()
v.src = message
return v
}
// ToBool outputs as bool.
func (v Verifier) ToBool() bool {
if len(v.src) == 0 || len(v.sign) == 0 {
return false
}
return v.Error == nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化