2022-03-10 09:44:48 +00:00
|
|
|
package srtp
|
|
|
|
|
|
|
|
import (
|
2024-01-18 18:54:54 +00:00
|
|
|
"github.com/pion/transport/replaydetector"
|
2022-03-10 09:44:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ContextOption represents option of Context using the functional options pattern.
|
|
|
|
type ContextOption func(*Context) error
|
|
|
|
|
|
|
|
// SRTPReplayProtection sets SRTP replay protection window size.
|
2024-01-18 18:54:54 +00:00
|
|
|
func SRTPReplayProtection(windowSize uint) ContextOption { // nolint:golint
|
2022-03-10 09:44:48 +00:00
|
|
|
return func(c *Context) error {
|
|
|
|
c.newSRTPReplayDetector = func() replaydetector.ReplayDetector {
|
2024-01-18 18:54:54 +00:00
|
|
|
return replaydetector.WithWrap(windowSize, maxSequenceNumber)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRTCPReplayProtection sets SRTCP replay protection window size.
|
|
|
|
func SRTCPReplayProtection(windowSize uint) ContextOption {
|
|
|
|
return func(c *Context) error {
|
|
|
|
c.newSRTCPReplayDetector = func() replaydetector.ReplayDetector {
|
2024-01-18 18:54:54 +00:00
|
|
|
return replaydetector.WithWrap(windowSize, maxSRTCPIndex)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRTPNoReplayProtection disables SRTP replay protection.
|
2024-01-18 18:54:54 +00:00
|
|
|
func SRTPNoReplayProtection() ContextOption { // nolint:golint
|
2022-03-10 09:44:48 +00:00
|
|
|
return func(c *Context) error {
|
|
|
|
c.newSRTPReplayDetector = func() replaydetector.ReplayDetector {
|
|
|
|
return &nopReplayDetector{}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRTCPNoReplayProtection disables SRTCP replay protection.
|
|
|
|
func SRTCPNoReplayProtection() ContextOption {
|
|
|
|
return func(c *Context) error {
|
|
|
|
c.newSRTCPReplayDetector = func() replaydetector.ReplayDetector {
|
|
|
|
return &nopReplayDetector{}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type nopReplayDetector struct{}
|
|
|
|
|
|
|
|
func (s *nopReplayDetector) Check(uint64) (func(), bool) {
|
|
|
|
return func() {}, true
|
|
|
|
}
|