Repository: bluenviron/gortsplib
Pull request #338 (2023-07-31 08:00:53)

restore API compatibility

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) Report
> Merging [#338](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) (9018bf5) into [main](https://app.codecov.io/gh/bluenviron/gortsplib/commit/8b8b52e689d9986b2cd29f5452275d5a4cf7d586?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) (8b8b52e) will **increase** coverage by `0.01%`.
> The diff coverage is `71.42%`.

> :exclamation: Current head 9018bf5 differs from pull request most recent head 9b9fe4e. Consider uploading reports for the commit 9b9fe4e to get more accurate results

```diff
@@            Coverage Diff             @@
##             main     #338      +/-   ##
==========================================
+ Coverage   83.05%   83.07%   +0.01%     
==========================================
  Files         101      101              
  Lines       10354    10358       +4     
==========================================
+ Hits         8600     8605       +5     
+ Misses       1377     1376       -1     
  Partials      377      377              
```


| [Files Changed](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) | Coverage Δ | |
|---|---|---|
| [pkg/auth/validate.go](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron#diff-cGtnL2F1dGgvdmFsaWRhdGUuZ28=) | `92.07% <66.66%> (-1.68%)` | :arrow_down: |
| [pkg/auth/validator.go](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron#diff-cGtnL2F1dGgvdmFsaWRhdG9yLmdv) | `41.32% <100.00%> (+1.15%)` | :arrow_up: |

... and [3 files with indirect coverage changes](https://app.codecov.io/gh/bluenviron/gortsplib/pull/338/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron)

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron)


Patch:
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,


Test patch:
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/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{