Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ linters:
- maintidx # maintidx measures the maintainability index of each function.
- makezero # Finds slice declarations with non-zero initial length
- misspell # Finds commonly misspelled English words in comments
- modernize # Replace and suggests simplifications to code
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
Expand Down
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestInvalidContextOptions(t *testing.T) {
assert.ErrorIs(t, err, errTooShortSRTPAuthTag)
}

for n := 0; n < 4; n++ {
for n := range 4 {
_, err = CreateContext(masterKey, masterSalt, profile, RolloverCounterCarryingTransform(RCCMode2, 10),
SRTPAuthenticationTagLength(n))
assert.ErrorIs(t, err, errTooShortSRTPAuthTag)
Expand Down
2 changes: 1 addition & 1 deletion crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestXorBytesCTR(t *testing.T) {
require.NoError(t, err)

iv := make([]byte, block.BlockSize())
for i := 0; i < 1500; i++ {
for i := range 1500 {
src := make([]byte, i)
dst := make([]byte, i)
reference := make([]byte, i)
Expand Down
14 changes: 7 additions & 7 deletions key_derivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ func generateCounter(
copy(counter[:], sessionSalt)

counter[4] ^= byte(ssrc >> 24)
counter[5] ^= byte(ssrc >> 16)
counter[6] ^= byte(ssrc >> 8)
counter[7] ^= byte(ssrc)
counter[5] ^= byte(ssrc >> 16) //nolint:gosec
counter[6] ^= byte(ssrc >> 8) //nolint:gosec
counter[7] ^= byte(ssrc) //nolint:gosec
counter[8] ^= byte(rolloverCounter >> 24)
counter[9] ^= byte(rolloverCounter >> 16)
counter[10] ^= byte(rolloverCounter >> 8)
counter[11] ^= byte(rolloverCounter)
counter[9] ^= byte(rolloverCounter >> 16) //nolint:gosec
counter[10] ^= byte(rolloverCounter >> 8) //nolint:gosec
counter[11] ^= byte(rolloverCounter) //nolint:gosec
counter[12] ^= byte(sequenceNumber >> 8)
counter[13] ^= byte(sequenceNumber)
counter[13] ^= byte(sequenceNumber) //nolint:gosec
Comment on lines +63 to +71

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can maybe add a comment to explain that it's a false positive or what linter we're suppressing.


return counter
}
2 changes: 1 addition & 1 deletion session_srtcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestSessionSRTCPReplayProtection(t *testing.T) {
// Generate test packets
var packets [][]byte
var expectedSSRC []uint32
for i := uint32(0); i < 0x100; i++ {
for i := range uint32(0x100) {
testPacket := &rtcp.PictureLossIndication{
MediaSSRC: testSSRC,
SenderSSRC: i,
Expand Down
12 changes: 0 additions & 12 deletions srtcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ func TestRTCPLifecycle(t *testing.T) {
}

for name, option := range options {
option := option
t.Run(name, func(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
encryptContext, err := CreateContext(testCase.masterKey, testCase.masterSalt, testCase.algo, option...)
Expand All @@ -151,7 +149,6 @@ func TestRTCPLifecycle(t *testing.T) {

func TestRTCPLifecycleInPlace(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
authTagLen, err := testCase.algo.AuthTagRTCPLen()
Expand Down Expand Up @@ -202,7 +199,6 @@ func TestRTCPLifecycleInPlace(t *testing.T) {
// Assert that passing a dst buffer that is too short doesn't result in a failure.
func TestRTCPLifecyclePartialAllocation(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
encryptHeader := &rtcp.Header{}
Expand Down Expand Up @@ -237,7 +233,6 @@ func TestRTCPLifecyclePartialAllocation(t *testing.T) {

func TestRTCPInvalidAuthTag(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
authTagLen, err := testCase.algo.AuthTagRTCPLen()
Expand Down Expand Up @@ -272,7 +267,6 @@ func TestRTCPInvalidAuthTag(t *testing.T) {

func TestRTCPReplayDetectorSeparation(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
decryptContext, err := CreateContext(
Expand Down Expand Up @@ -306,7 +300,6 @@ func getRTCPIndex(encrypted []byte, authTagLen int) uint32 {

func TestEncryptRTCPSeparation(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
encryptContext, err := CreateContext(testCase.masterKey, testCase.masterSalt, testCase.algo)
Expand Down Expand Up @@ -359,7 +352,6 @@ func TestEncryptRTCPSeparation(t *testing.T) {

func TestRTCPDecryptShortenedPacket(t *testing.T) {
for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
pkt := testCase.packets[0]
for i := 1; i < len(pkt.encrypted)-1; i++ {
Expand Down Expand Up @@ -486,7 +478,6 @@ func TestRTCPMaxPackets(t *testing.T) {
}

for caseName, testCase := range testCases {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
assertT := assert.New(t)
encryptContext, err := CreateContext(testCase.masterKey, testCase.masterSalt, testCase.algo)
Expand Down Expand Up @@ -571,7 +562,6 @@ func TestRTCPInvalidMKI(t *testing.T) {
mki2 := []byte{0x02, 0x03, 0x04, 0x05}

for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
encryptContext, err := CreateContext(
testCase.masterKey,
Expand Down Expand Up @@ -606,7 +596,6 @@ func TestRTCPHandleMultipleMKI(t *testing.T) { //nolint:cyclop
mki2 := []byte{0x02, 0x03, 0x04, 0x05}

for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
masterKey2 := make([]byte, len(testCase.masterKey))
copy(masterKey2, testCase.masterKey)
Expand Down Expand Up @@ -660,7 +649,6 @@ func TestRTCPSwitchMKI(t *testing.T) { //nolint:cyclop
mki2 := []byte{0x02, 0x03, 0x04, 0x05}

for caseName, testCase := range rtcpTestCases() {
testCase := testCase
t.Run(caseName, func(t *testing.T) {
masterKey2 := make([]byte, len(testCase.masterKey))
copy(masterKey2, testCase.masterKey)
Expand Down
2 changes: 1 addition & 1 deletion srtp_cipher_aes_cm_hmac_sha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package srtp

import ( //nolint:gci
import (
"crypto/aes"
"crypto/cipher"
"crypto/hmac"
Expand Down
7 changes: 2 additions & 5 deletions srtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ func TestRTPDecryptShotenedPacket(t *testing.T) {
"GCM": profileGCM,
}
for name, profile := range profiles {
profile := profile
t.Run(name, func(t *testing.T) {
for _, testCase := range rtpTestCases() {
decryptContext, err := buildTestContext(profile)
Expand Down Expand Up @@ -682,7 +681,6 @@ func TestRTPMaxPackets(t *testing.T) {
"GCM": profileGCM,
}
for name, profile := range profiles {
profile := profile
t.Run(name, func(t *testing.T) {
context, err := buildTestContext(profile)
assert.NoError(t, err)
Expand Down Expand Up @@ -724,7 +722,6 @@ func TestRTPBurstLossWithSetROC(t *testing.T) { //nolint:cyclop
"GCM": profileGCM,
}
for name, profile := range profiles {
profile := profile
t.Run(name, func(t *testing.T) {
assertT := assert.New(t)

Expand All @@ -746,8 +743,8 @@ func TestRTPBurstLossWithSetROC(t *testing.T) { //nolint:cyclop
pkt: rtp.Packet{
Payload: []byte{
byte(i >> 16),
byte(i >> 8),
byte(i),
byte(i >> 8), //nolint:gosec
byte(i), //nolint:gosec
},
Header: rtp.Header{
Marker: true,
Expand Down
Loading