Skip to content

Commit

Permalink
Fix golint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen00991 committed Sep 18, 2024
1 parent 21dc71d commit e4fb229
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 100 deletions.
138 changes: 65 additions & 73 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file contains all available configuration options
# with their default values.
# options for analysis running
run:
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
# If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota.
# Default: the number of logical CPUs in the machine
concurrency: 4
Expand Down Expand Up @@ -46,7 +44,7 @@ run:

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
formats:
- format: "colored-line-number"
path: stdout
Expand All @@ -67,6 +65,7 @@ output:
- file # filepath, line, and column.
show-stats: true

# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
Expand All @@ -82,15 +81,7 @@ linters-settings:
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
#exclude: /path/to/file.txt
funlen:
lines: 60
statements: 40
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 4

goconst:
# minimal length of string constant, 3 by default
min-len: 5
Expand Down Expand Up @@ -138,9 +129,6 @@ linters-settings:
# Default: 2
minThreshold: 4

gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging
Expand All @@ -157,34 +145,6 @@ linters-settings:
# simplify code: gofmt with `-s` option, true by default
simplify: true

goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/org/project
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
gomodguard:
allowed:
modules: # List of allowed modules
# - gopkg.in/yaml.v2
domains: # List of allowed module domains
# - golang.org
blocked:
modules: # List of blocked modules
# - github.com/uudashr/go-module: # Blocked module
# recommendations: # Recommended modules that should be used instead (Optional)
# - golang.org/x/mod
# reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional)
versions: # List of blocked module version constraints
# - github.com/mitchellh/go-homedir: # Blocked module with version constraint
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
enable-all: false
# enable or disable analyzers by name
Expand All @@ -206,6 +166,7 @@ linters-settings:
# Whether to be strict about shadowing; can be noisy.
# Default: false
strict: true

depguard:
rules:
# Name of a rule.
Expand All @@ -224,21 +185,38 @@ linters-settings:
line-length: 120
# tab width in spaces. Default to 1.
tab-width: 1
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true

nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30

testpackage:
# regexp pattern to skip files
skip-regexp: (export|internal)_test\.go

unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
# Mark all struct fields that have been written to as used.
# Default: true
field-writes-are-uses: true
# Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write.
# Default: false
post-statements-are-reads: true
# Mark all exported identifiers as used.
# Default: true
exported-is-used: true
# Mark all exported fields as used.
# default: true
exported-fields-are-used: true
# Mark all function parameters as used.
# default: true
parameters-are-used: true
# Mark all local variables as used.
# default: true
local-variables-are-used: true
# Mark all identifiers inside generated files as used.
# Default: true
generated-is-used: true

whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
Expand All @@ -262,30 +240,42 @@ linters-settings:
locale: US
ignore-words: []

wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
strict-append: true
# Allow calls and assignments to be cuddled as long as the lines have any
# matching variables, fields or types. Default is true.
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
# Allow trailing comments in ending of blocks
allow-trailing-comment: true
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0
# Force cuddling of err checks with err var assignment
force-err-cuddling: false
# Allow leading comments to be separated with empty liens
allow-separated-leading-comment: false
custom:
gomnd:
# !important in golangci-lint v1.58.0, gomnd is replaced by mnd
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
checks:
# - argument
- case
# - condition
- operation
- return
# - assign
# List of numbers to exclude from analysis.
# The numbers should be written as string.
# Values always ignored: "1", "1.0", "0" and "0.0"
# Default: []
ignored-numbers: []
# List of file patterns to exclude from analysis.
# Values always ignored: `.+_test.go`
# Default: []
ignored-files: []
# List of function patterns to exclude from analysis.
# Following functions are always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- 'os\.Mkdir'
- 'os\.MkdirAll'
- '^math\.'
- '^http\.StatusText$'

# custom:
# Each custom linter should have a unique name.

linters:
disable-all: true
disable-all: true
enable:
- errcheck
- goconst
Expand All @@ -312,12 +302,14 @@ linters:
- dogsled
- bodyclose
- asciicheck
- gosec
# - dupl

# Enable only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true


issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
Expand Down
15 changes: 8 additions & 7 deletions message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ func (container *ProposalContainer) BuildProposal(proposalNumber uint8, protocol
}

func (container *IKEPayloadContainer) BuildDeletePayload(
protocolID uint8, SPISize uint8, numberOfSPI uint16, SPIs []byte,
protocolID uint8, spiSize uint8, numberOfSPI uint16, spis []byte,
) {
deletePayload := new(Delete)
deletePayload.ProtocolID = protocolID
deletePayload.SPISize = SPISize
deletePayload.SPISize = spiSize
deletePayload.NumberOfSPI = numberOfSPI
deletePayload.SPIs = SPIs
deletePayload.SPIs = spis
*container = append(*container, deletePayload)
}

Expand Down Expand Up @@ -252,7 +252,7 @@ func (container *IKEPayloadContainer) BuildEAP5GNAS(identifier uint8, nasPDU []b
if len(nasPDU) == 0 {
return errors.Errorf("BuildEAP5GNAS(): NASPDU is nil")
}

var vendorData []byte
header := make([]byte, 4)

// Message ID
Expand All @@ -263,7 +263,8 @@ func (container *IKEPayloadContainer) BuildEAP5GNAS(identifier uint8, nasPDU []b
return errors.Errorf("BuildEAP5GNAS(): nasPDU length exceeds uint16 limit: %d", nasPDULen)
}
binary.BigEndian.PutUint16(header[2:4], uint16(nasPDULen))
vendorData := append(header, nasPDU...)
vendorData = append(vendorData, header...)
vendorData = append(vendorData, nasPDU...)

eap := container.BuildEAP(EAPCodeRequest, identifier)
eap.EAPTypeData.BuildEAPExpanded(VendorID3GPP, VendorTypeEAP5G, vendorData)
Expand All @@ -275,7 +276,7 @@ func (container *IKEPayloadContainer) BuildNotify5G_QOS_INFO(
qfiList []uint8,
isDefault bool,
isDSCPSpecified bool,
DSCP uint8,
dscp uint8,
) error {
notifyData := make([]byte, 1) // For length
// Append PDU session ID
Expand All @@ -299,7 +300,7 @@ func (container *IKEPayloadContainer) BuildNotify5G_QOS_INFO(

notifyData = append(notifyData, defaultAndDifferentiatedServiceFlags)
if isDSCPSpecified {
notifyData = append(notifyData, DSCP)
notifyData = append(notifyData, dscp)
}

// Assign length
Expand Down
3 changes: 2 additions & 1 deletion message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func (container *IKEPayloadContainer) Decode(nextPayload uint8, b []byte) error
return errors.Errorf("DecodePayload(): Illegal payload length %d < header length 4", payloadLength)
}
if len(b) < int(payloadLength) {
return errors.Errorf("DecodePayload(): The length of received message not matchs the length specified in header: %v", len(b))
return errors.Errorf("DecodePayload(): The length of received message not matchs"+
" the length specified in header: %v", len(b))
}

criticalBit := (b[1] & 0x80) >> 7
Expand Down
8 changes: 5 additions & 3 deletions message/payload_trafficselectorinitiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (trafficSelector *TrafficSelectorInitiator) Type() IKEPayloadType { return

func (trafficSelector *TrafficSelectorInitiator) marshal() ([]byte, error) {
if len(trafficSelector.TrafficSelectors) == 0 {
return nil, errors.Errorf("TrafficSelector: Contains no traffic selector for marshalling message")
return nil, errors.Errorf("TrafficSelector: Contains no traffic selector for marshaling message")
}

trafficSelectorData := make([]byte, 4)
Expand Down Expand Up @@ -62,7 +62,8 @@ func (trafficSelector *TrafficSelectorInitiator) marshal() ([]byte, error) {

dataLen := len(individualTrafficSelectorData)
if dataLen > 0xFFFF {
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 maximum value: %v", dataLen)
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 "+
"maximum value: %v", dataLen)
}
binary.BigEndian.PutUint16(individualTrafficSelectorData[2:4], uint16(dataLen))

Expand All @@ -88,7 +89,8 @@ func (trafficSelector *TrafficSelectorInitiator) marshal() ([]byte, error) {

dataLen := len(individualTrafficSelectorData)
if dataLen > 0xFFFF {
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 maximum value: %v", dataLen)
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 "+
"maximum value: %v", dataLen)
}
binary.BigEndian.PutUint16(individualTrafficSelectorData[2:4], uint16(dataLen))

Expand Down
2 changes: 1 addition & 1 deletion message/payload_trafficselectorinitiator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestTrafficSelectorInitiatorMarshal(t *testing.T) {
expErr bool
}{
{
description: "Contains no traffic selector for marshalling message",
description: "Contains no traffic selector for marshaling message",
tsi: TrafficSelectorInitiator{},
expErr: true,
},
Expand Down
8 changes: 5 additions & 3 deletions message/payload_trafficselectorresponder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (trafficSelector *TrafficSelectorResponder) marshal() ([]byte, error) {

dataLen := len(individualTrafficSelectorData)
if dataLen > 0xFFFF {
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 maximum value: %v", dataLen)
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 "+
"maximum value: %v", dataLen)
}
binary.BigEndian.PutUint16(individualTrafficSelectorData[2:4], uint16(dataLen))

Expand All @@ -73,7 +74,8 @@ func (trafficSelector *TrafficSelectorResponder) marshal() ([]byte, error) {

dataLen := len(individualTrafficSelectorData)
if dataLen > 0xFFFF {
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 maximum value: %v", dataLen)
return nil, errors.Errorf("TrafficSelector: individualTrafficSelectorData length exceeds uint16 "+
"maximum value: %v", dataLen)
}
binary.BigEndian.PutUint16(individualTrafficSelectorData[2:4], uint16(dataLen))

Expand All @@ -85,7 +87,7 @@ func (trafficSelector *TrafficSelectorResponder) marshal() ([]byte, error) {

return trafficSelectorData, nil
} else {
return nil, errors.Errorf("TrafficSelector: Contains no traffic selector for marshalling message")
return nil, errors.Errorf("TrafficSelector: Contains no traffic selector for marshaling message")
}
}

Expand Down
2 changes: 1 addition & 1 deletion message/payload_trafficselectorresponder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestTrafficSelectorResponderMarshal(t *testing.T) {
expErr bool
}{
{
description: "Contains no traffic selector for marshalling message",
description: "Contains no traffic selector for marshaling message",
tsi: TrafficSelectorResponder{},
expErr: true,
},
Expand Down
2 changes: 1 addition & 1 deletion message/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const (
const (
EstablishmentCauseEmergency = 0
EstablishmentCauseHighPriorityAccess = 1
EstablishmentCauseMO_Signalling = 3
EstablishmentCauseMO_Signaling = 3
EstablishmentCauseMO_Data = 4
EstablishmentCauseMPS_PriorityAccess = 8
EstablishmentCauseMCS_PriorityAccess = 9
Expand Down
3 changes: 1 addition & 2 deletions security/encr/encr_aes_cbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func (encr *ENCR_AES_CBC_Crypto) Decrypt(cipherText []byte) ([]byte, error) {
return nil, errors.Errorf("ENCR_AES_CBC_Crypto: Length of cipher text is too short to decrypt")
}

initializationVector := make([]byte, aes.BlockSize)
initializationVector = cipherText[:aes.BlockSize]
initializationVector := cipherText[:aes.BlockSize]
encryptedMessage := cipherText[aes.BlockSize:]

if len(encryptedMessage)%aes.BlockSize != 0 {
Expand Down
Loading

0 comments on commit e4fb229

Please sign in to comment.