Skip to main content

elif_security/
lib.rs

1//! # elif-security
2//!
3//! Security middleware and utilities for the elif.rs web framework.
4//! Provides CORS, CSRF protection, rate limiting, and other security features.
5
6pub mod config;
7pub mod middleware;
8pub mod integration;
9
10// Re-export main types
11pub use config::*;
12pub use middleware::cors::{CorsMiddleware, CorsConfig};
13pub use middleware::csrf::{CsrfMiddleware, CsrfConfig};
14pub use integration::{
15    SecurityMiddlewareBuilder, 
16    basic_security_pipeline, 
17    strict_security_pipeline, 
18    development_security_pipeline
19};
20
21/// Common result type for security operations
22pub type SecurityResult<T> = Result<T, SecurityError>;
23
24/// Security-related errors
25#[derive(thiserror::Error, Debug)]
26pub enum SecurityError {
27    #[error("CORS violation: {message}")]
28    CorsViolation { message: String },
29    
30    #[error("CSRF token validation failed")]
31    CsrfValidationFailed,
32    
33    #[error("Rate limit exceeded: {limit} requests per {window_seconds} seconds")]
34    RateLimitExceeded { limit: u32, window_seconds: u32 },
35    
36    #[error("Configuration error: {message}")]
37    ConfigError { message: String },
38    
39    #[error("Security policy violation: {message}")]
40    PolicyViolation { message: String },
41}