diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-09 17:53:59 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-09 23:13:56 +0100 |
commit | 182247f5c830f93bfdb2a843a0ce3d394008c6d0 (patch) | |
tree | a2e3c0356c6c5ff2fcb8b572654d39e4735c4850 /conf | |
parent | build: update to go 1.17.4 and drop upstreamed patches (diff) | |
download | wireguard-windows-182247f5c830f93bfdb2a843a0ce3d394008c6d0.tar.xz wireguard-windows-182247f5c830f93bfdb2a843a0ce3d394008c6d0.zip |
global: apply gofumpt
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf')
-rw-r--r-- | conf/config.go | 8 | ||||
-rw-r--r-- | conf/migration_windows.go | 8 | ||||
-rw-r--r-- | conf/name.go | 9 | ||||
-rw-r--r-- | conf/parser.go | 4 | ||||
-rw-r--r-- | conf/parser_test.go | 2 | ||||
-rw-r--r-- | conf/path_windows.go | 8 | ||||
-rw-r--r-- | conf/store.go | 8 |
7 files changed, 30 insertions, 17 deletions
diff --git a/conf/config.go b/conf/config.go index e6cc6aac..d8935b44 100644 --- a/conf/config.go +++ b/conf/config.go @@ -27,9 +27,11 @@ type Endpoint struct { Port uint16 } -type Key [KeyLength]byte -type HandshakeTime time.Duration -type Bytes uint64 +type ( + Key [KeyLength]byte + HandshakeTime time.Duration + Bytes uint64 +) type Config struct { Name string diff --git a/conf/migration_windows.go b/conf/migration_windows.go index e81fb5e4..4e106e20 100644 --- a/conf/migration_windows.go +++ b/conf/migration_windows.go @@ -18,8 +18,10 @@ import ( "golang.org/x/sys/windows" ) -var migrating sync.Mutex -var lastMigrationTimer *time.Timer +var ( + migrating sync.Mutex + lastMigrationTimer *time.Timer +) type MigrationCallback func(name, oldPath, newPath string) @@ -53,7 +55,7 @@ func migrateUnencryptedConfigs(sharingBase int, migrated MigrationCallback) { if err != nil { continue } - if info.Mode().Perm()&0444 == 0 { + if info.Mode().Perm()&0o444 == 0 { continue } diff --git a/conf/name.go b/conf/name.go index 2b42c0e9..1ecb3225 100644 --- a/conf/name.go +++ b/conf/name.go @@ -18,9 +18,11 @@ var reservedNames = []string{ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", } -const serviceNameForbidden = "$" -const netshellDllForbidden = "\\/:*?\"<>|\t" -const specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00" +const ( + serviceNameForbidden = "$" + netshellDllForbidden = "\\/:*?\"<>|\t" + specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00" +) var allowedNameFormat = regexp.MustCompile("^[a-zA-Z0-9_=+.-]{1,32}$") @@ -60,6 +62,7 @@ type naturalSortToken struct { maybeString string maybeNumber int } + type naturalSortString struct { originalString string tokens []naturalSortToken diff --git a/conf/parser.go b/conf/parser.go index 477a5205..ff030362 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -158,7 +158,7 @@ func (c *Config) maybeAddPeer(p *Peer) { } } -func FromWgQuick(s string, name string) (*Config, error) { +func FromWgQuick(s, name string) (*Config, error) { if !TunnelNameIsValid(name) { return nil, &ParseError{l18n.Sprintf("Tunnel name is not valid"), name} } @@ -319,7 +319,7 @@ func FromWgQuick(s string, name string) (*Config, error) { return &conf, nil } -func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) { +func FromWgQuickWithUnknownEncoding(s, name string) (*Config, error) { c, firstErr := FromWgQuick(s, name) if firstErr == nil { return c, nil diff --git a/conf/parser_test.go b/conf/parser_test.go index c2f757c7..67a208eb 100644 --- a/conf/parser_test.go +++ b/conf/parser_test.go @@ -54,6 +54,7 @@ func equal(t *testing.T, expected, actual interface{}) bool { t.Errorf("Failed equals at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected) return false } + func lenTest(t *testing.T, actualO interface{}, expected int) bool { actual := reflect.ValueOf(actualO).Len() if reflect.DeepEqual(expected, actual) { @@ -63,6 +64,7 @@ func lenTest(t *testing.T, actualO interface{}, expected int) bool { t.Errorf("Wrong length at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected) return false } + func contains(t *testing.T, list, element interface{}) bool { listValue := reflect.ValueOf(list) for i := 0; i < listValue.Len(); i++ { diff --git a/conf/path_windows.go b/conf/path_windows.go index e994a1b1..ec93d5ff 100644 --- a/conf/path_windows.go +++ b/conf/path_windows.go @@ -15,8 +15,10 @@ import ( "golang.org/x/sys/windows" ) -var cachedConfigFileDir string -var cachedRootDir string +var ( + cachedConfigFileDir string + cachedRootDir string +) func tunnelConfigurationsDirectory() (string, error) { if cachedConfigFileDir != "" { @@ -27,7 +29,7 @@ func tunnelConfigurationsDirectory() (string, error) { return "", err } c := filepath.Join(root, "Configurations") - err = os.Mkdir(c, os.ModeDir|0700) + err = os.Mkdir(c, os.ModeDir|0o700) if err != nil && !os.IsExist(err) { return "", err } diff --git a/conf/store.go b/conf/store.go index def94836..af253046 100644 --- a/conf/store.go +++ b/conf/store.go @@ -14,8 +14,10 @@ import ( "golang.zx2c4.com/wireguard/windows/conf/dpapi" ) -const configFileSuffix = ".conf.dpapi" -const configFileUnencryptedSuffix = ".conf" +const ( + configFileSuffix = ".conf.dpapi" + configFileUnencryptedSuffix = ".conf" +) func ListConfigNames() ([]string, error) { configFileDir, err := tunnelConfigurationsDirectory() @@ -40,7 +42,7 @@ func ListConfigNames() ([]string, error) { if err != nil { continue } - if info.Mode().Perm()&0444 == 0 { + if info.Mode().Perm()&0o444 == 0 { continue } configs[i] = name |