Skip to main content

cratefield_core/ports/
captcha.rs

1//! The `Captcha` port. The Turnstile adapter is the reference
2//! implementation (issue #7).
3
4use async_trait::async_trait;
5use thiserror::Error;
6
7/// A captcha verification verdict. `ok: false` with a `reason` from the
8/// provider's `error-codes`; transport-level unavailability surfaces as
9/// `ok: false, reason: "unavailable"` unless the adapter is configured
10/// fail-open (staging only).
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct Verdict {
13    pub ok: bool,
14    pub reason: Option<String>,
15}
16
17#[derive(Debug, Clone, Error)]
18pub enum CaptchaError {
19    #[error("captcha transport error: {0}")]
20    Transport(String),
21}
22
23#[async_trait]
24pub trait Captcha: Send + Sync {
25    async fn verify(&self, token: &str, remote_ip: Option<&str>) -> Result<Verdict, CaptchaError>;
26}