aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf/parser.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-22 14:35:27 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-22 16:49:48 +0200
commit014c2a75454d6108c4fc6a7495a37874a3535e74 (patch)
treeeac24aad094e9e3ac6343c1928f455c7b07a9d83 /conf/parser.go
parenttunnel: disable firewall before destroying wintun (diff)
downloadwireguard-windows-014c2a75454d6108c4fc6a7495a37874a3535e74.tar.xz
wireguard-windows-014c2a75454d6108c4fc6a7495a37874a3535e74.zip
conf: read files potentially with UTF16
Diffstat (limited to '')
-rw-r--r--conf/parser.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/conf/parser.go b/conf/parser.go
index e98a0244..88802688 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"
+
+ "golang.org/x/text/encoding/unicode"
)
type ParseError struct {
@@ -338,6 +340,23 @@ func FromWgQuick(s string, name string) (*Config, error) {
return &conf, nil
}
+func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) {
+ c, firstErr := FromWgQuick(s, name)
+ if firstErr == nil {
+ return c, nil
+ }
+ for _, encoding := range unicode.All {
+ decoded, err := encoding.NewDecoder().String(s)
+ if err == nil {
+ c, err := FromWgQuick(decoded, name)
+ if err == nil {
+ return c, nil
+ }
+ }
+ }
+ return nil, firstErr
+}
+
func FromUAPI(s string, existingConfig *Config) (*Config, error) {
lines := strings.Split(s, "\n")
parserState := inInterfaceSection