|
|
|
|
@ -69,6 +69,14 @@ func parseKeyHex(s string) (*wgkey.Key, error) { |
|
|
|
|
return &key, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// stringsCut is strings.Cut from proposed https://github.com/golang/go/issues/46336.
|
|
|
|
|
func stringsCut(s, sep string) (before, after string, found bool) { |
|
|
|
|
if i := strings.Index(s, sep); i >= 0 { |
|
|
|
|
return s[:i], s[i+len(sep):], true |
|
|
|
|
} |
|
|
|
|
return s, "", false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FromUAPI generates a Config from r.
|
|
|
|
|
// r should be generated by calling device.IpcGetOperation;
|
|
|
|
|
// it is not compatible with other uapi streams.
|
|
|
|
|
@ -83,12 +91,10 @@ func FromUAPI(r io.Reader) (*Config, error) { |
|
|
|
|
if line == "" { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
parts := strings.Split(line, "=") |
|
|
|
|
if len(parts) != 2 { |
|
|
|
|
return nil, fmt.Errorf("failed to parse line %q, found %d =-separated parts, want 2", line, len(parts)) |
|
|
|
|
key, value, ok := stringsCut(line, "=") |
|
|
|
|
if !ok { |
|
|
|
|
return nil, fmt.Errorf("failed to cut line %q on =", line) |
|
|
|
|
} |
|
|
|
|
key := parts[0] |
|
|
|
|
value := parts[1] |
|
|
|
|
valueBytes := scanner.Bytes()[len(key)+1:] |
|
|
|
|
|
|
|
|
|
if key == "public_key" { |
|
|
|
|
|