mirror of
https://github.com/arnaucube/testudo.git
synced 2026-02-01 08:46:41 +01:00
Refactor to idiomatic Result/Option patterns (#25)
This: - introduces a small [thiserror](https://github.com/dtolnay/thiserror)-powered enum to improve ProofVerifyError's messages, - refactors point decompression errors into a variant of that enum, thereby suppressing the panics which occur when decompresison fails. - folds other panics into the Error cases of their enclosing `Result` return
This commit is contained in:
committed by
GitHub
parent
7b102a241f
commit
9e4c166edb
@@ -1,16 +1,17 @@
|
||||
use core::fmt;
|
||||
use core::fmt::Debug;
|
||||
use thiserror::Error;
|
||||
|
||||
pub struct ProofVerifyError;
|
||||
|
||||
impl fmt::Display for ProofVerifyError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Proof verification failed")
|
||||
}
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ProofVerifyError {
|
||||
#[error("Proof verification failed")]
|
||||
InternalError,
|
||||
#[error("Compressed group element failed to decompress: {0:?}")]
|
||||
DecompressionError([u8; 32]),
|
||||
}
|
||||
|
||||
impl fmt::Debug for ProofVerifyError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{{ file: {}, line: {} }}", file!(), line!())
|
||||
impl Default for ProofVerifyError {
|
||||
fn default() -> Self {
|
||||
ProofVerifyError::InternalError
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user