1use alloc::string::String;
12#[cfg(not(feature = "std"))]
13use core::fmt;
14
15#[derive(Debug)]
17#[cfg_attr(feature = "std", derive(thiserror::Error))]
18#[cfg_attr(feature = "std", error("Invalid instance: {message}"))]
19pub struct InvalidInstance {
20 pub message: String,
22}
23
24impl InvalidInstance {
25 pub fn new(message: impl Into<String>) -> Self {
27 Self {
28 message: message.into(),
29 }
30 }
31}
32
33impl From<InvalidInstance> for Error {
34 fn from(_err: InvalidInstance) -> Self {
35 Error::InvalidInstanceWitnessPair
36 }
37}
38
39#[non_exhaustive]
43#[derive(Debug)]
44#[cfg_attr(feature = "std", derive(thiserror::Error))]
45pub enum Error {
46 #[cfg_attr(feature = "std", error("Verification failed."))]
48 VerificationFailure,
49 #[cfg_attr(feature = "std", error("Invalid instance/witness pair."))]
51 InvalidInstanceWitnessPair,
52 #[cfg_attr(
54 feature = "std",
55 error("Uninitialized group element variable: {var_debug}")
56 )]
57 UnassignedGroupVar {
58 var_debug: String,
60 },
61}
62
63impl From<spongefish::VerificationError> for Error {
64 fn from(_value: spongefish::VerificationError) -> Self {
65 Error::VerificationFailure
66 }
67}
68
69#[cfg(not(feature = "std"))]
71impl fmt::Display for InvalidInstance {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 write!(f, "Invalid instance: {}", self.message)
74 }
75}
76
77#[cfg(not(feature = "std"))]
78impl fmt::Display for Error {
79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80 match self {
81 Error::VerificationFailure => write!(f, "Verification failed."),
82 Error::InvalidInstanceWitnessPair => write!(f, "Invalid instance/witness pair."),
83 Error::UnassignedGroupVar { var_debug } => {
84 write!(f, "Uninitialized group element variable: {}", var_debug)
85 }
86 }
87 }
88}
89
90pub type Result<T> = core::result::Result<T, Error>;
91
92pub const fn Ok<T>(value: T) -> Result<T> {
94 Result::Ok(value)
95}