From ab3689e57e9a0c44533e3992671be0458cbe7cfe Mon Sep 17 00:00:00 2001 From: MicroPanda123 Date: Mon, 31 Mar 2025 22:13:22 +0200 Subject: [PATCH] add support for thiserror --- Cargo.toml | 5 +++-- src/error.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0d830c..4a564d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "altcha-lib-rs" -version = "0.1.2" +version = "0.1.3" edition = "2021" authors = ["jmic "] description = "Community implementation of the Altcha library in Rust for your own server application to create and validate challenges and responses." @@ -25,6 +25,7 @@ sha1 = "0" hmac = "0" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", optional = true } +thiserror = "2.0.12" [features] default = [] @@ -32,4 +33,4 @@ json = ["serde_json"] [dev-dependencies] actix-web = "4" -base64 = "0.22" \ No newline at end of file +base64 = "0.22" diff --git a/src/error.rs b/src/error.rs index 0b8a13f..aa2b4d9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,15 +1,25 @@ -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum Error { #[cfg(feature = "json")] + #[error("JSON parsing error: {0}")] ParseJson(serde_json::Error), + #[error("Integer parsing error: {0}")] ParseInteger(std::num::ParseIntError), + #[error("Expiration parsing error: {0}")] ParseExpire(String), + #[error("Solution expired: {0}")] VerificationFailedExpired(String), + #[error("Solution does not match the challenge: {0}")] VerificationMismatchChallenge(String), + #[error("Signature in the solution does not match the challenge: {0}")] VerificationMismatchSignature(String), + #[error("Max number reached: {0}")] SolveChallengeMaxNumberReached(String), + #[error("Wrong challenge input: {0}")] WrongChallengeInput(String), + #[error("Altcha error: {0}")] General(String), + #[error("Error in the randomizer: {0}")] RandError(rand::distr::uniform::Error), }