1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 05:55:04 +08:00

rf: remove Base64DecodeString

Now segmentio/asm resolve issue 50, we don't need this wrapper.
This commit is contained in:
wdvxdr 2022-08-31 17:24:22 +08:00
parent 98712bf9ca
commit 1ff5e4de12
3 changed files with 4 additions and 16 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
b14 "github.com/fumiama/go-base16384"
"github.com/segmentio/asm/base64"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@ -1122,7 +1123,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video bool, sourceTy
return &LocalImageElement{File: fu.Path, URL: f}, nil
}
if !video && strings.HasPrefix(f, "base64") {
b, err := param.Base64DecodeString(strings.TrimPrefix(f, "base64://"))
b, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(f, "base64://"))
if err != nil {
return nil, err
}

View File

@ -14,9 +14,8 @@ import (
"github.com/Mrs4s/MiraiGo/utils"
b14 "github.com/fumiama/go-base16384"
"github.com/segmentio/asm/base64"
log "github.com/sirupsen/logrus"
"github.com/Mrs4s/go-cqhttp/internal/param"
)
const (
@ -89,7 +88,7 @@ func FindFile(file, cache, p string) (data []byte, err error) {
return nil, err
}
case strings.HasPrefix(file, "base64"):
data, err = param.Base64DecodeString(strings.TrimPrefix(file, "base64://"))
data, err = base64.StdEncoding.DecodeString(strings.TrimPrefix(file, "base64://"))
if err != nil {
return nil, err
}

View File

@ -7,8 +7,6 @@ import (
"strings"
"sync"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/segmentio/asm/base64"
"github.com/tidwall/gjson"
)
@ -83,13 +81,3 @@ func SplitURL(s string) []string {
result = append(result, s[last:])
return result
}
// Base64DecodeString decode base64 with avx2
// see https://github.com/segmentio/asm/issues/50
// avoid incorrect unsafe usage in origin library
func Base64DecodeString(s string) ([]byte, error) {
e := base64.StdEncoding
dst := make([]byte, e.DecodedLen(len(s)))
n, err := e.Decode(dst, utils.S2B(s))
return dst[:n], err
}