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:
François Garillot
2020-09-29 18:18:43 -04:00
committed by GitHub
parent 7b102a241f
commit 9e4c166edb
13 changed files with 84 additions and 90 deletions

View File

@@ -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
}
}