diff --git a/src/storage/mod.rs b/src/storage/mod.rs index a76c609..52ec968 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -51,6 +51,24 @@ pub trait CaptchaStorage: Send + Sync + 'static { &self, token: &str, ) -> impl std::future::Future> + Send; + + /// Create a new captcha image and return the answer and the image encoded as png. + /// + /// This method will store the answer in the storage. + fn new_captcha( + &self, + generator: G, + ) -> impl std::future::Future< + Output = Result<(String, Vec), either::Either>, + > + Send { + async move { + let (answer, image) = generator.new_captcha().await.map_err(either::Right)?; + Ok(( + self.store_answer(answer).await.map_err(either::Left)?, + image, + )) + } + } } impl CaptchaStorage for Arc