add support for thiserror

This commit is contained in:
MicroPanda123
2025-03-31 22:13:22 +02:00
parent 62b458dfd6
commit ab3689e57e
2 changed files with 14 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "altcha-lib-rs"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["jmic <jmic@users.noreply.github.com>"]
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"
base64 = "0.22"

View File

@@ -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),
}