ParseSSHConfigOption parses a single ssh config option into its key/value pair.
(opt string)
| 708 | |
| 709 | // ParseSSHConfigOption parses a single ssh config option into its key/value pair. |
| 710 | func ParseSSHConfigOption(opt string) (key string, value string, err error) { |
| 711 | if strings.ContainsAny(opt, "\r\n\x00") { |
| 712 | return "", "", xerrors.Errorf("config-ssh option %q must not contain carriage return, newline, or NUL characters", opt) |
| 713 | } |
| 714 | |
| 715 | // An equal sign or a space is the separator between the key and value. |
| 716 | idx := strings.IndexFunc(opt, func(r rune) bool { |
| 717 | return r == ' ' || r == '=' |
| 718 | }) |
| 719 | if idx == -1 { |
| 720 | return "", "", xerrors.Errorf("config-ssh option %q is missing a key/value separator ('=' or ' ')", opt) |
| 721 | } |
| 722 | return opt[:idx], opt[idx+1:], nil |
| 723 | } |
| 724 | |
| 725 | // isSingleHostPatternToken reports whether s is safe to write as a single SSH |
| 726 | // host pattern token. Whitespace or control characters could break out into |