oauth2_utils/errors/
mod.rs1use crate::consts::{CV_MAX_SIZE, CV_MIN_SIZE};
2use base64::DecodeError as DecErr;
3use std::fmt::{self, Display, Formatter};
4
5#[derive(Debug, PartialEq)]
6pub enum CodeVerifierError {
7 TooBig,
8 TooSmall,
9}
10
11pub type DecodeError = DecErr;
12
13#[derive(Debug, PartialEq)]
14pub enum B64Error {
15 InvalidEncoding,
16 DecodeError,
17}
18
19impl Display for B64Error {
20 fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
21 match self {
22 Self::InvalidEncoding => write!(fmt, "Invalid Base64 encoding."),
23 Self::DecodeError => write!(fmt, "Cannot decode the given value"),
24 }
25 }
26}
27
28impl Display for CodeVerifierError {
29 fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
30 match self {
31 Self::TooBig => write!(fmt, "It must be less than {}", CV_MAX_SIZE),
32 Self::TooSmall => {
33 write!(fmt, "It must be greater than {}", CV_MIN_SIZE)
34 }
35 }
36 }
37}
38
39impl std::error::Error for CodeVerifierError {}
40impl std::error::Error for B64Error {}