xref: /webrtc/srtp/src/option.rs (revision 630c46fe)
1 use util::replay_detector::*;
2 
3 pub type ContextOption = Box<dyn (Fn() -> Box<dyn ReplayDetector + Send + 'static>) + Send + Sync>;
4 
5 pub(crate) const MAX_SEQUENCE_NUMBER: u16 = 65535;
6 pub(crate) const MAX_SRTCP_INDEX: usize = 0x7FFFFFFF;
7 
8 /// srtp_replay_protection sets SRTP replay protection window size.
srtp_replay_protection(window_size: usize) -> ContextOption9 pub 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.
srtcp_replay_protection(window_size: usize) -> ContextOption19 pub 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.
srtp_no_replay_protection() -> ContextOption29 pub 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.
srtcp_no_replay_protection() -> ContextOption34 pub fn srtcp_no_replay_protection() -> ContextOption {
35     Box::new(|| -> Box<dyn ReplayDetector + Send> { Box::<NoOpReplayDetector>::default() })
36 }
37