mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-05-06 05:26:33 -05:00
Some checks failed
Build CI / build (push) Has been cancelled
Additionally adds verification and sanity checks for all values passed to Sake from the client
43 lines
956 B
Go
43 lines
956 B
Go
package common
|
|
|
|
import (
|
|
"encoding/base64"
|
|
)
|
|
|
|
var (
|
|
Base64DwcEncoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-").WithPadding('*')
|
|
Base64GamespyAlternativeEncoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]").WithPadding('_')
|
|
)
|
|
|
|
func Base32Encode(value uint64) string {
|
|
alpha := "0123456789abcdefghijklmnopqrstuv"
|
|
|
|
encoded := ""
|
|
for value > 0 {
|
|
encoded += string(alpha[value&0x1f])
|
|
value >>= 5
|
|
}
|
|
|
|
encoded = reverse(encoded)
|
|
|
|
return encoded
|
|
}
|
|
|
|
func Base64Convert(input string, fromEncoding, toEncoding *base64.Encoding) (string, error) {
|
|
decoded, err := fromEncoding.DecodeString(input)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return toEncoding.EncodeToString(decoded), nil
|
|
}
|
|
|
|
func reverse(s string) string {
|
|
rns := []rune(s)
|
|
for i, j := 0, len(rns)-1; i < j; i, j = i+1, j-1 {
|
|
rns[i], rns[j] = rns[j], rns[i]
|
|
}
|
|
|
|
return string(rns)
|
|
}
|