pub struct NonceConfig {
pub db_path: String,
pub cache_size_kb: i32,
pub wal_mode: bool,
pub sync_mode: String,
pub temp_store: String,
pub cleanup_batch_size: usize,
pub cleanup_optimize_threshold: usize,
pub default_ttl: Duration,
pub time_window: Duration,
}Expand description
Comprehensive configuration for nonce authentication system.
This struct provides a centralized way to configure all aspects of the nonce authentication system, including database settings, performance tuning, and security parameters.
§Environment Variables
All configuration options can be set via environment variables:
§Database Configuration
NONCE_AUTH_DB_PATH: Database file path (default: “nonce_auth.db”)NONCE_AUTH_CACHE_SIZE: SQLite cache size in KB (default: 2048)NONCE_AUTH_WAL_MODE: Enable WAL mode (default: true)NONCE_AUTH_SYNC_MODE: Synchronous mode NORMAL/FULL/OFF (default: NORMAL)NONCE_AUTH_TEMP_STORE: Temp storage MEMORY/FILE (default: MEMORY)
§Performance Configuration
NONCE_AUTH_CLEANUP_BATCH_SIZE: Cleanup batch size (default: 1000)NONCE_AUTH_CLEANUP_THRESHOLD: Auto-optimize threshold (default: 100)
§Security Configuration
NONCE_AUTH_DEFAULT_TTL: Default TTL in seconds (default: 300)NONCE_AUTH_DEFAULT_TIME_WINDOW: Time window in seconds (default: 60)
§Example
use nonce_auth::nonce::NonceConfig;
use std::time::Duration;
// Use default configuration
let config = NonceConfig::default();
// Create custom configuration
let config = NonceConfig {
db_path: "custom_nonce.db".to_string(),
cache_size_kb: 4096, // 4MB cache
default_ttl: Duration::from_secs(600), // 10 minutes
time_window: Duration::from_secs(120), // 2 minutes
..Default::default()
};
// Use config directly with Database::new(config)Fields§
§db_path: StringSQLite database file path
cache_size_kb: i32SQLite cache size in KB
wal_mode: boolEnable WAL (Write-Ahead Logging) mode
sync_mode: StringSynchronous mode: OFF, NORMAL, FULL
temp_store: StringTemporary storage: MEMORY, FILE
cleanup_batch_size: usizeBatch size for cleanup operations
cleanup_optimize_threshold: usizeThreshold for triggering database optimization
default_ttl: DurationDefault time-to-live for nonce records
time_window: DurationTime window for timestamp validation
Implementations§
Source§impl NonceConfig
impl NonceConfig
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Creates a new configuration from environment variables.
This method first determines the preset configuration based on the
NONCE_AUTH_PRESET environment variable, then applies individual
environment variable overrides.
§Environment Variables
NONCE_AUTH_PRESET: Preset configuration (production,development,high_performance)- Individual configuration variables override preset values
§Returns
A NonceConfig instance with preset and environment variable values.
§Example
# Use production preset with custom cache size
export NONCE_AUTH_PRESET=production
export NONCE_AUTH_CACHE_SIZE=16384Sourcepub fn update_from_env(self) -> Self
pub fn update_from_env(self) -> Self
Updates this configuration with values from environment variables.
Only updates fields where environment variables are set. This allows combining preset configurations with environment overrides.
§Returns
A new NonceConfig instance with environment variable overrides applied.
§Example
use nonce_auth::nonce::NonceConfig;
// Start with production preset, then apply environment overrides
let config = NonceConfig::production().update_from_env();Sourcepub fn production() -> Self
pub fn production() -> Self
Creates a new configuration with recommended production settings.
This preset is optimized for production environments with:
- Larger cache size for better performance
- WAL mode enabled for concurrency
- Balanced security settings
- Optimized cleanup parameters
§Returns
A NonceConfig instance with production-optimized settings.
§Example
use nonce_auth::nonce::NonceConfig;
let config = NonceConfig::production();
// Use config directly with Database::new(config)Sourcepub fn development() -> Self
pub fn development() -> Self
Creates a new configuration optimized for development and testing.
This preset uses:
- In-memory database for faster tests
- Smaller cache size to save memory
- Shorter TTL for faster test cycles
- Relaxed time window for development
§Returns
A NonceConfig instance with development-optimized settings.
§Example
use nonce_auth::nonce::NonceConfig;
let config = NonceConfig::development();
// Use config directly with Database::new(config)Sourcepub fn high_performance() -> Self
pub fn high_performance() -> Self
Creates a new configuration optimized for high-performance scenarios.
This preset maximizes performance with:
- Large cache size
- Aggressive optimization settings
- Larger batch sizes
- Minimal synchronization overhead
§Returns
A NonceConfig instance with high-performance settings.
§Example
use nonce_auth::nonce::NonceConfig;
let config = NonceConfig::high_performance();
// Use config directly with Database::new(config)Sourcepub fn validate(&self) -> Vec<String>
pub fn validate(&self) -> Vec<String>
Validates the configuration and returns any issues found.
This method checks for common configuration problems and returns a list of validation errors or warnings.
§Returns
A vector of validation messages. Empty if configuration is valid.
§Example
use nonce_auth::nonce::NonceConfig;
let config = NonceConfig::default();
let issues = config.validate();
if !issues.is_empty() {
for issue in issues {
println!("Config issue: {}", issue);
}
}Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Returns a summary of the current configuration.
This method provides a human-readable summary of all configuration settings, useful for logging and debugging.
§Returns
A formatted string describing the configuration.
§Example
use nonce_auth::nonce::NonceConfig;
let config = NonceConfig::default();
println!("Configuration:\n{}", config.summary());Trait Implementations§
Source§impl Clone for NonceConfig
impl Clone for NonceConfig
Source§fn clone(&self) -> NonceConfig
fn clone(&self) -> NonceConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more