Struct NonceConfig

Source
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: String

SQLite database file path

§cache_size_kb: i32

SQLite cache size in KB

§wal_mode: bool

Enable WAL (Write-Ahead Logging) mode

§sync_mode: String

Synchronous mode: OFF, NORMAL, FULL

§temp_store: String

Temporary storage: MEMORY, FILE

§cleanup_batch_size: usize

Batch size for cleanup operations

§cleanup_optimize_threshold: usize

Threshold for triggering database optimization

§default_ttl: Duration

Default time-to-live for nonce records

§time_window: Duration

Time window for timestamp validation

Implementations§

Source§

impl NonceConfig

Source

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=16384
Source

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();
Source

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)
Source

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)
Source

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)
Source

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);
    }
}
Source

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

Source§

fn clone(&self) -> NonceConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NonceConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NonceConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.