1 Star 0 Fork 50

黄苏伟/dongle

forked from golang-module/dongle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dongle.go 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2023-02-05 15:26 . 更新版本号
// @Package dongle
// @Description a simple, semantic and developer-friendly golang package for encoding&decoding, encryption&decryption and signature&verification
// @Page github.com/golang-module/dongle
// @Developer gouguoyin
// @Blog www.gouguoyin.com
// Package dongle is a simple, semantic and developer-friendly golang package for encoding&decoding, encryption&decryption and signature&verification.
package dongle
import (
"unsafe"
)
// Version current version
// 当前版本号
const Version = "0.2.8"
// dongle defines a dongle struct.
// 定义 dongle 结构体
type dongle struct {
src []byte
dst []byte
Error error
}
var (
// Encode returns a new Encoder instance
// 返回 encoder 实例
Encode = newEncoder()
// Decode returns a new Decoder instance
// 返回 decoder 实例
Decode = newDecoder()
// Encrypt returns a new Encrypter instance
// 返回 encrypter 实例
Encrypt = newEncrypter()
// Decrypt returns a new Decrypter instance
// 返回 decrypter 实例
Decrypt = newDecrypter()
// Sign returns a new Signer instance
// 返回 signer 实例
Sign = newSigner()
// Verify returns a new Verifier instance
// 返回 verifier 实例
Verify = newVerifier()
)
// converts string to byte slice without a memory allocation.
// 将字符串转换为字节切片
func string2bytes(s string) []byte {
if len(s) == 0 {
return []byte("")
}
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}
// converts byte slice to string without a memory allocation.
// 将字节切片转换为字符串
func bytes2string(b []byte) string {
if len(b) == 0 {
return ""
}
return *(*string)(unsafe.Pointer(&b))
}
// converts interface to byte slice.
// 将接口转换为字节切片
func interface2bytes(i interface{}) (b []byte) {
switch v := i.(type) {
case string:
b = string2bytes(v)
case []byte:
b = v
}
return
}
// split the byte slice by the specified size.
// 按照指定长度分割字节切片
func bytesSplit(buf []byte, size int) [][]byte {
var chunk []byte
chunks := make([][]byte, 0, len(buf)/size+1)
for len(buf) >= size {
chunk, buf = buf[:size], buf[size:]
chunks = append(chunks, chunk)
}
return chunks
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/huang-suwei/dongle.git
[email protected]:huang-suwei/dongle.git
huang-suwei
dongle
dongle
master

搜索帮助