From 2f52aa7ed8624ec2889508451d59797e47573b8c Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Thu, 2 Jan 2025 09:45:46 +0000 Subject: [PATCH] Freedom noises: Support RawURLEncoding for "base64" In case we want to share `noises` via sharing link. --- infra/conf/freedom.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/infra/conf/freedom.go b/infra/conf/freedom.go index 5eb3e871..15f1bcff 100644 --- a/infra/conf/freedom.go +++ b/infra/conf/freedom.go @@ -153,8 +153,9 @@ func (c *FreedomConfig) Build() (proto.Message, error) { func ParseNoise(noise *Noise) (*freedom.Noise, error) { var err error NConfig := new(freedom.Noise) + noise.Packet = strings.TrimSpace(noise.Packet) - switch strings.ToLower(noise.Type) { + switch noise.Type { case "rand": min, max, err := ParseRangeString(noise.Packet) if err != nil { @@ -168,7 +169,7 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) { case "str": // user input string - NConfig.Packet = []byte(strings.TrimSpace(noise.Packet)) + NConfig.Packet = []byte(noise.Packet) case "hex": // user input hex @@ -179,7 +180,7 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) { case "base64": // user input base64 - NConfig.Packet, err = base64.StdEncoding.DecodeString(strings.TrimSpace(noise.Packet)) + NConfig.Packet, err = base64.RawURLEncoding.DecodeString(strings.NewReplacer("+", "-", "/", "_", "=", "").Replace(noise.Packet)) if err != nil { return nil, errors.New("Invalid base64 string").Base(err) }