From f41055778ce24d8779cf8949c16d7a4467fa4987 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 23 Feb 2023 09:15:05 -0400 Subject: [PATCH] fix: use stdbase64 encoding --- waku/v2/rpc/rpc_type.go | 7 ++----- waku/v2/rpc/util_test.go | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/waku/v2/rpc/rpc_type.go b/waku/v2/rpc/rpc_type.go index 0bd4a3d0..3106f931 100644 --- a/waku/v2/rpc/rpc_type.go +++ b/waku/v2/rpc/rpc_type.go @@ -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 { diff --git a/waku/v2/rpc/util_test.go b/waku/v2/rpc/util_test.go index 1abc2f99..b03b35cb 100644 --- a/waku/v2/rpc/util_test.go +++ b/waku/v2/rpc/util_test.go @@ -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)