Skip to content

Commit

Permalink
Switch udp_mux_test to use sha256 instead of sha1 (#733)
Browse files Browse the repository at this point in the history
Minor change to this test to stop using sha1 and remove the linter
exceptions.

Co-authored-by: Daniel Kessler <[email protected]>
  • Loading branch information
dkess and Daniel Kessler authored Sep 23, 2024
1 parent 2d9be9b commit 1f9684c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions udp_mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package ice

import (
"crypto/rand"
"crypto/sha1" //nolint:gosec
"crypto/sha256"
"encoding/binary"
"net"
"sync"
Expand Down Expand Up @@ -216,12 +216,12 @@ func testMuxConnectionPair(t *testing.T, pktConn net.PacketConn, remoteConn *net
for written := 0; written < targetSize; {
buf := make([]byte, receiveMTU)
// Byte 0-4: sequence
// Bytes 4-24: sha1 checksum
// Bytes2 4-mtu: random data
_, err := rand.Read(buf[24:])
// Bytes 4-36: sha256 checksum
// Bytes2 36-mtu: random data
_, err := rand.Read(buf[36:])
require.NoError(t, err)
h := sha1.Sum(buf[24:]) //nolint:gosec
copy(buf[4:24], h[:])
h := sha256.Sum256(buf[36:])
copy(buf[4:36], h[:])
binary.LittleEndian.PutUint32(buf[0:4], uint32(sequence))

_, err = remoteConn.Write(buf)
Expand All @@ -240,8 +240,8 @@ func testMuxConnectionPair(t *testing.T, pktConn net.PacketConn, remoteConn *net
func verifyPacket(t *testing.T, b []byte, nextSeq uint32) {
readSeq := binary.LittleEndian.Uint32(b[0:4])
require.Equal(t, nextSeq, readSeq)
h := sha1.Sum(b[24:]) //nolint:gosec
require.Equal(t, h[:], b[4:24])
h := sha256.Sum256(b[36:])
require.Equal(t, h[:], b[4:36])
}

func TestUDPMux_Agent_Restart(t *testing.T) {
Expand Down

0 comments on commit 1f9684c

Please sign in to comment.