use crate::{DdsResult, QosBuilder};
#[derive(Debug, Clone, Default)]
pub struct SecurityConfig {
identity_ca: Option<String>,
identity_certificate: Option<String>,
identity_private_key: Option<String>,
governance: Option<String>,
permissions: Option<String>,
permissions_ca: Option<String>,
auth_plugin: String,
access_plugin: String,
crypto_plugin: String,
}
impl SecurityConfig {
pub fn new() -> Self {
Self {
auth_plugin: "dds.sec.auth.builtin.PKI-DH".into(),
access_plugin: "dds.sec.access.builtin.Access-Permissions".into(),
crypto_plugin: "dds.sec.crypto.builtin.AES-GCM-GMAC".into(),
..Default::default()
}
}
pub fn identity_ca(mut self, path: impl Into<String>) -> Self {
self.identity_ca = Some(path.into());
self
}
pub fn identity_certificate(mut self, path: impl Into<String>) -> Self {
self.identity_certificate = Some(path.into());
self
}
pub fn identity_private_key(mut self, path: impl Into<String>) -> Self {
self.identity_private_key = Some(path.into());
self
}
pub fn governance(mut self, path: impl Into<String>) -> Self {
self.governance = Some(path.into());
self
}
pub fn permissions(mut self, path: impl Into<String>) -> Self {
self.permissions = Some(path.into());
self
}
pub fn permissions_ca(mut self, path: impl Into<String>) -> Self {
self.permissions_ca = Some(path.into());
self
}
pub fn auth_plugin(mut self, name: impl Into<String>) -> Self {
self.auth_plugin = name.into();
self
}
pub fn access_plugin(mut self, name: impl Into<String>) -> Self {
self.access_plugin = name.into();
self
}
pub fn crypto_plugin(mut self, name: impl Into<String>) -> Self {
self.crypto_plugin = name.into();
self
}
pub fn apply_to(self, builder: QosBuilder) -> QosBuilder {
let mut b = builder
.property("dds.sec.auth.plugin", &self.auth_plugin)
.property("dds.sec.access.plugin", &self.access_plugin)
.property("dds.sec.crypto.plugin", &self.crypto_plugin);
if let Some(path) = self.identity_ca {
b = b.property("dds.sec.auth.identity_ca", &format!("file:{}", path));
}
if let Some(path) = self.identity_certificate {
b = b.property(
"dds.sec.auth.identity_certificate",
&format!("file:{}", path),
);
}
if let Some(path) = self.identity_private_key {
b = b.property(
"dds.sec.auth.private_key",
&format!("file:{}", path),
);
}
if let Some(path) = self.governance {
b = b.property(
"dds.sec.access.governance",
&format!("file:{}", path),
);
}
if let Some(path) = self.permissions {
b = b.property(
"dds.sec.access.permissions",
&format!("file:{}", path),
);
}
if let Some(path) = self.permissions_ca {
b = b.property(
"dds.sec.access.permissions_ca",
&format!("file:{}", path),
);
}
b
}
}
impl QosBuilder {
pub fn security(self, config: SecurityConfig) -> Self {
config.apply_to(self)
}
}