Harmonize nolint directives

This commit is contained in:
Steffen Vogel
2023-04-12 09:50:14 +02:00
parent 2151fd82cc
commit 7c533756a6
32 changed files with 157 additions and 153 deletions

View File

@@ -60,7 +60,7 @@ func TestMappedAddress(t *testing.T) {
})
}
func TestMappedAddressV6(t *testing.T) { // nolint:dupl
func TestMappedAddressV6(t *testing.T) { //nolint:dupl
m := new(Message)
addr := &MappedAddress{
IP: net.ParseIP("::"),
@@ -88,7 +88,7 @@ func TestMappedAddressV6(t *testing.T) { // nolint:dupl
})
}
func TestAlternateServer(t *testing.T) { // nolint:dupl
func TestAlternateServer(t *testing.T) { //nolint:dupl
m := new(Message)
addr := &AlternateServer{
IP: net.ParseIP("122.12.34.5"),
@@ -116,7 +116,7 @@ func TestAlternateServer(t *testing.T) { // nolint:dupl
})
}
func TestOtherAddress(t *testing.T) { // nolint:dupl
func TestOtherAddress(t *testing.T) { //nolint:dupl
m := new(Message)
addr := &OtherAddress{
IP: net.ParseIP("122.12.34.5"),

View File

@@ -130,7 +130,7 @@ func TestAgent_GC(t *testing.T) {
)
gcDeadline := deadline.Add(-time.Second)
deadlineNotGC := gcDeadline.AddDate(0, 0, -1)
a.SetHandler(func(e Event) { // nolint:errcheck,gosec
a.SetHandler(func(e Event) { //nolint:errcheck,gosec
id := e.TransactionID
shouldTimeOut, found := shouldTimeOutID[id]
if !found {

View File

@@ -9,7 +9,7 @@ func BenchmarkMessage_GetNotFound(b *testing.B) {
m := New()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m.Get(AttrRealm) // nolint:errcheck,gosec
m.Get(AttrRealm) //nolint:errcheck,gosec
}
}
@@ -18,7 +18,7 @@ func BenchmarkMessage_Get(b *testing.B) {
m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7})
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m.Get(AttrUsername) // nolint:errcheck,gosec
m.Get(AttrUsername) //nolint:errcheck,gosec
}
}
@@ -42,12 +42,12 @@ func TestRawAttribute_AddTo(t *testing.T) {
func TestMessage_GetNoAllocs(t *testing.T) {
m := New()
NewSoftware("c").AddTo(m) // nolint:errcheck,gosec
NewSoftware("c").AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
t.Run("Default", func(t *testing.T) {
allocs := testing.AllocsPerRun(10, func() {
m.Get(AttrSoftware) // nolint:errcheck,gosec
m.Get(AttrSoftware) //nolint:errcheck,gosec
})
if allocs > 0 {
t.Error("allocated memory, but should not")
@@ -55,7 +55,7 @@ func TestMessage_GetNoAllocs(t *testing.T) {
})
t.Run("Not found", func(t *testing.T) {
allocs := testing.AllocsPerRun(10, func() {
m.Get(AttrOrigin) // nolint:errcheck,gosec
m.Get(AttrOrigin) //nolint:errcheck,gosec
})
if allocs > 0 {
t.Error("allocated memory, but should not")

View File

@@ -227,7 +227,7 @@ func (t *clientTransaction) handle(e Event) {
}
}
var clientTransactionPool = &sync.Pool{ // nolint:gochecknoglobals
var clientTransactionPool = &sync.Pool{ //nolint:gochecknoglobals
New: func() interface{} {
return &clientTransaction{
raw: make([]byte, 1500),
@@ -288,7 +288,8 @@ func (c *Client) SetRTO(rto time.Duration) {
// StopErr occurs when Client fails to stop transaction while
// processing error.
// nolint:errname
//
//nolint:errname
type StopErr struct {
Err error // value returned by Stop()
Cause error // error that caused Stop() call
@@ -299,7 +300,8 @@ func (e StopErr) Error() string {
}
// CloseErr indicates client close failure.
// nolint:errname
//
//nolint:errname
type CloseErr struct {
AgentErr error
ConnectionErr error
@@ -307,7 +309,7 @@ type CloseErr struct {
func sprintErr(err error) string {
if err == nil {
return "<nil>" // nolint:goconst
return "<nil>" //nolint:goconst
}
return err.Error()
}
@@ -339,7 +341,7 @@ func closedOrPanic(err error) {
if err == nil || errors.Is(err, ErrAgentClosed) {
return
}
panic(err) // nolint
panic(err) //nolint
}
type tickerCollector struct {
@@ -431,7 +433,7 @@ type callbackWaitHandler struct {
func (s *callbackWaitHandler) HandleEvent(e Event) {
s.cond.L.Lock()
if s.callback == nil {
panic("s.callback is nil") // nolint
panic("s.callback is nil") //nolint
}
s.callback(e)
s.processed = true
@@ -451,7 +453,7 @@ func (s *callbackWaitHandler) wait() {
func (s *callbackWaitHandler) setCallback(f func(event Event)) {
if f == nil {
panic("f is nil") // nolint
panic("f is nil") //nolint
}
s.cond.L.Lock()
s.callback = f
@@ -461,7 +463,7 @@ func (s *callbackWaitHandler) setCallback(f func(event Event)) {
s.cond.L.Unlock()
}
var callbackWaitHandlerPool = sync.Pool{ // nolint:gochecknoglobals
var callbackWaitHandlerPool = sync.Pool{ //nolint:gochecknoglobals
New: func() interface{} {
return &callbackWaitHandler{
cond: sync.NewCond(new(sync.Mutex)),
@@ -515,7 +517,7 @@ type buffer struct {
buf []byte
}
var bufferPool = &sync.Pool{ // nolint:gochecknoglobals
var bufferPool = &sync.Pool{ //nolint:gochecknoglobals
New: func() interface{} {
return &buffer{buf: make([]byte, 2048)}
},

View File

@@ -100,7 +100,7 @@ func BenchmarkClient_Do(b *testing.B) {
}
}()
m := New()
m.NewTransactionID() // nolint:errcheck,gosec
m.NewTransactionID() //nolint:errcheck,gosec
m.Encode()
for pb.Next() {
if err := client.Do(m, noopF); err != nil {
@@ -1479,7 +1479,7 @@ func TestClientImmediateTimeout(t *testing.T) {
}
gotReads <- struct{}{}
}()
c.Start(MustBuild(response, BindingRequest), func(e Event) { // nolint:errcheck,gosec
c.Start(MustBuild(response, BindingRequest), func(e Event) { //nolint:errcheck,gosec
if errors.Is(e.Error, ErrTransactionTimeOut) {
t.Error("unexpected error")
}

View File

@@ -21,17 +21,17 @@ import (
)
var (
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers") // nolint:gochecknoglobals
addr = flag.String("addr", "localhost", "target address") // nolint:gochecknoglobals
port = flag.Int("port", stun.DefaultPort, "target port") // nolint:gochecknoglobals
duration = flag.Duration("d", time.Minute, "benchmark duration") // nolint:gochecknoglobals
network = flag.String("net", "udp", "protocol to use (udp, tcp)") // nolint:gochecknoglobals
cpuProfile = flag.String("cpuprofile", "", "file output of pprof cpu profile") // nolint:gochecknoglobals
memProfile = flag.String("memprofile", "", "file output of pprof memory profile") // nolint:gochecknoglobals
realRand = flag.Bool("crypt", false, "use crypto/rand as random source") // nolint:gochecknoglobals
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers") //nolint:gochecknoglobals
addr = flag.String("addr", "localhost", "target address") //nolint:gochecknoglobals
port = flag.Int("port", stun.DefaultPort, "target port") //nolint:gochecknoglobals
duration = flag.Duration("d", time.Minute, "benchmark duration") //nolint:gochecknoglobals
network = flag.String("net", "udp", "protocol to use (udp, tcp)") //nolint:gochecknoglobals
cpuProfile = flag.String("cpuprofile", "", "file output of pprof cpu profile") //nolint:gochecknoglobals
memProfile = flag.String("memprofile", "", "file output of pprof memory profile") //nolint:gochecknoglobals
realRand = flag.Bool("crypt", false, "use crypto/rand as random source") //nolint:gochecknoglobals
)
func main() { // nolint:gocognit
func main() { //nolint:gocognit
flag.Parse()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
@@ -101,7 +101,7 @@ func main() { // nolint:gocognit
log.Fatal("rand.Read failed:", err)
}
} else {
mathRand.Read(req.TransactionID[:]) // nolint:gosec
mathRand.Read(req.TransactionID[:]) //nolint:gosec
}
req.Type = stun.BindingRequest
req.WriteHeader()

View File

@@ -78,7 +78,7 @@ func multiplex(conn *net.UDPConn, stunAddr net.Addr, stunConn io.Reader) {
}
}
var stunServer = flag.String("stun", "stun.l.google.com:19302", "STUN Server to use") // nolint:gochecknoglobals
var stunServer = flag.String("stun", "stun.l.google.com:19302", "STUN Server to use") //nolint:gochecknoglobals
func main() {
flag.Parse()

View File

@@ -27,10 +27,10 @@ func (c *stunServerConn) Close() error {
}
var (
addrStrPtr = flag.String("server", "stun.voip.blackberry.com:3478", "STUN server address") // nolint:gochecknoglobals
timeoutPtr = flag.Int("timeout", 3, "the number of seconds to wait for STUN server's response") // nolint:gochecknoglobals
verbose = flag.Int("verbose", 1, "the verbosity level") // nolint:gochecknoglobals
log logging.LeveledLogger // nolint:gochecknoglobals
addrStrPtr = flag.String("server", "stun.voip.blackberry.com:3478", "STUN server address") //nolint:gochecknoglobals
timeoutPtr = flag.Int("timeout", 3, "the number of seconds to wait for STUN server's response") //nolint:gochecknoglobals
verbose = flag.Int("verbose", 1, "the verbosity level") //nolint:gochecknoglobals
log logging.LeveledLogger //nolint:gochecknoglobals
)
const (
@@ -241,7 +241,7 @@ func parse(msg *stun.Message) (ret struct {
stun.AttrResponseOrigin,
stun.AttrMappedAddress,
stun.AttrSoftware:
break //nolint: staticcheck
break //nolint:staticcheck
default:
log.Debugf("\t%v (l=%v)", attr, attr.Length)
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/pion/stun"
)
var server = flag.String("server", "pion.ly:3478", "Stun server address") // nolint:gochecknoglobals
var server = flag.String("server", "pion.ly:3478", "Stun server address") //nolint:gochecknoglobals
const (
udp = "udp4"
@@ -23,7 +23,7 @@ const (
timeoutMillis = 500
)
func main() { // nolint:gocognit
func main() { //nolint:gocognit
flag.Parse()
srvAddr, err := net.ResolveUDPAddr(udp, *server)

View File

@@ -13,7 +13,7 @@ import (
func test(network string) {
addr := resolve(network)
fmt.Println("START", strings.ToUpper(addr.Network())) // nolint
fmt.Println("START", strings.ToUpper(addr.Network())) //nolint
var (
nonce stun.Nonce
realm stun.Realm
@@ -24,44 +24,44 @@ func test(network string) {
)
conn, err := net.Dial(addr.Network(), addr.String())
if err != nil {
log.Fatalln("failed to dial conn:", err) // nolint
log.Fatalln("failed to dial conn:", err) //nolint
}
var options []stun.ClientOption
if network == "tcp" {
// Switching to "NO-RTO" mode.
fmt.Println("using WithNoRetransmit for TCP") // nolint
fmt.Println("using WithNoRetransmit for TCP") //nolint
options = append(options, stun.WithNoRetransmit)
}
client, err := stun.NewClient(conn, options...)
if err != nil {
log.Fatal(err) // nolint
log.Fatal(err) //nolint
}
// First request should error.
request, err := stun.Build(stun.BindingRequest, stun.TransactionID, stun.Fingerprint)
if err != nil {
log.Fatalln("failed to build:", err) // nolint
log.Fatalln("failed to build:", err) //nolint
}
if err = client.Do(request, func(event stun.Event) {
if event.Error != nil {
log.Fatalln("got event with error:", event.Error) // nolint
log.Fatalln("got event with error:", event.Error) //nolint
}
response := event.Message
if response.Type != stun.BindingError {
log.Fatalln("bad message", response) // nolint
log.Fatalln("bad message", response) //nolint
}
var errCode stun.ErrorCodeAttribute
if codeErr := errCode.GetFrom(response); codeErr != nil {
log.Fatalln("failed to get error code:", codeErr) // nolint
log.Fatalln("failed to get error code:", codeErr) //nolint
}
if errCode.Code != stun.CodeUnauthorized {
log.Fatalln("unexpected error code:", errCode) // nolint
log.Fatalln("unexpected error code:", errCode) //nolint
}
if parseErr := response.Parse(&nonce, &realm); parseErr != nil {
log.Fatalln("failed to parse:", parseErr) // nolint
log.Fatalln("failed to parse:", parseErr) //nolint
}
fmt.Println("Got nonce", nonce, "and realm", realm) // nolint
fmt.Println("Got nonce", nonce, "and realm", realm) //nolint
}); err != nil {
log.Fatalln("failed to Do:", err) // nolint
log.Fatalln("failed to Do:", err) //nolint
}
// Authenticating and sending second request.
@@ -71,35 +71,35 @@ func test(network string) {
stun.Fingerprint,
)
if err != nil {
log.Fatalln(err) // nolint
log.Fatalln(err) //nolint
}
if err = client.Do(request, func(event stun.Event) {
if event.Error != nil {
log.Fatalln("got event with error:", event.Error) // nolint
log.Fatalln("got event with error:", event.Error) //nolint
}
response := event.Message
if response.Type != stun.BindingSuccess {
var errCode stun.ErrorCodeAttribute
if codeErr := errCode.GetFrom(response); codeErr != nil {
log.Fatalln("failed to get error code:", codeErr) // nolint
log.Fatalln("failed to get error code:", codeErr) //nolint
}
log.Fatalln("bad message", response, errCode) // nolint
log.Fatalln("bad message", response, errCode) //nolint
}
var xorMapped stun.XORMappedAddress
if err = response.Parse(&xorMapped); err != nil {
log.Fatalln("failed to parse xor mapped address:", err) // nolint
log.Fatalln("failed to parse xor mapped address:", err) //nolint
}
if conn.LocalAddr().String() != xorMapped.String() {
log.Fatalln(conn.LocalAddr(), "!=", xorMapped) // nolint
log.Fatalln(conn.LocalAddr(), "!=", xorMapped) //nolint
}
fmt.Println("OK", response, "GOT", xorMapped) // nolint
fmt.Println("OK", response, "GOT", xorMapped) //nolint
}); err != nil {
log.Fatalln("failed to Do:", err) // nolint
log.Fatalln("failed to Do:", err) //nolint
}
if err := client.Close(); err != nil {
log.Fatalln("failed to close client:", err) // nolint
log.Fatalln("failed to close client:", err) //nolint
}
fmt.Println("OK", strings.ToUpper(addr.Network())) // nolint
fmt.Println("OK", strings.ToUpper(addr.Network())) //nolint
}
func resolve(network string) net.Addr {
@@ -115,14 +115,14 @@ func resolve(network string) net.Addr {
case "tcp":
resolved, resolveErr = net.ResolveTCPAddr("tcp", addr)
default:
panic("unknown network") // nolint
panic("unknown network") //nolint
}
if resolveErr == nil {
return resolved
}
time.Sleep(time.Millisecond * 300 * time.Duration(i))
}
panic(resolveErr) // nolint
panic(resolveErr) //nolint
}
func main() {

View File

@@ -131,6 +131,7 @@ const (
CodePeerAddrFamilyMismatch ErrorCode = 443 // Peer Address Family Mismatch
)
//nolint:gocheckglobals
var errorReasons = map[ErrorCode][]byte{
CodeTryAlternate: []byte("Try Alternate"),
CodeBadRequest: []byte("Bad Request"),

View File

@@ -14,7 +14,7 @@ func BenchmarkErrorCode_AddTo(b *testing.B) {
m := New()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
CodeStaleNonce.AddTo(m) // nolint:errcheck,gosec
CodeStaleNonce.AddTo(m) //nolint:errcheck,gosec
m.Reset()
}
}
@@ -27,7 +27,7 @@ func BenchmarkErrorCodeAttribute_AddTo(b *testing.B) {
Reason: []byte("not found!"),
}
for i := 0; i < b.N; i++ {
a.AddTo(m) // nolint:errcheck,gosec
a.AddTo(m) //nolint:errcheck,gosec
m.Reset()
}
}
@@ -39,9 +39,9 @@ func BenchmarkErrorCodeAttribute_GetFrom(b *testing.B) {
Code: 404,
Reason: []byte("not found!"),
}
a.AddTo(m) // nolint:errcheck,gosec
a.AddTo(m) //nolint:errcheck,gosec
for i := 0; i < b.N; i++ {
a.GetFrom(m) // nolint:errcheck,gosec
a.GetFrom(m) //nolint:errcheck,gosec
}
}
@@ -65,7 +65,7 @@ func TestMessage_AddErrorCode(t *testing.T) {
copy(m.TransactionID[:], transactionID)
expectedCode := ErrorCode(438)
expectedReason := "Stale Nonce"
CodeStaleNonce.AddTo(m) // nolint:errcheck,gosec
CodeStaleNonce.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
mRes := New()

View File

@@ -3,7 +3,8 @@ package stun
import "errors"
// DecodeErr records an error and place when it is occurred.
// nolint:errname
//
//nolint:errname
type DecodeErr struct {
Place DecodeErrPlace
Message string

View File

@@ -19,10 +19,10 @@ var ErrFingerprintMismatch = errors.New("fingerprint check failed")
//
// m := New()
// Fingerprint.AddTo(m)
var Fingerprint FingerprintAttr // nolint:gochecknoglobals
var Fingerprint FingerprintAttr //nolint:gochecknoglobals
const (
fingerprintXORValue uint32 = 0x5354554e // nolint:staticcheck
fingerprintXORValue uint32 = 0x5354554e //nolint:staticcheck
fingerprintSize = 4 // 32 bit
)

View File

@@ -19,7 +19,7 @@ func BenchmarkFingerprint_AddTo(b *testing.B) {
addAttr(b, m, s)
b.SetBytes(int64(len(m.Raw)))
for i := 0; i < b.N; i++ {
Fingerprint.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
m.WriteLength()
m.Length -= attributeHeaderSize + fingerprintSize
m.Raw = m.Raw[:m.Length+messageHeaderSize]
@@ -31,7 +31,7 @@ func TestFingerprint_Check(t *testing.T) {
m := new(Message)
addAttr(t, m, NewSoftware("software"))
m.WriteHeader()
Fingerprint.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
if err := Fingerprint.Check(m); err != nil {
t.Error(err)
@@ -65,7 +65,7 @@ func BenchmarkFingerprint_Check(b *testing.B) {
addAttr(b, m, addr)
addAttr(b, m, s)
m.WriteHeader()
Fingerprint.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
b.SetBytes(int64(len(m.Raw)))
for i := 0; i < b.N; i++ {

View File

@@ -68,7 +68,7 @@ func (m *Message) Parse(getters ...Getter) error {
func MustBuild(setters ...Setter) *Message {
m, err := Build(setters...)
if err != nil {
panic(err) // nolint
panic(err) //nolint
}
return m
}

View File

@@ -19,14 +19,14 @@ func BenchmarkBuildOverhead(b *testing.B) {
b.ReportAllocs()
m := new(Message)
for i := 0; i < b.N; i++ {
m.Build(&t, &username, &nonce, &realm, &Fingerprint) // nolint:errcheck,gosec
m.Build(&t, &username, &nonce, &realm, &Fingerprint) //nolint:errcheck,gosec
}
})
b.Run("BuildNonPointer", func(b *testing.B) {
b.ReportAllocs()
m := new(Message)
for i := 0; i < b.N; i++ {
m.Build(t, username, nonce, realm, Fingerprint) // nolint:errcheck,gosec // nolint:errcheck,gosec
m.Build(t, username, nonce, realm, Fingerprint) //nolint:errcheck,gosec //nolint:errcheck,gosec
}
})
b.Run("Raw", func(b *testing.B) {
@@ -36,10 +36,10 @@ func BenchmarkBuildOverhead(b *testing.B) {
m.Reset()
m.WriteHeader()
m.SetType(t)
username.AddTo(m) // nolint:errcheck,gosec
nonce.AddTo(m) // nolint:errcheck,gosec
realm.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) // nolint:errcheck,gosec
username.AddTo(m) //nolint:errcheck,gosec
nonce.AddTo(m) //nolint:errcheck,gosec
realm.AddTo(m) //nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
}
})
}

View File

@@ -1,8 +1,8 @@
package stun
import ( // nolint:gci
"crypto/md5" // nolint:gosec
"crypto/sha1" // nolint:gosec
import ( //nolint:gci
"crypto/md5" //nolint:gosec
"crypto/sha1" //nolint:gosec
"errors"
"fmt"
"strings"
@@ -17,7 +17,7 @@ const credentialsSep = ":"
// credentials. Password, username, and realm must be SASL-prepared.
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
k := strings.Join([]string{username, realm, password}, credentialsSep)
h := md5.New() // nolint:gosec
h := md5.New() //nolint:gosec
fmt.Fprint(h, k)
return MessageIntegrity(h.Sum(nil))
}

View File

@@ -21,7 +21,7 @@ func TestMessageIntegrity_AddTo_Simple(t *testing.T) {
if err := i.AddTo(m); err != nil {
t.Error(err)
}
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
dM := new(Message)
dM.Raw = m.Raw
@@ -42,7 +42,7 @@ func TestMessageIntegrityWithFingerprint(t *testing.T) {
m := new(Message)
m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
m.WriteHeader()
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
i := NewShortTermIntegrity("pwd")
if i.String() != "KEY: 0x707764" {
t.Error("bad string", i)
@@ -81,7 +81,7 @@ func TestMessageIntegrity(t *testing.T) {
func TestMessageIntegrityBeforeFingerprint(t *testing.T) {
m := new(Message)
m.WriteHeader()
Fingerprint.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
i := NewShortTermIntegrity("password")
if err := i.AddTo(m); err == nil {
t.Error("should error")
@@ -106,7 +106,7 @@ func BenchmarkMessageIntegrity_AddTo(b *testing.B) {
func BenchmarkMessageIntegrity_Check(b *testing.B) {
m := new(Message)
m.Raw = make([]byte, 0, 1024)
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
integrity := NewShortTermIntegrity("password")
b.ReportAllocs()
m.WriteHeader()

View File

@@ -58,13 +58,13 @@ func (h *hmac) Sum(in []byte) []byte {
if h.marshaled {
if err := h.outer.(marshalable).UnmarshalBinary(h.opad); err != nil { //nolint:forcetypeassert
panic(err) // nolint
panic(err) //nolint
}
} else {
h.outer.Reset()
h.outer.Write(h.opad) //nolint: errcheck,gosec
h.outer.Write(h.opad) //nolint:errcheck,gosec
}
h.outer.Write(in[origLen:]) //nolint: errcheck,gosec
h.outer.Write(in[origLen:]) //nolint:errcheck,gosec
return h.outer.Sum(in[:origLen])
}
@@ -78,13 +78,13 @@ func (h *hmac) BlockSize() int { return h.inner.BlockSize() }
func (h *hmac) Reset() {
if h.marshaled {
if err := h.inner.(marshalable).UnmarshalBinary(h.ipad); err != nil { //nolint:forcetypeassert
panic(err) // nolint
panic(err) //nolint
}
return
}
h.inner.Reset()
h.inner.Write(h.ipad) //nolint: errcheck,gosec
h.inner.Write(h.ipad) //nolint:errcheck,gosec
// If the underlying hash is marshalable, we can save some time by
// saving a copy of the hash state now, and restoring it on future
@@ -107,7 +107,7 @@ func (h *hmac) Reset() {
}
h.outer.Reset()
h.outer.Write(h.opad) //nolint: errcheck,gosec
h.outer.Write(h.opad) //nolint:errcheck,gosec
omarshal, err := marshalableOuter.MarshalBinary()
if err != nil {
return
@@ -132,7 +132,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
hm.opad = make([]byte, blocksize)
if len(key) > blocksize {
// If key is too big, hash it.
hm.outer.Write(key) // nolint:errcheck,gosec
hm.outer.Write(key) //nolint:errcheck,gosec
key = hm.outer.Sum(nil)
}
copy(hm.ipad, key)
@@ -143,7 +143,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
for i := range hm.opad {
hm.opad[i] ^= 0x5c
}
hm.inner.Write(hm.ipad) //nolint: errcheck,gosec
hm.inner.Write(hm.ipad) //nolint:errcheck,gosec
return hm
}

View File

@@ -4,9 +4,9 @@
package hmac
import ( // nolint:gci
"crypto/md5" // nolint:gosec
"crypto/sha1" // nolint:gosec
import ( //nolint:gci
"crypto/md5" //nolint:gosec
"crypto/sha1" //nolint:gosec
"crypto/sha256"
"crypto/sha512"
"fmt"
@@ -405,7 +405,7 @@ func hmacTests() []hmacTest {
},
{
sha512.New384,
[]byte{ // nolint:dupl
[]byte{ //nolint:dupl
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -485,7 +485,7 @@ func hmacTests() []hmacTest {
},
{
sha512.New,
[]byte{ // nolint:dupl
[]byte{ //nolint:dupl
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -588,7 +588,7 @@ func BenchmarkHMACSHA256_1K(b *testing.B) {
h := New(sha256.New, key)
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
h.Write(buf) // nolint:errcheck,gosec
h.Write(buf) //nolint:errcheck,gosec
h.Reset()
mac := h.Sum(nil)
buf[0] = mac[0]
@@ -601,7 +601,7 @@ func BenchmarkHMACSHA256_32(b *testing.B) {
h := New(sha256.New, key)
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
h.Write(buf) // nolint:errcheck,gosec
h.Write(buf) //nolint:errcheck,gosec
h.Reset()
mac := h.Sum(nil)
buf[0] = mac[0]

View File

@@ -1,7 +1,7 @@
package hmac
import ( // nolint:gci
"crypto/sha1" // nolint:gosec
import ( //nolint:gci
"crypto/sha1" //nolint:gosec
"crypto/sha256"
"hash"
"sync"
@@ -18,7 +18,7 @@ func (h *hmac) resetTo(key []byte) {
if len(key) > blocksize {
// If key is too big, hash it.
h.outer.Write(key) // nolint:errcheck,gosec
h.outer.Write(key) //nolint:errcheck,gosec
key = h.outer.Sum(nil)
}
copy(h.ipad, key)
@@ -29,12 +29,12 @@ func (h *hmac) resetTo(key []byte) {
for i := range h.opad {
h.opad[i] ^= 0x5c
}
h.inner.Write(h.ipad) //nolint: errcheck,gosec
h.inner.Write(h.ipad) //nolint:errcheck,gosec
h.marshaled = false
}
var hmacSHA1Pool = &sync.Pool{ // nolint:gochecknoglobals
var hmacSHA1Pool = &sync.Pool{ //nolint:gochecknoglobals
New: func() interface{} {
h := New(sha1.New, make([]byte, sha1.BlockSize))
return h
@@ -56,7 +56,7 @@ func PutSHA1(h hash.Hash) {
hmacSHA1Pool.Put(hm)
}
var hmacSHA256Pool = &sync.Pool{ // nolint:gochecknoglobals
var hmacSHA256Pool = &sync.Pool{ //nolint:gochecknoglobals
New: func() interface{} {
h := New(sha256.New, make([]byte, sha256.BlockSize))
return h
@@ -82,8 +82,8 @@ func PutSHA256(h hash.Hash) {
//
// Put and Acquire functions are internal functions to project, so
// checking it via such assert is optimal.
func assertHMACSize(h *hmac, size, blocksize int) { //nolint: unparam
func assertHMACSize(h *hmac, size, blocksize int) { //nolint:unparam
if h.Size() != size || h.BlockSize() != blocksize {
panic("BUG: hmac size invalid") // nolint
panic("BUG: hmac size invalid") //nolint
}
}

View File

@@ -1,7 +1,7 @@
package hmac
import ( // nolint:gci
"crypto/sha1" // nolint:gosec
import ( //nolint:gci
"crypto/sha1" //nolint:gosec
"crypto/sha256"
"fmt"
"testing"
@@ -14,7 +14,7 @@ func BenchmarkHMACSHA1_512(b *testing.B) {
h := AcquireSHA1(key)
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
h.Write(buf) // nolint:errcheck,gosec
h.Write(buf) //nolint:errcheck,gosec
h.Reset()
mac := h.Sum(nil)
buf[0] = mac[0]
@@ -29,7 +29,7 @@ func BenchmarkHMACSHA1_512_Pool(b *testing.B) {
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
h := AcquireSHA1(key)
h.Write(buf) // nolint:errcheck,gosec
h.Write(buf) //nolint:errcheck,gosec
h.Reset()
mac := h.Sum(tBuf)
buf[0] = mac[0]
@@ -68,7 +68,7 @@ func TestHMACReset(t *testing.T) {
}
}
func TestHMACPool_SHA1(t *testing.T) { // nolint:dupl
func TestHMACPool_SHA1(t *testing.T) { //nolint:dupl
for i, tt := range hmacTests() {
if tt.blocksize != sha1.BlockSize || tt.size != sha1.Size {
continue
@@ -102,7 +102,7 @@ func TestHMACPool_SHA1(t *testing.T) { // nolint:dupl
}
}
func TestHMACPool_SHA256(t *testing.T) { // nolint:dupl
func TestHMACPool_SHA256(t *testing.T) { //nolint:dupl
for i, tt := range hmacTests() {
if tt.blocksize != sha256.BlockSize || tt.size != sha256.Size {
continue

View File

@@ -432,11 +432,11 @@ const (
// Common STUN message types.
var (
// Binding request message type.
BindingRequest = NewType(MethodBinding, ClassRequest) // nolint:gochecknoglobals
BindingRequest = NewType(MethodBinding, ClassRequest) //nolint:gochecknoglobals
// Binding success response message type
BindingSuccess = NewType(MethodBinding, ClassSuccessResponse) // nolint:gochecknoglobals
BindingSuccess = NewType(MethodBinding, ClassSuccessResponse) //nolint:gochecknoglobals
// Binding error response message type.
BindingError = NewType(MethodBinding, ClassErrorResponse) // nolint:gochecknoglobals
BindingError = NewType(MethodBinding, ClassErrorResponse) //nolint:gochecknoglobals
)
func (c MessageClass) String() string {
@@ -450,7 +450,7 @@ func (c MessageClass) String() string {
case ClassErrorResponse:
return "error response"
default:
panic("unknown message class") // nolint
panic("unknown message class") //nolint
}
}

View File

@@ -266,7 +266,7 @@ func BenchmarkMessage_WriteTo(b *testing.B) {
buf := new(bytes.Buffer)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m.WriteTo(buf) // nolint:errcheck,gosec
m.WriteTo(buf) //nolint:errcheck,gosec
buf.Reset()
}
}
@@ -502,7 +502,7 @@ func TestMessage_String(t *testing.T) {
func TestIsMessage(t *testing.T) {
m := New()
NewSoftware("software").AddTo(m) // nolint:errcheck,gosec
NewSoftware("software").AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
tt := [...]struct {
@@ -531,7 +531,7 @@ func BenchmarkIsMessage(b *testing.B) {
m := New()
m.Type = MessageType{Method: MethodBinding, Class: ClassRequest}
m.TransactionID = NewTransactionID()
NewSoftware("cydev/stun test").AddTo(m) // nolint:errcheck,gosec
NewSoftware("cydev/stun test").AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
b.SetBytes(int64(messageHeaderSize))
@@ -546,7 +546,7 @@ func BenchmarkIsMessage(b *testing.B) {
func loadData(tb testing.TB, name string) []byte {
name = filepath.Join("testdata", name)
f, err := os.Open(name) //nolint: gosec
f, err := os.Open(name) //nolint:gosec
if err != nil {
tb.Fatal(err)
}
@@ -634,7 +634,7 @@ func BenchmarkMessageFull(b *testing.B) {
}
m.WriteAttributes()
m.WriteHeader()
Fingerprint.AddTo(m) // nolint:errcheck,gosec
Fingerprint.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
m.Reset()
}
@@ -688,7 +688,7 @@ func TestMessage_Contains(t *testing.T) {
func ExampleMessage() {
buf := new(bytes.Buffer)
m := new(Message)
m.Build(BindingRequest, // nolint:errcheck,gosec
m.Build(BindingRequest, //nolint:errcheck,gosec
NewTransactionIDSetter([TransactionIDSize]byte{
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
}),
@@ -714,11 +714,11 @@ func ExampleMessage() {
decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw
// ReadFrom does not allocate internal buffer for reading from io.Reader,
// instead it uses m.Raw, expanding it length to capacity.
decoded.ReadFrom(buf) // nolint:errcheck,gosec
decoded.ReadFrom(buf) //nolint:errcheck,gosec
fmt.Println("has software:", decoded.Contains(AttrSoftware))
fmt.Println("has nonce:", decoded.Contains(AttrNonce))
var software Software
decoded.Parse(&software) // nolint:errcheck,gosec
decoded.Parse(&software) //nolint:errcheck,gosec
// Rule for Parse method is same as for Build.
fmt.Println("software:", software)
if err := Fingerprint.Check(decoded); err == nil {
@@ -901,7 +901,7 @@ func BenchmarkMessage_CloneTo(b *testing.B) {
}
b.SetBytes(int64(len(m.Raw)))
a := new(Message)
m.CloneTo(a) // nolint:errcheck,gosec
m.CloneTo(a) //nolint:errcheck,gosec
for i := 0; i < b.N; i++ {
if err := m.CloneTo(a); err != nil {
b.Fatal(err)
@@ -930,7 +930,7 @@ func TestMessage_AddTo(t *testing.T) {
if b.Equal(m) {
t.Fatal("should not be equal")
}
m.AddTo(b) // nolint:errcheck,gosec
m.AddTo(b) //nolint:errcheck,gosec
if !b.Equal(m) {
t.Fatal("should be equal")
}
@@ -948,7 +948,7 @@ func BenchmarkMessage_AddTo(b *testing.B) {
b.Fatal(err)
}
a := new(Message)
m.CloneTo(a) // nolint:errcheck,gosec
m.CloneTo(a) //nolint:errcheck,gosec
for i := 0; i < b.N; i++ {
if err := m.AddTo(a); err != nil {
b.Fatal(err)

View File

@@ -82,7 +82,7 @@ func TestRFC5769(t *testing.T) {
if err := r.GetFrom(m); err != nil {
t.Error(err)
}
if r.String() != "example.org" { // nolint:goconst
if r.String() != "example.org" { //nolint:goconst
t.Error("bad realm")
}
// checking HMAC

View File

@@ -17,12 +17,12 @@ import (
)
// bin is shorthand to binary.BigEndian.
var bin = binary.BigEndian // nolint:gochecknoglobals
var bin = binary.BigEndian //nolint:gochecknoglobals
func readFullOrPanic(r io.Reader, v []byte) int {
n, err := io.ReadFull(r, v)
if err != nil {
panic(err) // nolint
panic(err) //nolint
}
return n
}
@@ -30,7 +30,7 @@ func readFullOrPanic(r io.Reader, v []byte) int {
func writeOrPanic(w io.Writer, v []byte) int {
n, err := w.Write(v)
if err != nil {
panic(err) // nolint
panic(err) //nolint
}
return n
}

View File

@@ -30,7 +30,7 @@ func NewUDPServer(
udpConn, err := net.ListenUDP(network, &net.UDPAddr{IP: net.ParseIP(ip), Port: 0})
if err != nil {
t.Fatal(err) // nolint
t.Fatal(err)
}
// necessary for ipv6
@@ -68,7 +68,7 @@ func NewUDPServer(
select {
case err := <-errCh:
if err != nil {
t.Fatal(err) // nolint
t.Fatal(err) //nolint
return
}
default:
@@ -76,7 +76,7 @@ func NewUDPServer(
err := udpConn.Close()
if err != nil {
t.Fatal(err) // nolint
t.Fatal(err) //nolint
}
<-errCh

View File

@@ -74,7 +74,7 @@ func BenchmarkUsername_AddTo(b *testing.B) {
func BenchmarkUsername_GetFrom(b *testing.B) {
b.ReportAllocs()
m := new(Message)
Username("test").AddTo(m) // nolint:errcheck,gosec
Username("test").AddTo(m) //nolint:errcheck,gosec
var u Username
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -260,8 +260,8 @@ func BenchmarkNonce_GetFrom(b *testing.B) {
b.ReportAllocs()
m := New()
n := NewNonce("nonce")
n.AddTo(m) // nolint:errcheck,gosec
n.AddTo(m) //nolint:errcheck,gosec
for i := 0; i < b.N; i++ {
n.GetFrom(m) // nolint:errcheck,gosec
n.GetFrom(m) //nolint:errcheck,gosec
}
}

4
uri.go
View File

@@ -37,10 +37,10 @@ func ParseURI(rawURI string) (URI, error) {
return URI{}, urlParseErr
}
if u.Scheme != Scheme && u.Scheme != SchemeSecure {
return URI{}, fmt.Errorf("unknown uri scheme %q", u.Scheme) //nolint: goerr113
return URI{}, fmt.Errorf("unknown uri scheme %q", u.Scheme) //nolint:goerr113
}
if u.Opaque == "" {
return URI{}, errors.New("invalid uri format: expected opaque") //nolint: goerr113
return URI{}, errors.New("invalid uri format: expected opaque") //nolint:goerr113
}
// Using URL methods to split host.
u.Host = u.Opaque

View File

@@ -35,12 +35,12 @@ func TestParseURI(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
out, parseErr := ParseURI(tc.in) //nolint: scopelint
out, parseErr := ParseURI(tc.in) //nolint:scopelint
if parseErr != nil {
t.Fatal(parseErr)
}
if out != tc.out { //nolint: scopelint
t.Errorf("%s != %s", out, tc.out) //nolint: scopelint
if out != tc.out { //nolint:scopelint
t.Errorf("%s != %s", out, tc.out) //nolint:scopelint
}
})
}
@@ -63,7 +63,7 @@ func TestParseURI(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
_, parseErr := ParseURI(tc.in) //nolint: scopelint
_, parseErr := ParseURI(tc.in) //nolint:scopelint
if parseErr == nil {
t.Fatal("should fail, but did not")
}
@@ -109,8 +109,8 @@ func TestURI_String(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
if v := tc.uri.String(); v != tc.out { //nolint: scopelint
t.Errorf("%q != %q", v, tc.out) //nolint: scopelint
if v := tc.uri.String(); v != tc.out { //nolint:scopelint
t.Errorf("%q != %q", v, tc.out) //nolint:scopelint
}
})
}

View File

@@ -20,7 +20,7 @@ func BenchmarkXORMappedAddress_AddTo(b *testing.B) {
ip := net.ParseIP("192.168.1.32")
for i := 0; i < b.N; i++ {
addr := &XORMappedAddress{IP: ip, Port: 3654}
addr.AddTo(m) // nolint:errcheck,gosec
addr.AddTo(m) //nolint:errcheck,gosec
m.Reset()
}
}
@@ -107,7 +107,7 @@ func TestXORMappedAddress_GetFrom_Invalid(t *testing.T) {
addr.IP = expectedIP
addr.Port = expectedPort
addr.AddTo(m) // nolint:errcheck,gosec
addr.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
mRes := New()
@@ -165,7 +165,7 @@ func TestXORMappedAddress_AddTo_IPv6(t *testing.T) {
IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"),
Port: 21254,
}
addr.AddTo(m) // nolint:errcheck,gosec
addr.AddTo(m) //nolint:errcheck,gosec
m.WriteHeader()
mRes := New()