summaryrefslogtreecommitdiffhomepage
path: root/device
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-12-09 17:55:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-12-09 23:15:55 +0100
commit9c9e7e2724340280d0ca4ff29c067f2d144562c0 (patch)
tree239826ccafe70e5cee73936d9bcea8989dd33899 /device
parent2dd424e2d808703339688ff78e32ed30cd0dfe87 (diff)
global: apply gofumpt
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device')
-rw-r--r--device/allowedips_test.go3
-rw-r--r--device/cookie.go5
-rw-r--r--device/cookie_test.go5
-rw-r--r--device/device_test.go2
-rw-r--r--device/kdf_test.go2
-rw-r--r--device/noise-protocol.go7
-rw-r--r--device/send.go1
-rw-r--r--device/timers.go1
-rw-r--r--device/uapi.go1
9 files changed, 9 insertions, 18 deletions
diff --git a/device/allowedips_test.go b/device/allowedips_test.go
index a274997..68f382b 100644
--- a/device/allowedips_test.go
+++ b/device/allowedips_test.go
@@ -20,7 +20,6 @@ type testPairCommonBits struct {
}
func TestCommonBits(t *testing.T) {
-
tests := []testPairCommonBits{
{s1: []byte{1, 4, 53, 128}, s2: []byte{0, 0, 0, 0}, match: 7},
{s1: []byte{0, 4, 53, 128}, s2: []byte{0, 0, 0, 0}, match: 13},
@@ -41,7 +40,7 @@ func TestCommonBits(t *testing.T) {
}
}
-func benchmarkTrie(peerNumber int, addressNumber int, addressLength int, b *testing.B) {
+func benchmarkTrie(peerNumber, addressNumber, addressLength int, b *testing.B) {
var trie *trieEntry
var peers []*Peer
root := parentIndirection{&trie, 2}
diff --git a/device/cookie.go b/device/cookie.go
index b02b769..840f709 100644
--- a/device/cookie.go
+++ b/device/cookie.go
@@ -83,7 +83,7 @@ func (st *CookieChecker) CheckMAC1(msg []byte) bool {
return hmac.Equal(mac1[:], msg[smac1:smac2])
}
-func (st *CookieChecker) CheckMAC2(msg []byte, src []byte) bool {
+func (st *CookieChecker) CheckMAC2(msg, src []byte) bool {
st.RLock()
defer st.RUnlock()
@@ -119,7 +119,6 @@ func (st *CookieChecker) CreateReply(
recv uint32,
src []byte,
) (*MessageCookieReply, error) {
-
st.RLock()
// refresh cookie secret
@@ -204,7 +203,6 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool {
xchapoly, _ := chacha20poly1305.NewX(st.mac2.encryptionKey[:])
_, err := xchapoly.Open(cookie[:0], msg.Nonce[:], msg.Cookie[:], st.mac2.lastMAC1[:])
-
if err != nil {
return false
}
@@ -215,7 +213,6 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool {
}
func (st *CookieGenerator) AddMacs(msg []byte) {
-
size := len(msg)
smac2 := size - blake2s.Size128
diff --git a/device/cookie_test.go b/device/cookie_test.go
index 02e01d1..06f306f 100644
--- a/device/cookie_test.go
+++ b/device/cookie_test.go
@@ -10,7 +10,6 @@ import (
)
func TestCookieMAC1(t *testing.T) {
-
// setup generator / checker
var (
@@ -132,12 +131,12 @@ func TestCookieMAC1(t *testing.T) {
msg[5] ^= 0x20
- srcBad1 := []byte{192, 168, 13, 37, 40, 01}
+ srcBad1 := []byte{192, 168, 13, 37, 40, 1}
if checker.CheckMAC2(msg, srcBad1) {
t.Fatal("MAC2 generation/verification failed")
}
- srcBad2 := []byte{192, 168, 13, 38, 40, 01}
+ srcBad2 := []byte{192, 168, 13, 38, 40, 1}
if checker.CheckMAC2(msg, srcBad2) {
t.Fatal("MAC2 generation/verification failed")
}
diff --git a/device/device_test.go b/device/device_test.go
index 84221be..b484ca2 100644
--- a/device/device_test.go
+++ b/device/device_test.go
@@ -48,7 +48,7 @@ func uapiCfg(cfg ...string) string {
// genConfigs generates a pair of configs that connect to each other.
// The configs use distinct, probably-usable ports.
-func genConfigs(tb testing.TB) (cfgs [2]string, endpointCfgs [2]string) {
+func genConfigs(tb testing.TB) (cfgs, endpointCfgs [2]string) {
var key1, key2 NoisePrivateKey
_, err := rand.Read(key1[:])
if err != nil {
diff --git a/device/kdf_test.go b/device/kdf_test.go
index b14aa6d..872195c 100644
--- a/device/kdf_test.go
+++ b/device/kdf_test.go
@@ -20,7 +20,7 @@ type KDFTest struct {
t2 string
}
-func assertEquals(t *testing.T, a string, b string) {
+func assertEquals(t *testing.T, a, b string) {
if a != b {
t.Fatal("expected", a, "=", b)
}
diff --git a/device/noise-protocol.go b/device/noise-protocol.go
index e31ceda..ffa0452 100644
--- a/device/noise-protocol.go
+++ b/device/noise-protocol.go
@@ -138,11 +138,11 @@ var (
ZeroNonce [chacha20poly1305.NonceSize]byte
)
-func mixKey(dst *[blake2s.Size]byte, c *[blake2s.Size]byte, data []byte) {
+func mixKey(dst, c *[blake2s.Size]byte, data []byte) {
KDF1(dst, c[:], data)
}
-func mixHash(dst *[blake2s.Size]byte, h *[blake2s.Size]byte, data []byte) {
+func mixHash(dst, h *[blake2s.Size]byte, data []byte) {
hash, _ := blake2s.New256(nil)
hash.Write(h[:])
hash.Write(data)
@@ -175,7 +175,7 @@ func init() {
}
func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, error) {
- var errZeroECDHResult = errors.New("ECDH returned all zeros")
+ errZeroECDHResult := errors.New("ECDH returned all zeros")
device.staticIdentity.RLock()
defer device.staticIdentity.RUnlock()
@@ -436,7 +436,6 @@ func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer {
)
ok := func() bool {
-
// lock handshake state
handshake.mutex.RLock()
diff --git a/device/send.go b/device/send.go
index b05c69e..0a7135f 100644
--- a/device/send.go
+++ b/device/send.go
@@ -226,7 +226,6 @@ func (device *Device) RoutineReadFromTUN() {
offset := MessageTransportHeaderSize
size, err := device.tun.device.Read(elem.buffer[:], offset)
-
if err != nil {
if !device.isClosed() {
if !errors.Is(err, os.ErrClosed) {
diff --git a/device/timers.go b/device/timers.go
index 176976d..4d2d0f8 100644
--- a/device/timers.go
+++ b/device/timers.go
@@ -130,7 +130,6 @@ func expiredNewHandshake(peer *Peer) {
}
peer.Unlock()
peer.SendHandshakeInitiation(false)
-
}
func expiredZeroKeyMaterial(peer *Peer) {
diff --git a/device/uapi.go b/device/uapi.go
index 0f98c68..1994d46 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -73,7 +73,6 @@ func (device *Device) IpcGetOperation(w io.Writer) error {
}
func() {
-
// lock required resources
device.net.RLock()