webrtc_srtp/
option.rs

1use util::replay_detector::*;
2
3pub type ContextOption = Box<dyn (Fn() -> Box<dyn ReplayDetector + Send + 'static>) + Send + Sync>;
4
5pub(crate) const MAX_SEQUENCE_NUMBER: u16 = 65535;
6pub(crate) const MAX_SRTCP_INDEX: usize = 0x7FFFFFFF;
7
8/// srtp_replay_protection sets SRTP replay protection window size.
9pub fn srtp_replay_protection(window_size: usize) -> ContextOption {
10    Box::new(move || -> Box<dyn ReplayDetector + Send> {
11        Box::new(WrappedSlidingWindowDetector::new(
12            window_size,
13            MAX_SEQUENCE_NUMBER as u64,
14        ))
15    })
16}
17
18/// Sets SRTCP replay protection window size.
19pub fn srtcp_replay_protection(window_size: usize) -> ContextOption {
20    Box::new(move || -> Box<dyn ReplayDetector + Send> {
21        Box::new(WrappedSlidingWindowDetector::new(
22            window_size,
23            MAX_SRTCP_INDEX as u64,
24        ))
25    })
26}
27
28/// srtp_no_replay_protection disables SRTP replay protection.
29pub fn srtp_no_replay_protection() -> ContextOption {
30    Box::new(|| -> Box<dyn ReplayDetector + Send> { Box::<NoOpReplayDetector>::default() })
31}
32
33/// srtcp_no_replay_protection disables SRTCP replay protection.
34pub fn srtcp_no_replay_protection() -> ContextOption {
35    Box::new(|| -> Box<dyn ReplayDetector + Send> { Box::<NoOpReplayDetector>::default() })
36}