-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ProofError/ProofResult for better error handling.
- Loading branch information
Showing
13 changed files
with
140 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
use std::{error::Error, fmt::Display}; | ||
use std::{error::Error, fmt::Display, borrow::Borrow}; | ||
|
||
/// Signals an invalid IO pattern. | ||
/// | ||
/// This error indicates a wrong IO Pattern declared | ||
/// upon instantiation of the SAFE sponge. | ||
#[derive(Debug, Clone)] | ||
pub struct InvalidTag(String); | ||
pub struct IOPatternError(String); | ||
|
||
impl Display for InvalidTag { | ||
#[derive(Debug, Clone)] | ||
pub enum ProofError { | ||
InvalidProof, | ||
InvalidIO(IOPatternError), | ||
SerializationError, | ||
} | ||
|
||
|
||
pub type ProofResult<T> = Result<T, ProofError>; | ||
|
||
impl Display for IOPatternError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{:?}", self.0) | ||
} | ||
} | ||
|
||
impl Error for InvalidTag {} | ||
impl Display for ProofError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::SerializationError => | ||
write!(f, "Serialization Error"), | ||
Self::InvalidIO(e) => e.fmt(f), | ||
Self::InvalidProof => write!(f, "Invalid proof") | ||
} | ||
} | ||
} | ||
|
||
impl Error for IOPatternError {} | ||
impl Error for ProofError {} | ||
|
||
impl From<&str> for InvalidTag { | ||
impl From<&str> for IOPatternError { | ||
fn from(s: &str) -> Self { | ||
s.to_string().into() | ||
} | ||
} | ||
|
||
impl From<String> for InvalidTag { | ||
impl From<String> for IOPatternError { | ||
fn from(s: String) -> Self { | ||
Self(s) | ||
} | ||
} | ||
|
||
impl<B: Borrow<IOPatternError>> From<B> for ProofError { | ||
fn from(value: B) -> Self { | ||
ProofError::InvalidIO(value.borrow().clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.