Skip to content

Commit

Permalink
Fix new golangci-lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Apr 12, 2023
1 parent eb487e0 commit e754b8a
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ func TestALPNExtension(t *testing.T) {
SupportedProtocols: test.ServerProtocolNameList,
}
if _, err2 := testServer(ctx2, cb2, conf, true); !errors.Is(err2, context.Canceled) {
if test.ExpectAlertFromServer {
if test.ExpectAlertFromServer { //nolint
// Assert the error type?
} else {
t.Error(err2)
Expand Down
4 changes: 2 additions & 2 deletions flight0handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pion/dtls/v2/pkg/protocol/handshake"
)

func flight0Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
func flight0Parse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
seq, msgs, ok := cache.fullPullMap(0, state.cipherSuite,
handshakeCachePullRule{handshake.TypeClientHello, cfg.initialEpoch, true, false},
)
Expand Down Expand Up @@ -113,7 +113,7 @@ func handleHelloResume(sessionID []byte, state *State, cfg *handshakeConfig, nex
return next, nil, nil
}

func flight0Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight0Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
// Initialize
if !cfg.insecureSkipHelloVerify {
state.cookie = make([]byte, cookieLength)
Expand Down
2 changes: 1 addition & 1 deletion flight1handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func flight1Parse(ctx context.Context, c flightConn, state *State, cache *handsh
return 0, &alert.Alert{Level: alert.Fatal, Description: alert.InternalError}, nil
}

func flight1Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight1Generate(c flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
var zeroEpoch uint16
state.localEpoch.Store(zeroEpoch)
state.remoteEpoch.Store(zeroEpoch)
Expand Down
2 changes: 1 addition & 1 deletion flight2handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func flight2Parse(ctx context.Context, c flightConn, state *State, cache *handsh
return flight4, nil, nil
}

func flight2Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight2Generate(_ flightConn, state *State, _ *handshakeCache, _ *handshakeConfig) ([]*packet, *alert.Alert, error) {
state.handshakeSendSequence = 0
return []*packet{
{
Expand Down
2 changes: 1 addition & 1 deletion flight3handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func handleServerKeyExchange(_ flightConn, state *State, cfg *handshakeConfig, h
return nil, nil //nolint:nilnil
}

func flight3Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight3Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
extensions := []extension.Extension{
&extension.SupportedSignatureAlgorithms{
SignatureHashAlgorithms: cfg.localSignatureSchemes,
Expand Down
4 changes: 2 additions & 2 deletions flight4bhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pion/dtls/v2/pkg/protocol/recordlayer"
)

func flight4bParse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
func flight4bParse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
_, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence, state.cipherSuite,
handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, true, false},
)
Expand Down Expand Up @@ -44,7 +44,7 @@ func flight4bParse(ctx context.Context, c flightConn, state *State, cache *hands
return flight4b, nil, nil
}

func flight4bGenerate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight4bGenerate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
var pkts []*packet

extensions := []extension.Extension{&extension.RenegotiationInfo{
Expand Down
2 changes: 1 addition & 1 deletion flight4handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func flight4Parse(ctx context.Context, c flightConn, state *State, cache *handsh
return flight6, nil, nil
}

func flight4Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight4Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
extensions := []extension.Extension{&extension.RenegotiationInfo{
RenegotiatedConnection: 0,
}}
Expand Down
4 changes: 2 additions & 2 deletions flight4handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (

type flight4TestMockFlightConn struct{}

func (f *flight4TestMockFlightConn) notify(ctx context.Context, level alert.Level, desc alert.Description) error {
func (f *flight4TestMockFlightConn) notify(context.Context, alert.Level, alert.Description) error {
return nil
}
func (f *flight4TestMockFlightConn) writePackets(context.Context, []*packet) error { return nil }
func (f *flight4TestMockFlightConn) recvHandshake() <-chan chan struct{} { return nil }
func (f *flight4TestMockFlightConn) setLocalEpoch(epoch uint16) {}
func (f *flight4TestMockFlightConn) setLocalEpoch(uint16) {}
func (f *flight4TestMockFlightConn) handleQueuedPackets(context.Context) error { return nil }
func (f *flight4TestMockFlightConn) sessionKey() []byte { return nil }

Expand Down
4 changes: 2 additions & 2 deletions flight5bhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pion/dtls/v2/pkg/protocol/recordlayer"
)

func flight5bParse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
func flight5bParse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
_, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence-1, state.cipherSuite,
handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, false, false},
)
Expand All @@ -27,7 +27,7 @@ func flight5bParse(ctx context.Context, c flightConn, state *State, cache *hands
return flight5b, nil, nil
}

func flight5bGenerate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { //nolint:gocognit
func flight5bGenerate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { //nolint:gocognit
var pkts []*packet

pkts = append(pkts,
Expand Down
2 changes: 1 addition & 1 deletion flight5handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/pion/dtls/v2/pkg/protocol/recordlayer"
)

func flight5Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
func flight5Parse(_ context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
_, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence, state.cipherSuite,
handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, false, false},
)
Expand Down
4 changes: 2 additions & 2 deletions flight6handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pion/dtls/v2/pkg/protocol/recordlayer"
)

func flight6Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
func flight6Parse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) {
_, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence-1, state.cipherSuite,
handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, true, false},
)
Expand All @@ -27,7 +27,7 @@ func flight6Parse(ctx context.Context, c flightConn, state *State, cache *handsh
return flight6, nil, nil
}

func flight6Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
func flight6Generate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) {
var pkts []*packet

pkts = append(pkts,
Expand Down
6 changes: 3 additions & 3 deletions handshaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ func (c *flightTestConn) setLocalEpoch(epoch uint16) {
c.epoch = epoch
}

func (c *flightTestConn) notify(ctx context.Context, level alert.Level, desc alert.Description) error {
func (c *flightTestConn) notify(context.Context, alert.Level, alert.Description) error {
return nil
}

func (c *flightTestConn) writePackets(ctx context.Context, pkts []*packet) error {
func (c *flightTestConn) writePackets(_ context.Context, pkts []*packet) error {
time.Sleep(c.delay)
for _, p := range pkts {
if c.filter != nil && !c.filter(p) {
Expand Down Expand Up @@ -436,7 +436,7 @@ func (c *flightTestConn) writePackets(ctx context.Context, pkts []*packet) error
return nil
}

func (c *flightTestConn) handleQueuedPackets(ctx context.Context) error {
func (c *flightTestConn) handleQueuedPackets(context.Context) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/crypto/ccm/ccm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ func TestRFC3610Vectors(t *testing.T) {
}

if len(cases) != 24 {
t.Fatalf("Expected %d test cases, got: %d", 24, len(cases))
t.FailNow()
t.Fatalf("Expected %d test cases, got: %d", 24, len(cases)) //nolint:revive
t.FailNow() //nolint:revive
}

for idx, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/ciphersuite/ccm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c *CCM) Decrypt(in []byte) ([]byte, error) {
additionalData := generateAEADAdditionalData(&h, len(out)-int(c.tagLen))
out, err = c.remoteCCM.Open(out[:0], nonce, out, additionalData)
if err != nil {
return nil, fmt.Errorf("%w: %v", errDecryptPacket, err)
return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) //nolint:errorlint
}
return append(in[:recordlayer.HeaderSize], out...), nil
}
2 changes: 1 addition & 1 deletion pkg/crypto/ciphersuite/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (g *GCM) Decrypt(in []byte) ([]byte, error) {
additionalData := generateAEADAdditionalData(&h, len(out)-gcmTagLength)
out, err = g.remoteGCM.Open(out[:0], nonce, out, additionalData)
if err != nil {
return nil, fmt.Errorf("%w: %v", errDecryptPacket, err)
return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) //nolint:errorlint
}
return append(in[:recordlayer.HeaderSize], out...), nil
}
2 changes: 1 addition & 1 deletion pkg/crypto/clientcertificate/client_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package clientcertificate
// Type is used to communicate what
// type of certificate is being transported
//
//https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-2
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-2
type Type byte

// ClientCertificateType enums
Expand Down
10 changes: 5 additions & 5 deletions pkg/crypto/prf/prf.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ func ellipticCurvePreMasterSecret(publicKey, privateKey []byte, c1, c2 ellipticS
// specify a PRF and, in general, SHOULD use the TLS PRF with SHA-256 or a
// stronger standard hash function.
//
// P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
// HMAC_hash(secret, A(2) + seed) +
// HMAC_hash(secret, A(3) + seed) + ...
// P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
// HMAC_hash(secret, A(2) + seed) +
// HMAC_hash(secret, A(3) + seed) + ...
//
// A() is defined as:
//
// A(0) = seed
// A(i) = HMAC_hash(secret, A(i-1))
// A(0) = seed
// A(i) = HMAC_hash(secret, A(i-1))
//
// P_hash can be iterated as many times as necessary to produce the
// required quantity of data. For example, if P_SHA256 is being used to
Expand Down
20 changes: 10 additions & 10 deletions pkg/protocol/handshake/message_hello_verify_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (

// MessageHelloVerifyRequest is as follows:
//
// struct {
// ProtocolVersion server_version;
// opaque cookie<0..2^8-1>;
// } HelloVerifyRequest;
// struct {
// ProtocolVersion server_version;
// opaque cookie<0..2^8-1>;
// } HelloVerifyRequest;
//
// The HelloVerifyRequest message type is hello_verify_request(3).
// The HelloVerifyRequest message type is hello_verify_request(3).
//
// When the client sends its ClientHello message to the server, the server
// MAY respond with a HelloVerifyRequest message. This message contains
// a stateless cookie generated using the technique of [PHOTURIS]. The
// client MUST retransmit the ClientHello with the cookie added.
// When the client sends its ClientHello message to the server, the server
// MAY respond with a HelloVerifyRequest message. This message contains
// a stateless cookie generated using the technique of [PHOTURIS]. The
// client MUST retransmit the ClientHello with the cookie added.
//
// https://tools.ietf.org/html/rfc6347#section-4.2.1
// https://tools.ietf.org/html/rfc6347#section-4.2.1
type MessageHelloVerifyRequest struct {
Version protocol.Version
Cookie []byte
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/handshake/message_server_hello_done.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ func (m *MessageServerHelloDone) Marshal() ([]byte, error) {
}

// Unmarshal populates the message from encoded data
func (m *MessageServerHelloDone) Unmarshal(data []byte) error {
func (m *MessageServerHelloDone) Unmarshal([]byte) error {
return nil
}
6 changes: 3 additions & 3 deletions resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ func (b *backupConn) RemoteAddr() net.Addr {
return nil
}

func (b *backupConn) SetDeadline(t time.Time) error {
func (b *backupConn) SetDeadline(time.Time) error {
return nil
}

func (b *backupConn) SetReadDeadline(t time.Time) error {
func (b *backupConn) SetReadDeadline(time.Time) error {
return nil
}

func (b *backupConn) SetWriteDeadline(t time.Time) error {
func (b *backupConn) SetWriteDeadline(time.Time) error {
return nil
}
6 changes: 2 additions & 4 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ func (s *State) UnmarshalBinary(data []byte) error {
}

s.deserialize(serialized)
if err := s.initCipherSuite(); err != nil {
return err
}
return nil

return s.initCipherSuite()
}

// ExportKeyingMaterial returns length bytes of exported key material in a new
Expand Down

0 comments on commit e754b8a

Please sign in to comment.