Fix according to staticcheck result

staticcheck repo: https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
This commit is contained in:
loyalsoldier
2020-08-30 23:41:15 +08:00
parent 1fa89b32d4
commit f12f76582f
10 changed files with 22 additions and 30 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ func generateRandomBytes(random []byte, connType [4]byte) {
continue
}
if 0x00000000 == (uint32(random[7])<<24)|(uint32(random[6])<<16)|(uint32(random[5])<<8)|uint32(random[4]) {
if (uint32(random[7])<<24)|(uint32(random[6])<<16)|(uint32(random[5])<<8)|uint32(random[4]) == 0x00000000 {
continue
}
+2 -2
View File
@@ -8,6 +8,7 @@ import (
"encoding/binary"
"io"
"time"
"v2ray.com/core/common"
)
@@ -21,8 +22,7 @@ func SealVMessAEADHeader(key [16]byte, data []byte) []byte {
aeadPayloadLengthSerializeBuffer := bytes.NewBuffer(nil)
var headerPayloadDataLen uint16
headerPayloadDataLen = uint16(len(data))
headerPayloadDataLen := uint16(len(data))
common.Must(binary.Write(aeadPayloadLengthSerializeBuffer, binary.BigEndian, headerPayloadDataLen))
+2 -1
View File
@@ -3,9 +3,10 @@ package aead
import (
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOpenVMessAEADHeader(t *testing.T) {
+4 -6
View File
@@ -12,19 +12,18 @@ import (
"io/ioutil"
"sync"
"time"
"v2ray.com/core/common/dice"
vmessaead "v2ray.com/core/proxy/vmess/aead"
"golang.org/x/crypto/chacha20poly1305"
"v2ray.com/core/common"
"v2ray.com/core/common/bitmask"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/task"
"v2ray.com/core/proxy/vmess"
vmessaead "v2ray.com/core/proxy/vmess/aead"
)
type sessionId struct {
@@ -170,7 +169,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
var fixedSizeAuthID [16]byte
copy(fixedSizeAuthID[:], buffer.Bytes())
if foundAEAD == true {
if foundAEAD {
vmessAccount = user.Account.(*vmess.MemoryAccount)
var fixedSizeCmdKey [16]byte
copy(fixedSizeCmdKey[:], vmessAccount.ID.CmdKey())
@@ -405,8 +404,7 @@ func (s *ServerSession) EncodeResponseHeader(header *protocol.ResponseHeader, wr
aeadResponseHeaderLengthEncryptionBuffer := bytes.NewBuffer(nil)
var decryptedResponseHeaderLengthBinaryDeserializeBuffer uint16
decryptedResponseHeaderLengthBinaryDeserializeBuffer = uint16(aeadEncryptedHeaderBuffer.Len())
decryptedResponseHeaderLengthBinaryDeserializeBuffer := uint16(aeadEncryptedHeaderBuffer.Len())
common.Must(binary.Write(aeadResponseHeaderLengthEncryptionBuffer, binary.BigEndian, decryptedResponseHeaderLengthBinaryDeserializeBuffer))
+3 -3
View File
@@ -11,13 +11,13 @@ import (
"sync"
"sync/atomic"
"time"
"v2ray.com/core/common/dice"
"v2ray.com/core/proxy/vmess/aead"
"v2ray.com/core/common"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/task"
"v2ray.com/core/proxy/vmess/aead"
)
const (
@@ -141,7 +141,7 @@ func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error {
v.generateNewHashes(protocol.Timestamp(nowSec), uu)
account := uu.user.Account.(*MemoryAccount)
if v.behaviorFused == false {
if !v.behaviorFused {
hashkdf := hmac.New(func() hash.Hash { return sha256.New() }, []byte("VMESSBSKDF"))
hashkdf.Write(account.ID.Bytes())
v.behaviorSeed = crc64.Update(v.behaviorSeed, crc64.MakeTable(crc64.ECMA), hashkdf.Sum(nil))