mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
Some checks failed
code_lint / go (push) Has been cancelled
code_lint / go_mod (push) Has been cancelled
code_lint / docs (push) Has been cancelled
code_lint / api_docs (push) Has been cancelled
code_test / test_64 (push) Has been cancelled
code_test / test_32 (push) Has been cancelled
code_test / test_e2e (push) Has been cancelled
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/bluenviron/gortsplib/v5/pkg/auth"
|
|
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
|
|
)
|
|
|
|
// RTSPAuthMethods is the rtspAuthMethods parameter.
|
|
type RTSPAuthMethods []auth.VerifyMethod
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (d RTSPAuthMethods) MarshalJSON() ([]byte, error) {
|
|
out := make([]string, len(d))
|
|
|
|
for i, v := range d {
|
|
switch v {
|
|
case auth.VerifyMethodBasic:
|
|
out[i] = "basic"
|
|
|
|
default:
|
|
out[i] = "digest"
|
|
}
|
|
}
|
|
|
|
sort.Strings(out)
|
|
|
|
return json.Marshal(out)
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
|
func (d *RTSPAuthMethods) UnmarshalJSON(b []byte) error {
|
|
var in []string
|
|
if err := jsonwrapper.Unmarshal(b, &in); err != nil {
|
|
return err
|
|
}
|
|
|
|
*d = nil
|
|
|
|
for _, v := range in {
|
|
switch v {
|
|
case "basic":
|
|
*d = append(*d, auth.VerifyMethodBasic)
|
|
|
|
case "digest":
|
|
*d = append(*d, auth.VerifyMethodDigestMD5)
|
|
|
|
default:
|
|
return fmt.Errorf("invalid authentication method: '%s'", v)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnmarshalEnv implements env.Unmarshaler.
|
|
func (d *RTSPAuthMethods) UnmarshalEnv(_ string, v string) error {
|
|
byts, _ := json.Marshal(strings.Split(v, ","))
|
|
return d.UnmarshalJSON(byts)
|
|
}
|