mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-01-22 00:36:38 +00:00
Freedom noises: Support "hex" as type
& packet
(#4239)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
parent
33186ca5e6
commit
ca50c9cbe6
|
@ -2,6 +2,7 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -166,18 +167,25 @@ 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(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":
|
case "base64":
|
||||||
//user input base64
|
// user input base64
|
||||||
NConfig.Packet, err = base64.StdEncoding.DecodeString(strings.TrimSpace(noise.Packet))
|
NConfig.Packet, err = base64.StdEncoding.DecodeString(strings.TrimSpace(noise.Packet))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Invalid base64 string")
|
return nil, errors.New("Invalid base64 string").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
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 {
|
if noise.Delay != nil {
|
||||||
|
|
Loading…
Reference in a new issue