2024-01-27 14:36:14 +08:00
|
|
|
package convutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
strutil "tinyrdm/backend/utils/string"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Base64Convert struct{}
|
|
|
|
|
2024-02-20 10:55:46 +08:00
|
|
|
func (Base64Convert) Enable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-27 14:36:14 +08:00
|
|
|
func (Base64Convert) Encode(str string) (string, bool) {
|
|
|
|
return base64.StdEncoding.EncodeToString([]byte(str)), true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Base64Convert) Decode(str string) (string, bool) {
|
|
|
|
if decodedStr, err := base64.StdEncoding.DecodeString(str); err == nil {
|
|
|
|
if s := string(decodedStr); !strutil.ContainsBinary(s) {
|
|
|
|
return s, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str, false
|
|
|
|
}
|