diff --git a/tools/utils/base85/base85.go b/tools/utils/base85/base85.go index 3e24e8582..20f28591a 100644 --- a/tools/utils/base85/base85.go +++ b/tools/utils/base85/base85.go @@ -11,6 +11,8 @@ import ( "io" "strconv" "sync" + + "kitty/tools/utils" ) // 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~ @@ -148,13 +150,13 @@ func Encode(dst, src []byte) int { func EncodeToString(src []byte) string { buf := make([]byte, EncodedLen(len(src))) Encode(buf, src) - return string(buf) + return utils.UnsafeBytesToString(buf) } // DecodeString returns the bytes represented by the base85 string s. func DecodeString(src string) ([]byte, error) { buf := make([]byte, DecodedLen(len(src))) - _, err := Decode(buf, []byte(src)) + _, err := Decode(buf, utils.UnsafeStringToBytes(src)) return buf, err } diff --git a/tools/utils/base85/base85_test.go b/tools/utils/base85/base85_test.go index 395dc185e..86e4c3257 100644 --- a/tools/utils/base85/base85_test.go +++ b/tools/utils/base85/base85_test.go @@ -38,6 +38,13 @@ func TestBase85(t *testing.T) { for _, p := range []pair{ {"M", "O#"}, {"Manual", "O<`_zVQc"}, + { + "Man is distinguished, not only by his reason, but by this singular passion from " + + "other animals, which is a lust of the mind, that by a perseverance of delight in " + + "the continued and indefatigable generation of knowledge, exceeds the short " + + "vehemence of any carnal pleasure.", + "O<`^zX>%ZCX>)XGZfA9Ab7*B`EFf-gbRchTYDO_b1WctXlY|;AZc?TVIXXEb95kYW*~HEWgu;7Ze%PVbZB98AYyqSVIXj2a&u*NWpZI|V`U(3W*}r`Y-wj`bRcPNAarPDAY*TCbZKsNWn>^>Ze$>7Ze(RV>IZ)PBCZf|#NWn^b%EFfigV`XJzb0BnRWgv5CZ*p`Xc4cT~ZDnp_Wgu^6AYpEKAY);2ZeeU7aBO8^b9HiME&", + }, } { q := EncodeToString([]byte(p.src)) if diff := cmp.Diff(p.encoded, q); diff != "" {