diff --git a/client_play_test.go b/client_play_test.go index 15860e43..ffe6e4f3 100644 --- a/client_play_test.go +++ b/client_play_test.go @@ -1286,7 +1286,7 @@ func TestClientPlayAutomaticProtocol(t *testing.T) { require.NoError(t, err) require.Equal(t, base.Describe, req.Method) - nonce, err := auth.GenerateNonce() + nonce, err := auth.GenerateNonce2() require.NoError(t, err) err = conn.WriteResponse(&base.Response{ @@ -1400,7 +1400,7 @@ func TestClientPlayAutomaticProtocol(t *testing.T) { require.NoError(t, err) require.Equal(t, base.Setup, req.Method) - nonce, err := auth.GenerateNonce() + nonce, err := auth.GenerateNonce2() require.NoError(t, err) err = conn.WriteResponse(&base.Response{ diff --git a/client_test.go b/client_test.go index 6e22f9be..7553ef89 100644 --- a/client_test.go +++ b/client_test.go @@ -194,7 +194,7 @@ func TestClientAuth(t *testing.T) { require.NoError(t, err) require.Equal(t, base.Describe, req.Method) - nonce, err := auth.GenerateNonce() + nonce, err := auth.GenerateNonce2() require.NoError(t, err) err = conn.WriteResponse(&base.Response{ diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go index 5a19310b..a8b4e2a9 100644 --- a/pkg/auth/auth_test.go +++ b/pkg/auth/auth_test.go @@ -47,7 +47,7 @@ func TestAuth(t *testing.T) { } t.Run(c1.name+"_"+conf, func(t *testing.T) { - nonce, err := GenerateNonce() + nonce, err := GenerateNonce2() require.NoError(t, err) se, err := NewSender( @@ -105,7 +105,7 @@ func TestAuthVLC(t *testing.T) { "rtsp://myhost/mypath/test?testing/trackID=0", }, } { - nonce, err := GenerateNonce() + nonce, err := GenerateNonce2() require.NoError(t, err) se, err := NewSender( diff --git a/pkg/auth/validate.go b/pkg/auth/validate.go index 3fd5cf6f..317d2e45 100644 --- a/pkg/auth/validate.go +++ b/pkg/auth/validate.go @@ -10,8 +10,8 @@ import ( "github.com/bluenviron/gortsplib/v3/pkg/url" ) -// GenerateNonce generates a nonce that can be used in Validate(). -func GenerateNonce() (string, error) { +// GenerateNonce2 generates a nonce that can be used in Validate(). +func GenerateNonce2() (string, error) { byts := make([]byte, 16) _, err := rand.Read(byts) if err != nil { @@ -21,6 +21,17 @@ func GenerateNonce() (string, error) { return hex.EncodeToString(byts), nil } +// GenerateNonce generates a nonce that can be used in Validate(). +// +// Deprecated: use GenerateNonce2. +func GenerateNonce() string { + v, err := GenerateNonce2() + if err != nil { + panic(err) + } + return v +} + // GenerateWWWAuthenticate generates a WWW-Authenticate header. func GenerateWWWAuthenticate(methods []headers.AuthMethod, realm string, nonce string) base.HeaderValue { if methods == nil { diff --git a/pkg/auth/validator.go b/pkg/auth/validator.go index fc4a4def..ce7deef3 100644 --- a/pkg/auth/validator.go +++ b/pkg/auth/validator.go @@ -64,10 +64,7 @@ func NewValidator(user string, pass string, methods []headers.AuthMethod) *Valid methods = []headers.AuthMethod{headers.AuthBasic} } - nonce, err := GenerateNonce() - if err != nil { - panic(err) - } + nonce := GenerateNonce() return &Validator{ user: user, diff --git a/server_test.go b/server_test.go index c6bc3f85..a7a52546 100644 --- a/server_test.go +++ b/server_test.go @@ -1045,7 +1045,7 @@ func TestServerSessionTeardown(t *testing.T) { } func TestServerAuth(t *testing.T) { - nonce, err := auth.GenerateNonce() + nonce, err := auth.GenerateNonce2() require.NoError(t, err) s := &Server{