diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 2c3bc65..1f1475b 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -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 } diff --git a/global/fs.go b/global/fs.go index ccfac88..f985dd5 100644 --- a/global/fs.go +++ b/global/fs.go @@ -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 } diff --git a/internal/param/param.go b/internal/param/param.go index fd86b74..19da7fc 100644 --- a/internal/param/param.go +++ b/internal/param/param.go @@ -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 -}