fix: use stdbase64 encoding

This commit is contained in:
Richard Ramos 2023-02-23 09:15:05 -04:00 committed by RichΛrd
parent 042521e00b
commit f41055778c
2 changed files with 3 additions and 6 deletions

View File

@ -14,11 +14,8 @@ type MessagesReply = []*RPCWakuMessage
type Base64URLByte []byte
func (u Base64URLByte) MarshalJSON() ([]byte, error) {
base64Value := base64.URLEncoding.EncodeToString(u)
return []byte("\"" + base64Value + "\""), nil
}
// UnmarshalText is used by json.Unmarshal to decode both url-safe and standard
// base64 encoded strings with and without padding
func (h *Base64URLByte) UnmarshalText(b []byte) error {
inputValue := ""
if b != nil {

View File

@ -30,7 +30,7 @@ func TestBase64Encoding(t *testing.T) {
m := make(map[string]interface{})
err = json.Unmarshal(jsonBytes, &m)
require.NoError(t, err)
require.Equal(t, base64.URLEncoding.EncodeToString([]byte(input)), m["payload"])
require.Equal(t, base64.StdEncoding.EncodeToString([]byte(input)), m["payload"])
decodedRpcMsg := new(RPCWakuMessage)
err = json.Unmarshal(jsonBytes, decodedRpcMsg)