mirror of
https://github.com/pion/stun.git
synced 2025-10-05 15:56:56 +08:00
Update CI configs to v0.7.2
Update lint scripts and CI configs. Excluding codecov.yml.
This commit is contained in:
2
.github/workflows/lint.yaml
vendored
2
.github/workflows/lint.yaml
vendored
@@ -47,5 +47,5 @@ jobs:
|
|||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.31
|
version: v1.45.2
|
||||||
args: $GOLANGCI_LINT_EXRA_ARGS
|
args: $GOLANGCI_LINT_EXRA_ARGS
|
||||||
|
@@ -15,14 +15,22 @@ linters-settings:
|
|||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
||||||
|
- bidichk # Checks for dangerous unicode character sequences
|
||||||
- bodyclose # checks whether HTTP response body is closed successfully
|
- bodyclose # checks whether HTTP response body is closed successfully
|
||||||
|
- contextcheck # check the function whether use a non-inherited context
|
||||||
- deadcode # Finds unused code
|
- deadcode # Finds unused code
|
||||||
|
- decorder # check declaration order and count of types, constants, variables and functions
|
||||||
- depguard # Go linter that checks if package imports are in a list of acceptable packages
|
- depguard # Go linter that checks if package imports are in a list of acceptable packages
|
||||||
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
||||||
- dupl # Tool for code clone detection
|
- dupl # Tool for code clone detection
|
||||||
|
- durationcheck # check for two durations multiplied together
|
||||||
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
|
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
|
||||||
|
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
|
||||||
|
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
|
||||||
|
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
|
||||||
- exhaustive # check exhaustiveness of enum switch statements
|
- exhaustive # check exhaustiveness of enum switch statements
|
||||||
- exportloopref # checks for pointers to enclosing loop variables
|
- exportloopref # checks for pointers to enclosing loop variables
|
||||||
|
- forcetypeassert # finds forced type assertions
|
||||||
- gci # Gci control golang package import order and make it always deterministic.
|
- gci # Gci control golang package import order and make it always deterministic.
|
||||||
- gochecknoglobals # Checks that no globals are present in Go code
|
- gochecknoglobals # Checks that no globals are present in Go code
|
||||||
- gochecknoinits # Checks that no init functions are present in Go code
|
- gochecknoinits # Checks that no init functions are present in Go code
|
||||||
@@ -35,40 +43,62 @@ linters:
|
|||||||
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
|
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
|
||||||
- goheader # Checks is file header matches to pattern
|
- goheader # Checks is file header matches to pattern
|
||||||
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
|
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
|
||||||
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
|
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
|
||||||
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
|
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
|
||||||
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
|
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
|
||||||
- gosec # Inspects source code for security problems
|
- gosec # Inspects source code for security problems
|
||||||
- gosimple # Linter for Go source code that specializes in simplifying a code
|
- gosimple # Linter for Go source code that specializes in simplifying a code
|
||||||
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
||||||
|
- grouper # An analyzer to analyze expression groups.
|
||||||
|
- importas # Enforces consistent import aliases
|
||||||
- ineffassign # Detects when assignments to existing variables are not used
|
- ineffassign # Detects when assignments to existing variables are not used
|
||||||
- misspell # Finds commonly misspelled English words in comments
|
- misspell # Finds commonly misspelled English words in comments
|
||||||
- nakedret # Finds naked returns in functions greater than a specified function length
|
- nakedret # Finds naked returns in functions greater than a specified function length
|
||||||
|
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
|
||||||
|
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
|
||||||
- noctx # noctx finds sending http request without context.Context
|
- noctx # noctx finds sending http request without context.Context
|
||||||
- scopelint # Scopelint checks for unpinned variables in go programs
|
- predeclared # find code that shadows one of Go's predeclared identifiers
|
||||||
|
- revive # golint replacement, finds style mistakes
|
||||||
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
|
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
|
||||||
- structcheck # Finds unused struct fields
|
- structcheck # Finds unused struct fields
|
||||||
- stylecheck # Stylecheck is a replacement for golint
|
- stylecheck # Stylecheck is a replacement for golint
|
||||||
|
- tagliatelle # Checks the struct tags.
|
||||||
|
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
|
||||||
|
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
|
||||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
||||||
- unconvert # Remove unnecessary type conversions
|
- unconvert # Remove unnecessary type conversions
|
||||||
- unparam # Reports unused function parameters
|
- unparam # Reports unused function parameters
|
||||||
- unused # Checks Go code for unused constants, variables, functions and types
|
- unused # Checks Go code for unused constants, variables, functions and types
|
||||||
- varcheck # Finds unused global variables and constants
|
- varcheck # Finds unused global variables and constants
|
||||||
|
- wastedassign # wastedassign finds wasted assignment statements
|
||||||
- whitespace # Tool for detection of leading and trailing whitespace
|
- whitespace # Tool for detection of leading and trailing whitespace
|
||||||
disable:
|
disable:
|
||||||
|
- containedctx # containedctx is a linter that detects struct contained context.Context field
|
||||||
|
- cyclop # checks function and package cyclomatic complexity
|
||||||
|
- exhaustivestruct # Checks if all struct's fields are initialized
|
||||||
|
- forbidigo # Forbids identifiers
|
||||||
- funlen # Tool for detection of long functions
|
- funlen # Tool for detection of long functions
|
||||||
- gocyclo # Computes and checks the cyclomatic complexity of functions
|
- gocyclo # Computes and checks the cyclomatic complexity of functions
|
||||||
- godot # Check if comments end in a period
|
- godot # Check if comments end in a period
|
||||||
- gomnd # An analyzer to detect magic numbers.
|
- gomnd # An analyzer to detect magic numbers.
|
||||||
|
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
|
||||||
|
- ireturn # Accept Interfaces, Return Concrete Types
|
||||||
- lll # Reports long lines
|
- lll # Reports long lines
|
||||||
|
- maintidx # maintidx measures the maintainability index of each function.
|
||||||
|
- makezero # Finds slice declarations with non-zero initial length
|
||||||
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
|
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
|
||||||
- nestif # Reports deeply nested if statements
|
- nestif # Reports deeply nested if statements
|
||||||
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
|
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
|
||||||
- nolintlint # Reports ill-formed or insufficient nolint directives
|
- nolintlint # Reports ill-formed or insufficient nolint directives
|
||||||
|
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
|
||||||
- prealloc # Finds slice declarations that could potentially be preallocated
|
- prealloc # Finds slice declarations that could potentially be preallocated
|
||||||
|
- promlinter # Check Prometheus metrics naming via promlint
|
||||||
- rowserrcheck # checks whether Err of rows is checked successfully
|
- rowserrcheck # checks whether Err of rows is checked successfully
|
||||||
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
|
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
|
||||||
- testpackage # linter that makes you use a separate _test package
|
- testpackage # linter that makes you use a separate _test package
|
||||||
|
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
|
||||||
|
- varnamelen # checks that the length of a variable's name matches its scope
|
||||||
|
- wrapcheck # Checks that errors returned from external packages are wrapped
|
||||||
- wsl # Whitespace Linter - Forces you to use empty lines!
|
- wsl # Whitespace Linter - Forces you to use empty lines!
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !debug
|
||||||
// +build !debug
|
// +build !debug
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
@@ -236,7 +236,7 @@ var clientTransactionPool = &sync.Pool{ // nolint:gochecknoglobals
|
|||||||
}
|
}
|
||||||
|
|
||||||
func acquireClientTransaction() *clientTransaction {
|
func acquireClientTransaction() *clientTransaction {
|
||||||
return clientTransactionPool.Get().(*clientTransaction)
|
return clientTransactionPool.Get().(*clientTransaction) //nolint:forcetypeassert
|
||||||
}
|
}
|
||||||
|
|
||||||
func putClientTransaction(t *clientTransaction) {
|
func putClientTransaction(t *clientTransaction) {
|
||||||
@@ -288,6 +288,7 @@ func (c *Client) SetRTO(rto time.Duration) {
|
|||||||
|
|
||||||
// StopErr occurs when Client fails to stop transaction while
|
// StopErr occurs when Client fails to stop transaction while
|
||||||
// processing error.
|
// processing error.
|
||||||
|
// nolint:errname
|
||||||
type StopErr struct {
|
type StopErr struct {
|
||||||
Err error // value returned by Stop()
|
Err error // value returned by Stop()
|
||||||
Cause error // error that caused Stop() call
|
Cause error // error that caused Stop() call
|
||||||
@@ -298,6 +299,7 @@ func (e StopErr) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CloseErr indicates client close failure.
|
// CloseErr indicates client close failure.
|
||||||
|
// nolint:errname
|
||||||
type CloseErr struct {
|
type CloseErr struct {
|
||||||
AgentErr error
|
AgentErr error
|
||||||
ConnectionErr error
|
ConnectionErr error
|
||||||
@@ -489,7 +491,7 @@ func (c *Client) Do(m *Message, f func(Event)) error {
|
|||||||
if f == nil {
|
if f == nil {
|
||||||
return c.Indicate(m)
|
return c.Indicate(m)
|
||||||
}
|
}
|
||||||
h := callbackWaitHandlerPool.Get().(*callbackWaitHandler)
|
h := callbackWaitHandlerPool.Get().(*callbackWaitHandler) //nolint:forcetypeassert
|
||||||
h.setCallback(f)
|
h.setCallback(f)
|
||||||
defer func() {
|
defer func() {
|
||||||
callbackWaitHandlerPool.Put(h)
|
callbackWaitHandlerPool.Put(h)
|
||||||
@@ -545,7 +547,7 @@ func (c *Client) handleAgentCallback(e Event) {
|
|||||||
}
|
}
|
||||||
// Doing re-transmission.
|
// Doing re-transmission.
|
||||||
t.attempt++
|
t.attempt++
|
||||||
b := bufferPool.Get().(*buffer)
|
b := bufferPool.Get().(*buffer) //nolint:forcetypeassert
|
||||||
b.buf = b.buf[:copy(b.buf[:cap(b.buf)], t.raw)]
|
b.buf = b.buf[:copy(b.buf[:cap(b.buf)], t.raw)]
|
||||||
defer bufferPool.Put(b)
|
defer bufferPool.Put(b)
|
||||||
var (
|
var (
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
@@ -152,8 +153,8 @@ func TestClosedOrPanic(t *testing.T) {
|
|||||||
closedOrPanic(ErrAgentClosed)
|
closedOrPanic(ErrAgentClosed)
|
||||||
func() {
|
func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
r, ok := recover().(error)
|
||||||
if r != io.EOF {
|
if !ok || !errors.Is(r, io.EOF) {
|
||||||
t.Error(r)
|
t.Error(r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -492,7 +493,7 @@ func TestClientCloseErr(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err, ok := c.Close().(CloseErr); !ok || !errors.Is(err.AgentErr, io.ErrUnexpectedEOF) {
|
if err, ok := c.Close().(CloseErr); !ok || !errors.Is(err.AgentErr, io.ErrUnexpectedEOF) { //nolint:errorlint
|
||||||
t.Error("unexpected close err")
|
t.Error("unexpected close err")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -659,7 +660,7 @@ func TestClientFinalizer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCallbackWaitHandler(t *testing.T) {
|
func TestCallbackWaitHandler(t *testing.T) {
|
||||||
h := callbackWaitHandlerPool.Get().(*callbackWaitHandler)
|
h := callbackWaitHandlerPool.Get().(*callbackWaitHandler) //nolint:forcetypeassert
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
h.setCallback(func(event Event) {})
|
h.setCallback(func(event Event) {})
|
||||||
go func() {
|
go func() {
|
||||||
@@ -847,7 +848,7 @@ func testClientDoConcurrent(t *testing.T, concurrency int) {
|
|||||||
for {
|
for {
|
||||||
readN, readErr := connL.Read(buf)
|
readN, readErr := connL.Read(buf)
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
if readErr == io.EOF {
|
if errors.Is(readErr, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
t.Error(readErr)
|
t.Error(readErr)
|
||||||
@@ -877,7 +878,6 @@ func testClientDoConcurrent(t *testing.T, concurrency int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DoConcurrent(t *testing.T) {
|
func TestClient_DoConcurrent(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
for _, concurrency := range []int{
|
for _, concurrency := range []int{
|
||||||
1, 5, 10, 25, 100, 500,
|
1, 5, 10, 25, 100, 500,
|
||||||
} {
|
} {
|
||||||
@@ -1288,7 +1288,8 @@ func TestClientRTOWriteErr(t *testing.T) {
|
|||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
if doErr := c.Do(MustBuild(response, BindingRequest), func(event Event) {
|
if doErr := c.Do(MustBuild(response, BindingRequest), func(event Event) {
|
||||||
if e, ok := event.Error.(StopErr); !ok {
|
var e StopErr
|
||||||
|
if !errors.As(event.Error, &e) {
|
||||||
t.Error(event.Error)
|
t.Error(event.Error)
|
||||||
} else {
|
} else {
|
||||||
if !errors.Is(e.Err, agentStopErr) {
|
if !errors.Is(e.Err, agentStopErr) {
|
||||||
|
@@ -205,7 +205,8 @@ func parse(msg *stun.Message) (ret struct {
|
|||||||
respOrigin *stun.ResponseOrigin
|
respOrigin *stun.ResponseOrigin
|
||||||
mappedAddr *stun.MappedAddress
|
mappedAddr *stun.MappedAddress
|
||||||
software *stun.Software
|
software *stun.Software
|
||||||
}) {
|
},
|
||||||
|
) {
|
||||||
ret.mappedAddr = &stun.MappedAddress{}
|
ret.mappedAddr = &stun.MappedAddress{}
|
||||||
ret.xorAddr = &stun.XORMappedAddress{}
|
ret.xorAddr = &stun.XORMappedAddress{}
|
||||||
ret.respOrigin = &stun.ResponseOrigin{}
|
ret.respOrigin = &stun.ResponseOrigin{}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
@@ -3,6 +3,7 @@ package stun
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
// DecodeErr records an error and place when it is occurred.
|
// DecodeErr records an error and place when it is occurred.
|
||||||
|
// nolint:errname
|
||||||
type DecodeErr struct {
|
type DecodeErr struct {
|
||||||
Place DecodeErrPlace
|
Place DecodeErrPlace
|
||||||
Message string
|
Message string
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
package stun
|
package stun
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestDecodeErr_IsInvalidCookie(t *testing.T) {
|
func TestDecodeErr_IsInvalidCookie(t *testing.T) {
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
@@ -16,8 +19,8 @@ func TestDecodeErr_IsInvalidCookie(t *testing.T) {
|
|||||||
if err.Error() != expected {
|
if err.Error() != expected {
|
||||||
t.Error(err, "!=", expected)
|
t.Error(err, "!=", expected)
|
||||||
}
|
}
|
||||||
dErr, ok := err.(*DecodeErr)
|
var dErr *DecodeErr
|
||||||
if !ok {
|
if !errors.As(err, &dErr) {
|
||||||
t.Error("not decode error")
|
t.Error("not decode error")
|
||||||
}
|
}
|
||||||
if !dErr.IsInvalidCookie() {
|
if !dErr.IsInvalidCookie() {
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
@@ -108,7 +108,7 @@ func TestHelpersErrorHandling(t *testing.T) {
|
|||||||
MustBuild(NewTransactionIDSetter(transactionID{}))
|
MustBuild(NewTransactionIDSetter(transactionID{}))
|
||||||
})
|
})
|
||||||
defer func() {
|
defer func() {
|
||||||
if p := recover(); !errors.Is(p.(error), e.Err) {
|
if p, ok := recover().(error); !ok || !errors.Is(p, e.Err) {
|
||||||
t.Errorf("%s != %s",
|
t.Errorf("%s != %s",
|
||||||
p, e.Err,
|
p, e.Err,
|
||||||
)
|
)
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
@@ -57,7 +57,7 @@ func (h *hmac) Sum(in []byte) []byte {
|
|||||||
in = h.inner.Sum(in)
|
in = h.inner.Sum(in)
|
||||||
|
|
||||||
if h.marshaled {
|
if h.marshaled {
|
||||||
if err := h.outer.(marshalable).UnmarshalBinary(h.opad); err != nil {
|
if err := h.outer.(marshalable).UnmarshalBinary(h.opad); err != nil { //nolint:forcetypeassert
|
||||||
panic(err) // nolint
|
panic(err) // nolint
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -77,7 +77,7 @@ func (h *hmac) BlockSize() int { return h.inner.BlockSize() }
|
|||||||
|
|
||||||
func (h *hmac) Reset() {
|
func (h *hmac) Reset() {
|
||||||
if h.marshaled {
|
if h.marshaled {
|
||||||
if err := h.inner.(marshalable).UnmarshalBinary(h.ipad); err != nil {
|
if err := h.inner.(marshalable).UnmarshalBinary(h.ipad); err != nil { //nolint:forcetypeassert
|
||||||
panic(err) // nolint
|
panic(err) // nolint
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@@ -552,7 +552,7 @@ func TestHMAC(t *testing.T) {
|
|||||||
// Third and fourth iteration: make sure hmac works on
|
// Third and fourth iteration: make sure hmac works on
|
||||||
// hashes without MarshalBinary/UnmarshalBinary
|
// hashes without MarshalBinary/UnmarshalBinary
|
||||||
if j == 1 {
|
if j == 1 {
|
||||||
h = New(func() hash.Hash { return justHash{tt.hash()} }, tt.key) //nolint: scopecheck
|
h = New(func() hash.Hash { return justHash{tt.hash()} }, tt.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ var hmacSHA1Pool = &sync.Pool{ // nolint:gochecknoglobals
|
|||||||
|
|
||||||
// AcquireSHA1 returns new HMAC from pool.
|
// AcquireSHA1 returns new HMAC from pool.
|
||||||
func AcquireSHA1(key []byte) hash.Hash {
|
func AcquireSHA1(key []byte) hash.Hash {
|
||||||
h := hmacSHA1Pool.Get().(*hmac)
|
h := hmacSHA1Pool.Get().(*hmac) //nolint:forcetypeassert
|
||||||
assertHMACSize(h, sha1.Size, sha1.BlockSize)
|
assertHMACSize(h, sha1.Size, sha1.BlockSize)
|
||||||
h.resetTo(key)
|
h.resetTo(key)
|
||||||
return h
|
return h
|
||||||
@@ -51,7 +51,7 @@ func AcquireSHA1(key []byte) hash.Hash {
|
|||||||
|
|
||||||
// PutSHA1 puts h to pool.
|
// PutSHA1 puts h to pool.
|
||||||
func PutSHA1(h hash.Hash) {
|
func PutSHA1(h hash.Hash) {
|
||||||
hm := h.(*hmac)
|
hm := h.(*hmac) //nolint:forcetypeassert
|
||||||
assertHMACSize(hm, sha1.Size, sha1.BlockSize)
|
assertHMACSize(hm, sha1.Size, sha1.BlockSize)
|
||||||
hmacSHA1Pool.Put(hm)
|
hmacSHA1Pool.Put(hm)
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ var hmacSHA256Pool = &sync.Pool{ // nolint:gochecknoglobals
|
|||||||
|
|
||||||
// AcquireSHA256 returns new HMAC from SHA256 pool.
|
// AcquireSHA256 returns new HMAC from SHA256 pool.
|
||||||
func AcquireSHA256(key []byte) hash.Hash {
|
func AcquireSHA256(key []byte) hash.Hash {
|
||||||
h := hmacSHA256Pool.Get().(*hmac)
|
h := hmacSHA256Pool.Get().(*hmac) //nolint:forcetypeassert
|
||||||
assertHMACSize(h, sha256.Size, sha256.BlockSize)
|
assertHMACSize(h, sha256.Size, sha256.BlockSize)
|
||||||
h.resetTo(key)
|
h.resetTo(key)
|
||||||
return h
|
return h
|
||||||
@@ -73,7 +73,7 @@ func AcquireSHA256(key []byte) hash.Hash {
|
|||||||
|
|
||||||
// PutSHA256 puts h to SHA256 pool.
|
// PutSHA256 puts h to SHA256 pool.
|
||||||
func PutSHA256(h hash.Hash) {
|
func PutSHA256(h hash.Hash) {
|
||||||
hm := h.(*hmac)
|
hm := h.(*hmac) //nolint:forcetypeassert
|
||||||
assertHMACSize(hm, sha256.Size, sha256.BlockSize)
|
assertHMACSize(hm, sha256.Size, sha256.BlockSize)
|
||||||
hmacSHA256Pool.Put(hm)
|
hmacSHA256Pool.Put(hm)
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ func BenchmarkHMACSHA1_512_Pool(b *testing.B) {
|
|||||||
func TestHMACReset(t *testing.T) {
|
func TestHMACReset(t *testing.T) {
|
||||||
for i, tt := range hmacTests() {
|
for i, tt := range hmacTests() {
|
||||||
h := New(tt.hash, tt.key)
|
h := New(tt.hash, tt.key)
|
||||||
h.(*hmac).resetTo(tt.key)
|
h.(*hmac).resetTo(tt.key) //nolint:forcetypeassert
|
||||||
if s := h.Size(); s != tt.size {
|
if s := h.Size(); s != tt.size {
|
||||||
t.Errorf("Size: got %v, want %v", s, tt.size)
|
t.Errorf("Size: got %v, want %v", s, tt.size)
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ func TestHMACPool_SHA256(t *testing.T) { // nolint:dupl
|
|||||||
func TestAssertBlockSize(t *testing.T) {
|
func TestAssertBlockSize(t *testing.T) {
|
||||||
t.Run("Positive", func(t *testing.T) {
|
t.Run("Positive", func(t *testing.T) {
|
||||||
h := AcquireSHA1(make([]byte, 0, 1024))
|
h := AcquireSHA1(make([]byte, 0, 1024))
|
||||||
assertHMACSize(h.(*hmac), sha1.Size, sha1.BlockSize)
|
assertHMACSize(h.(*hmac), sha1.Size, sha1.BlockSize) //nolint:forcetypeassert
|
||||||
})
|
})
|
||||||
t.Run("Negative", func(t *testing.T) {
|
t.Run("Negative", func(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -148,6 +148,6 @@ func TestAssertBlockSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
h := AcquireSHA256(make([]byte, 0, 1024))
|
h := AcquireSHA256(make([]byte, 0, 1024))
|
||||||
assertHMACSize(h.(*hmac), sha1.Size, sha1.BlockSize)
|
assertHMACSize(h.(*hmac), sha1.Size, sha1.BlockSize) //nolint:forcetypeassert
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !race
|
||||||
// +build !race
|
// +build !race
|
||||||
|
|
||||||
package testutil
|
package testutil
|
||||||
|
@@ -450,7 +450,7 @@ func (c MessageClass) String() string {
|
|||||||
case ClassErrorResponse:
|
case ClassErrorResponse:
|
||||||
return "error response"
|
return "error response"
|
||||||
default:
|
default:
|
||||||
panic("unknown message class") // nolint: never happens unless wrongly casted
|
panic("unknown message class") // nolint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
@@ -191,12 +192,12 @@ func TestMessage_AttrLengthLessThanHeader(t *testing.T) {
|
|||||||
mDecoded := New()
|
mDecoded := New()
|
||||||
binary.BigEndian.PutUint16(m.Raw[2:4], 2) // rewrite to bad length
|
binary.BigEndian.PutUint16(m.Raw[2:4], 2) // rewrite to bad length
|
||||||
_, err := mDecoded.ReadFrom(bytes.NewReader(m.Raw[:20+2]))
|
_, err := mDecoded.ReadFrom(bytes.NewReader(m.Raw[:20+2]))
|
||||||
switch e := err.(type) {
|
var e *DecodeErr
|
||||||
case *DecodeErr:
|
if errors.As(err, &e) {
|
||||||
if !e.IsPlace(DecodeErrPlace{"attribute", "header"}) {
|
if !e.IsPlace(DecodeErrPlace{"attribute", "header"}) {
|
||||||
t.Error(e, "bad place")
|
t.Error(e, "bad place")
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
t.Error(err, "should be bad format")
|
t.Error(err, "should be bad format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,12 +221,12 @@ func TestMessage_AttrSizeLessThanLength(t *testing.T) {
|
|||||||
bin.PutUint16(m.Raw[2:4], 5) // rewrite to bad length
|
bin.PutUint16(m.Raw[2:4], 5) // rewrite to bad length
|
||||||
mDecoded := New()
|
mDecoded := New()
|
||||||
_, err := mDecoded.ReadFrom(bytes.NewReader(m.Raw[:20+5]))
|
_, err := mDecoded.ReadFrom(bytes.NewReader(m.Raw[:20+5]))
|
||||||
switch e := err.(type) {
|
var e *DecodeErr
|
||||||
case *DecodeErr:
|
if errors.As(err, &e) {
|
||||||
if !e.IsPlace(DecodeErrPlace{"attribute", "value"}) {
|
if !e.IsPlace(DecodeErrPlace{"attribute", "value"}) {
|
||||||
t.Error(e, "bad place")
|
t.Error(e, "bad place")
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
t.Error(err, "should be bad format")
|
t.Error(err, "should be bad format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,7 +583,7 @@ func TestMessageFromBrowsers(t *testing.T) {
|
|||||||
m := New()
|
m := New()
|
||||||
for {
|
for {
|
||||||
line, err := reader.Read()
|
line, err := reader.Read()
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -34,7 +34,7 @@ func NewUDPServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// necessary for ipv6
|
// necessary for ipv6
|
||||||
address := fmt.Sprintf("%s:%d", ip, udpConn.LocalAddr().(*net.UDPAddr).Port)
|
address := fmt.Sprintf("%s:%d", ip, udpConn.LocalAddr().(*net.UDPAddr).Port) //nolint:forcetypeassert
|
||||||
serverAddr, err := net.ResolveUDPAddr(network, address)
|
serverAddr, err := net.ResolveUDPAddr(network, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to resolve stun host: %s: %w", address, err)
|
return nil, nil, fmt.Errorf("failed to resolve stun host: %s: %w", address, err)
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !js
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package stun
|
package stun
|
||||||
|
Reference in New Issue
Block a user