Skip to content
Clone
a06673b
45 lines 1.7 KB Rust
use serde::{Deserialize, Serialize};
use time::Duration;
/// Configuration for the Altcha Proof-of-Work CAPTCHA module.
///
/// All fields have sensible defaults, so a [`PowSettings`] can be built with
/// `PowSettings::default()` and only the HMAC secret overridden.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PowSettings {
/// HMAC secret used to sign challenges and used to verify submitted
/// solutions. This MUST be set to a high-entropy value in production.
pub hmac_secret: String,
/// Key derivation algorithm, e.g. `"PBKDF2/SHA-256"`, `"SHA-256"`,
/// `"ARGON2ID"`.
pub algorithm: String,
/// Algorithm-specific cost parameter. For `"PBKDF2/SHA-256"` this is the
/// iteration count; for `"ARGON2ID"` it is the time cost.
pub cost: u32,
/// Length of the derived key in bytes.
pub key_length: usize,
/// Required hex prefix the derived key must start with. Lower values are
/// harder to satisfy.
pub key_prefix: String,
/// Memory cost in KiB for memory-hard algorithms (Argon2id, Scrypt).
pub memory_cost: Option<u32>,
/// Parallelism factor for Argon2id and Scrypt.
pub parallelism: Option<u32>,
/// How long a generated challenge remains valid before it expires.
pub challenge_ttl: Duration,
}
impl Default for PowSettings {
fn default() -> Self {
Self {
hmac_secret: String::new(),
algorithm: "PBKDF2/SHA-256".to_string(),
cost: 100_000,
key_length: 32,
key_prefix: "00".to_string(),
memory_cost: None,
parallelism: None,
challenge_ttl: Duration::minutes(5),
}
}
}