-
Notifications
You must be signed in to change notification settings - Fork 1
/
srs.go
46 lines (41 loc) · 1.08 KB
/
srs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package srsmilter
import (
"errors"
"strings"
"github.com/mileusna/srs"
)
func ForwardSrs(addr string, config *Configuration) (string, error) {
if len(config.SrsKeys) == 0 {
return "", errors.New("no SRS key found")
}
s := srs.SRS{
Secret: []byte(config.SrsKeys[0]),
Domain: config.SrsDomain.String(),
FirstSeparator: "=",
}
srsAddress, err := s.Forward(addr)
if err != nil {
return "", err
}
return srsAddress, nil
}
func ReverseSrs(srsAddress string, config *Configuration) (string, error) {
for _, key := range config.SrsKeys {
s := srs.SRS{
Secret: []byte(key),
Domain: config.SrsDomain.String(),
FirstSeparator: "=",
}
addr, err := s.Reverse(srsAddress)
if err != nil && err != srs.ErrHashInvalid {
return "", err
}
if err == nil {
return addr, nil
}
}
return "", errors.New("no SRS key found or all tried keys failed")
}
func looksLikeSrs(local string) bool {
return strings.HasPrefix(local, "SRS0=") || strings.HasPrefix(local, "SRS1=") || strings.HasPrefix(local, "srs0=") || strings.HasPrefix(local, "srs1=")
}