diff options
| author | Shulhan <ms@kilabit.info> | 2023-07-23 18:19:35 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-07-23 20:19:02 +0700 |
| commit | dcc33a41e7eeab8fbcaa0372a8f64299e85f2cb2 (patch) | |
| tree | c9fe0b150f4cc9bc9660db15db8693dde5612524 /lib/ssh | |
| parent | 610ce44bd51339507fd4f10072c1a4b49a358566 (diff) | |
| download | pakakeh.go-dcc33a41e7eeab8fbcaa0372a8f64299e85f2cb2.tar.xz | |
ssh/config: reorder struct fields for better alignment
Changes,
* Config: changes allocated size from 32 to 16 bytes (-8 bytes)
* parser: changes allocated size from 40 to 32 bytes (-8 bytes)
* Section: changes allocated size from 392 to 360 bytes (-32 bytes)
The rest of changes that are not mentioned are from test files.
Diffstat (limited to 'lib/ssh')
| -rw-r--r-- | lib/ssh/config/config.go | 2 | ||||
| -rw-r--r-- | lib/ssh/config/config_test.go | 2 | ||||
| -rw-r--r-- | lib/ssh/config/parser.go | 2 | ||||
| -rw-r--r-- | lib/ssh/config/parser_test.go | 2 | ||||
| -rw-r--r-- | lib/ssh/config/section.go | 89 | ||||
| -rw-r--r-- | lib/ssh/config/section_test.go | 6 |
6 files changed, 58 insertions, 45 deletions
diff --git a/lib/ssh/config/config.go b/lib/ssh/config/config.go index 27577bee..ba79fba4 100644 --- a/lib/ssh/config/config.go +++ b/lib/ssh/config/config.go @@ -126,8 +126,8 @@ var ( // Config contains mapping of host's patterns and its options from SSH // configuration file. type Config struct { - sections []*Section envs map[string]string + sections []*Section } // Load SSH configuration from file. diff --git a/lib/ssh/config/config_test.go b/lib/ssh/config/config_test.go index 3cd3a1c5..2169caf1 100644 --- a/lib/ssh/config/config_test.go +++ b/lib/ssh/config/config_test.go @@ -60,8 +60,8 @@ func TestConfig_Get(t *testing.T) { } cases := []struct { - s string exp func(def Section) *Section + s string }{{ s: "", exp: func(def Section) *Section { diff --git a/lib/ssh/config/parser.go b/lib/ssh/config/parser.go index 1abf3247..5f9e57bc 100644 --- a/lib/ssh/config/parser.go +++ b/lib/ssh/config/parser.go @@ -16,9 +16,9 @@ import ( // parser for the SSH config file that merge all "Include" files and convert // them all into lines of string. type parser struct { + files map[string]struct{} workDir string homeDir string - files map[string]struct{} } func newParser() (p *parser, err error) { diff --git a/lib/ssh/config/parser_test.go b/lib/ssh/config/parser_test.go index c1618290..f003776c 100644 --- a/lib/ssh/config/parser_test.go +++ b/lib/ssh/config/parser_test.go @@ -101,8 +101,8 @@ func TestConfigParser_load(t *testing.T) { cases := []struct { dir string pattern string - exp []string expError string + exp []string }{{ dir: wd, pattern: "testdata/config", diff --git a/lib/ssh/config/section.go b/lib/ssh/config/section.go index 3ea9266e..f048aaad 100644 --- a/lib/ssh/config/section.go +++ b/lib/ssh/config/section.go @@ -39,40 +39,30 @@ const ( // Section is the type that represent SSH client Host and Match section in // configuration. type Section struct { - AddKeysToAgent string - AddressFamily string - BindAddress string - BindInterface string - CanonicalDomains []string - CanonicalizeHostname string - CanonicalizeMaxDots int - CanonicalizePermittedCNAMEs *PermittedCNAMEs - CASignatureAlgorithms []string - CertificateFile []string - ConnectionAttempts int - ConnectTimeout int - // Environments contains system environment variables that will be // passed to Execute(). // The key and value is derived from "SendEnv" and "SetEnv". Environments map[string]string - Hostname string - identityAgent string - IdentityFile []string - Port string - User string - XAuthLocation string - IsBatchMode bool - IsCanonicalizeFallbackLocal bool - IsChallengeResponseAuthentication bool - IsCheckHostIP bool - IsClearAllForwardings bool - UseCompression bool - UseVisualHostKey bool + // PrivateKeys contains IdentityFile that has been parsed. + // This field will be set once the Signers has been called. + PrivateKeys map[string]any - // User's home directory. - homeDir string + CanonicalizePermittedCNAMEs *PermittedCNAMEs + + AddKeysToAgent string + AddressFamily string + BindAddress string + BindInterface string + CanonicalizeHostname string + + Hostname string + Port string + + // The first IdentityFile that exist and valid. + PrivateKeyFile string + + User string // WorkingDir contains the directory where the SSH client started. // This value is required when client want to copy file from/to @@ -81,18 +71,36 @@ type Section struct { // os.Getwd() or user's home directory. WorkingDir string - // The first IdentityFile that exist and valid. - PrivateKeyFile string + XAuthLocation string - // PrivateKeys contains IdentityFile that has been parsed. - // This field will be set once the Signers has been called. - PrivateKeys map[string]any + // User's home directory. + homeDir string + + identityAgent string + + CanonicalDomains []string + CASignatureAlgorithms []string + CertificateFile []string + IdentityFile []string // Patterns for Host section. patterns []*pattern // Criteria for Match section. - criteria []*matchCriteria + criteria []*matchCriteria + + CanonicalizeMaxDots int + ConnectionAttempts int + ConnectTimeout int + + IsBatchMode bool + IsCanonicalizeFallbackLocal bool + IsChallengeResponseAuthentication bool + IsCheckHostIP bool + IsClearAllForwardings bool + UseCompression bool + UseVisualHostKey bool + useCriteria bool useDefaultIdentityFile bool // Flag for the IdentityFile. @@ -101,8 +109,13 @@ type Section struct { // newSection create new Host or Match with default values. func newSection() *Section { return &Section{ + Environments: map[string]string{}, + AddKeysToAgent: valueNo, AddressFamily: valueAny, + Port: defPort, + XAuthLocation: defXAuthLocation, + CASignatureAlgorithms: []string{ ssh.KeyAlgoECDSA256, ssh.KeyAlgoECDSA384, @@ -110,16 +123,16 @@ func newSection() *Section { ssh.KeyAlgoED25519, ssh.KeyAlgoRSA, }, - ConnectionAttempts: defConnectionAttempts, - Environments: map[string]string{}, + IdentityFile: []string{ "~/.ssh/id_dsa", "~/.ssh/id_ecdsa", "~/.ssh/id_ed25519", "~/.ssh/id_rsa", }, - Port: defPort, - XAuthLocation: defXAuthLocation, + + ConnectionAttempts: defConnectionAttempts, + useDefaultIdentityFile: true, IsChallengeResponseAuthentication: true, IsCheckHostIP: true, diff --git a/lib/ssh/config/section_test.go b/lib/ssh/config/section_test.go index f42dd864..ac022905 100644 --- a/lib/ssh/config/section_test.go +++ b/lib/ssh/config/section_test.go @@ -11,8 +11,8 @@ import ( func TestNewSectionHost(t *testing.T) { cases := []struct { - rawPattern string exp func(def Section) *Section + rawPattern string }{{ rawPattern: "", exp: func(exp Section) *Section { @@ -93,8 +93,8 @@ func TestSection_setEnv(t *testing.T) { Environments: make(map[string]string), } cases := []struct { - value string exp map[string]string + value string }{{ value: "a", exp: make(map[string]string), @@ -122,8 +122,8 @@ func TestSection_setSendEnv(t *testing.T) { } cases := []struct { - pattern string exp map[string]string + pattern string }{{ pattern: "key_1", exp: map[string]string{ |
