admin_config/
security_config.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct SecurityConfig {
5    /// AES 密钥
6    pub aes_key: String,
7    /// AES 向量
8    pub aes_iv: String,
9    /// 是否启用 CORS
10    pub enable_cors: bool,
11    /// 允许的来源 (逗号分隔)
12    pub allowed_origins: String,
13    /// 是否启用 CSRF 防护
14    pub enable_csrf: bool,
15}
16
17impl Default for SecurityConfig {
18    fn default() -> Self {
19        Self {
20            aes_key: "".to_string(),
21            aes_iv: "".to_string(),
22            enable_cors: true,
23            allowed_origins: "".to_string(),
24            enable_csrf: false,
25        }
26    }
27}
28
29impl SecurityConfig {
30    pub fn allowed_origins_list(&self) -> Vec<String> {
31        self.allowed_origins.split(',').map(|s| s.trim().to_string()).collect()
32    }
33}