t_rust_less_lib/otp/
error.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4#[derive(Debug, Error, Serialize, Deserialize)]
5#[cfg_attr(feature = "with_specta", derive(specta::Type))]
6pub enum OTPError {
7  #[error("Invalid url: {0}")]
8  InvalidUrl(String),
9  #[error("Invalid url scheme. Expected otpauth")]
10  InvalidScheme,
11  #[error("Invalid OTP type. Only totp and hotp are supported")]
12  InvalidType,
13  #[error("Invalid OTP algorithm. Only SHA1, SHA256, SHA512 are supported")]
14  InvalidAlgorithm,
15  #[error("Invalid secret")]
16  InvalidSecret,
17  #[error("Missing required parameter: {0}")]
18  MissingParameter(String),
19}
20
21pub type OTPResult<T> = Result<T, OTPError>;
22
23error_convert_from!(url::ParseError, OTPError, InvalidUrl(display));