extern crate alloc;
use alloc::boxed::Box;
use crate::authentication::IdentityHandle;
use crate::error::SecurityResult;
use crate::properties::PropertyList;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PermissionsHandle(pub u64);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccessDecision {
Permit,
Deny,
}
impl AccessDecision {
#[must_use]
pub fn is_permitted(self) -> bool {
matches!(self, Self::Permit)
}
}
pub trait AccessControlPlugin: Send + Sync {
fn validate_local_permissions(
&mut self,
local: IdentityHandle,
participant_guid: [u8; 16],
props: &PropertyList,
) -> SecurityResult<PermissionsHandle>;
fn validate_remote_permissions(
&mut self,
local: IdentityHandle,
remote: IdentityHandle,
remote_permissions_token: &[u8],
remote_credential: &[u8],
) -> SecurityResult<PermissionsHandle>;
fn check_create_datawriter(
&self,
perms: PermissionsHandle,
topic_name: &str,
) -> SecurityResult<AccessDecision>;
fn check_create_datareader(
&self,
perms: PermissionsHandle,
topic_name: &str,
) -> SecurityResult<AccessDecision>;
fn check_remote_datawriter_match(
&self,
local_perms: PermissionsHandle,
remote_perms: PermissionsHandle,
topic_name: &str,
) -> SecurityResult<AccessDecision>;
fn check_remote_datareader_match(
&self,
local_perms: PermissionsHandle,
remote_perms: PermissionsHandle,
topic_name: &str,
) -> SecurityResult<AccessDecision>;
fn plugin_class_id(&self) -> &str;
fn check_create_participant(
&self,
_local_perms: PermissionsHandle,
_domain_id: u32,
) -> SecurityResult<AccessDecision> {
Ok(AccessDecision::Permit)
}
fn check_remote_participant(
&self,
_local_perms: PermissionsHandle,
_remote_perms: PermissionsHandle,
_domain_id: u32,
) -> SecurityResult<AccessDecision> {
Ok(AccessDecision::Permit)
}
fn check_create_topic(
&self,
_local_perms: PermissionsHandle,
_topic_name: &str,
) -> SecurityResult<AccessDecision> {
Ok(AccessDecision::Permit)
}
fn get_permissions_token(
&self,
_local_perms: PermissionsHandle,
) -> SecurityResult<alloc::vec::Vec<u8>> {
Ok(alloc::vec::Vec::new())
}
fn get_permissions_credential_token(
&self,
_local_perms: PermissionsHandle,
) -> SecurityResult<alloc::vec::Vec<u8>> {
Ok(alloc::vec::Vec::new())
}
}
pub type AccessControlBox = Box<dyn AccessControlPlugin>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn access_decision_helper() {
assert!(AccessDecision::Permit.is_permitted());
assert!(!AccessDecision::Deny.is_permitted());
}
}