mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-01-09 20:17:17 +03:00
Freedom noises: Support RawURLEncoding for "base64"
In case we want to share `noises` via sharing link.
This commit is contained in:
parent
ca50c9cbe6
commit
2f52aa7ed8
@ -153,8 +153,9 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
||||||
var err error
|
var err error
|
||||||
NConfig := new(freedom.Noise)
|
NConfig := new(freedom.Noise)
|
||||||
|
noise.Packet = strings.TrimSpace(noise.Packet)
|
||||||
|
|
||||||
switch strings.ToLower(noise.Type) {
|
switch noise.Type {
|
||||||
case "rand":
|
case "rand":
|
||||||
min, max, err := ParseRangeString(noise.Packet)
|
min, max, err := ParseRangeString(noise.Packet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -168,7 +169,7 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
|||||||
|
|
||||||
case "str":
|
case "str":
|
||||||
// user input string
|
// user input string
|
||||||
NConfig.Packet = []byte(strings.TrimSpace(noise.Packet))
|
NConfig.Packet = []byte(noise.Packet)
|
||||||
|
|
||||||
case "hex":
|
case "hex":
|
||||||
// user input hex
|
// user input hex
|
||||||
@ -179,7 +180,7 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
|||||||
|
|
||||||
case "base64":
|
case "base64":
|
||||||
// user input 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 {
|
if err != nil {
|
||||||
return nil, errors.New("Invalid base64 string").Base(err)
|
return nil, errors.New("Invalid base64 string").Base(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user