use crypto/rand instead of math/rand to avoid port conflicts and security issues

This commit is contained in:
aler9
2021-09-23 19:37:26 +02:00
parent 5ef9076357
commit 0454e5407f
5 changed files with 41 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
package rtcpreceiver
import (
"math/rand"
"crypto/rand"
"sync"
"time"
@@ -11,6 +11,12 @@ import (
"github.com/aler9/gortsplib/pkg/base"
)
func randUint32() uint32 {
var b [4]byte
rand.Read(b[:])
return uint32(b[0]<<24) | uint32(b[1]<<16) | uint32(b[2]<<8) | uint32(b[3])
}
// RTCPReceiver is a utility to generate RTCP receiver reports.
type RTCPReceiver struct {
receiverSSRC uint32
@@ -39,7 +45,7 @@ func New(receiverSSRC *uint32, clockRate int) *RTCPReceiver {
return &RTCPReceiver{
receiverSSRC: func() uint32 {
if receiverSSRC == nil {
return rand.Uint32()
return randUint32()
}
return *receiverSSRC
}(),