Skip to content

Commit

Permalink
Freedom noises: Support RawURLEncoding for "base64"
Browse files Browse the repository at this point in the history
In case we want to share `noises` via sharing link.
  • Loading branch information
RPRX authored Jan 2, 2025
1 parent ca50c9c commit 2f52aa7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions infra/conf/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 2f52aa7

Please sign in to comment.