challenge_bypass_ristretto/
errors.rs1use core::fmt;
5use core::fmt::Display;
6
7#[cfg(feature = "std")]
8use std::error::Error;
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
13pub enum InternalError {
14 PointDecompressionError,
16 ScalarFormatError,
18 BytesLengthError {
20 name: &'static str,
22 length: usize,
24 },
25 VerifyError,
27 LengthMismatchError,
29 DecodingError,
31}
32
33impl Display for InternalError {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 match *self {
36 InternalError::PointDecompressionError => write!(f, "Cannot decompress Edwards point"),
37 InternalError::ScalarFormatError => {
38 write!(f, "Input bytes were not in canonical representation")
39 }
40 InternalError::BytesLengthError { name: n, length: l } => {
41 write!(f, "{} must be {} bytes in length", n, l)
42 }
43 InternalError::VerifyError => write!(f, "Verification failed"),
44 InternalError::LengthMismatchError => write!(f, "Inputs differed in length"),
45 InternalError::DecodingError => write!(f, "Decoding failed"),
46 }
47 }
48}
49
50#[cfg(feature = "std")]
51impl Error for InternalError {}
52
53#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
55pub struct TokenError(pub InternalError);
56
57impl Display for TokenError {
58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59 write!(f, "{}", self.0)
60 }
61}
62
63#[cfg(feature = "std")]
64impl Error for TokenError {
65 fn source(&self) -> Option<&(dyn Error + 'static)> {
66 Some(&self.0)
67 }
68}