1 Star 0 Fork 0

golang-package/dongle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
decrypter.go 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-11-21 18:10 . base62
package dongle
// Decrypter defines Decrypter struct.
type Decrypter struct {
dongle
}
// newDecrypter returns a new Decrypter instance.
func newDecrypter() Decrypter {
return Decrypter{}
}
// FromRawString decrypts from raw string without encoding.
func (d Decrypter) FromRawString(s string) Decrypter {
d.src = string2bytes(s)
return d
}
// FromHexString decrypts from string with hex encoding.
func (d Decrypter) FromHexString(s string) Decrypter {
decode := Decode.FromString(s).ByHex()
if decode.Error != nil {
d.Error = NewDecodeError().ModeError("hex")
return d
}
d.src = decode.ToBytes()
return d
}
// FromBase64String decrypts from string with base64 encoding.
func (d Decrypter) FromBase64String(s string) Decrypter {
decode := Decode.FromString(s).ByBase64()
if decode.Error != nil {
d.Error = NewDecodeError().ModeError("base64")
return d
}
d.src = decode.ToBytes()
return d
}
// FromRawBytes decrypts from raw byte slice without encoding.
func (d Decrypter) FromRawBytes(b []byte) Decrypter {
d.src = b
return d
}
// FromHexBytes decrypts from byte slice with hex encoding.
func (d Decrypter) FromHexBytes(b []byte) Decrypter {
decode := Decode.FromBytes(b).ByHex()
if decode.Error != nil {
d.Error = NewDecodeError().ModeError("hex")
return d
}
d.src = decode.ToBytes()
return d
}
// FromBase64Bytes decrypts from byte slice with base64 encoding.
func (d Decrypter) FromBase64Bytes(b []byte) Decrypter {
decode := Decode.FromBytes(b).ByBase64()
if decode.Error != nil {
d.Error = NewDecodeError().ModeError("base64")
return d
}
d.src = decode.ToBytes()
return d
}
// String implements Stringer interface for Decrypter struct.
func (d Decrypter) String() string {
return d.ToString()
}
// ToString outputs as string.
func (d Decrypter) ToString() string {
return bytes2string(d.dst)
}
// ToBytes outputs as byte slice.
func (d Decrypter) ToBytes() []byte {
if len(d.dst) == 0 {
return []byte("")
}
return d.dst
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/golang-package/dongle.git
git@gitee.com:golang-package/dongle.git
golang-package
dongle
dongle
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385