1use std::net::IpAddr;
4
5use crate::{acl::Acl, security::ReplayProtection};
6
7pub struct Ctx {
11 replay_protection: ReplayProtection,
12 acl: Option<Acl>,
13}
14
15impl Ctx {
16 pub fn new() -> Self {
18 Ctx {
19 replay_protection: ReplayProtection::new(),
20 acl: None,
21 }
22 }
23
24 pub fn check_replay(&self, salt: &[u8]) -> bool {
26 self.replay_protection.check_and_insert(&salt)
27 }
28
29 pub fn set_acl(&mut self, acl: Acl) {
31 self.acl = Some(acl);
32 }
33
34 pub fn is_bypass(&self, ip: IpAddr, host: Option<&str>) -> bool {
36 match self.acl {
37 Some(ref acl) => acl.is_bypass(ip, host),
38 _ => false,
39 }
40 }
41
42 pub fn is_block_outbound(&self, ip: IpAddr, host: Option<&str>) -> bool {
44 match self.acl {
45 Some(ref acl) => acl.is_block_outbound(ip, host),
46 _ => false,
47 }
48 }
49}