Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freedom noises: Support "hex" as type & packet #4239

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions infra/conf/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package conf

import (
"encoding/base64"
"encoding/hex"
"net"
"strings"

Expand Down Expand Up @@ -166,18 +167,25 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
}

case "str":
//user input string
// user input string
NConfig.Packet = []byte(strings.TrimSpace(noise.Packet))

case "hex":
// user input hex
NConfig.Packet, err = hex.DecodeString(noise.Packet)
if err != nil {
return nil, errors.New("Invalid hex string").Base(err)
}

case "base64":
//user input base64
// user input base64
NConfig.Packet, err = base64.StdEncoding.DecodeString(strings.TrimSpace(noise.Packet))
if err != nil {
return nil, errors.New("Invalid base64 string")
return nil, errors.New("Invalid base64 string").Base(err)
}

default:
return nil, errors.New("Invalid packet, only rand/str/base64 are supported")
return nil, errors.New("Invalid packet, only rand/str/hex/base64 are supported")
}

if noise.Delay != nil {
Expand Down
Loading