ockam_core/access_control/
any.rs1use crate::access_control::{IncomingAccessControl, OutgoingAccessControl};
2use crate::compat::sync::Arc;
3use crate::compat::vec::Vec;
4use crate::{async_trait, compat::boxed::Box, RelayMessage, Result};
5
6#[derive(Debug)]
8pub struct AnyIncomingAccessControl(Vec<Arc<dyn IncomingAccessControl>>);
9
10impl AnyIncomingAccessControl {
11 pub fn new(access_controls: Vec<Arc<dyn IncomingAccessControl>>) -> Self {
13 Self(access_controls)
14 }
15}
16
17#[async_trait]
18impl IncomingAccessControl for AnyIncomingAccessControl {
19 async fn is_authorized(&self, relay_msg: &RelayMessage) -> Result<bool> {
20 for ac in &self.0 {
21 if ac.is_authorized(relay_msg).await? {
22 return crate::allow();
23 }
24 }
25
26 crate::deny()
27 }
28}
29
30#[derive(Debug)]
32pub struct AnyOutgoingAccessControl(Vec<Arc<dyn OutgoingAccessControl>>);
33
34impl AnyOutgoingAccessControl {
35 pub fn new(access_controls: Vec<Arc<dyn OutgoingAccessControl>>) -> Self {
37 Self(access_controls)
38 }
39}
40
41#[async_trait]
42impl OutgoingAccessControl for AnyOutgoingAccessControl {
43 async fn is_authorized(&self, relay_msg: &RelayMessage) -> Result<bool> {
44 for ac in &self.0 {
45 if ac.is_authorized(relay_msg).await? {
46 return crate::allow();
47 }
48 }
49
50 crate::deny()
51 }
52}
53
54