From c6956ad7299d6fe01e8c2fb524fb4c79ac7b418d Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Mon, 12 Aug 2024 20:11:42 +0000
Subject: [PATCH] feat: New `SimpleGenerator` to generate the captcha
Signed-off-by: Awiteb
---
src/captcha_gen.rs | 40 -----------
src/captcha_gen/mod.rs | 27 +++++++
src/captcha_gen/simple_generator.rs | 107 ++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 40 deletions(-)
delete mode 100644 src/captcha_gen.rs
create mode 100644 src/captcha_gen/mod.rs
create mode 100644 src/captcha_gen/simple_generator.rs
diff --git a/src/captcha_gen.rs b/src/captcha_gen.rs
deleted file mode 100644
index dbb48da..0000000
--- a/src/captcha_gen.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2024, Awiteb
-// A captcha middleware for Salvo framework.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-use crate::{CaptchaDifficulty, CaptchaName, CaptchaStorage};
-
-/// Captcha generator, used to generate a new captcha image. This trait are implemented for all [`CaptchaStorage`].
-pub trait CaptchaGenerator: CaptchaStorage {
- /// Create a new captcha image and return the token and the image encoded as png. Will return None if the captcha crate failed to create the captcha.
- ///
- /// The returned captcha image is 220x110 pixels.
- ///
- /// For more information about the captcha name and difficulty, see the [`README.md`](https://git.4rs.nl/awiteb/salvo-captcha/#captcha-name-and-difficulty).
- fn new_captcha(
- &self,
- name: CaptchaName,
- difficulty: CaptchaDifficulty,
- ) -> impl std::future::Future