Skip to content

Commit

Permalink
convolve: improve error type
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 29, 2023
1 parent 04c8865 commit b853c22
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions commit_verify/src/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ use crate::{CommitEncode, CommitmentProtocol, VerifyEq};
/// Error during commitment verification
#[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)]
#[display(doc_comments)]
#[allow(clippy::enum_variant_names)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),

Check warning on line 31 in commit_verify/src/convolve.rs

View check run for this annotation

Codecov / codecov/patch

commit_verify/src/convolve.rs#L31

Added line #L31 was not covered by tests
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub enum ConvolveVerifyError {
/// The verified commitment doesn't commit to the provided message.
InvalidCommitment,
/// The message is invalid since a commitment to it can't be created /
/// exist.
InvalidMessage,
CommitmentMismatch,

/// The message is invalid since a valid commitment to it can't be created.
ImpossibleMessage,

/// The proof of the commitment is invalid and the commitment can't be
/// verified.
InvalidProof,
Expand Down Expand Up @@ -80,12 +85,12 @@ where
let suppl = self.extract_supplement();
let (commitment_prime, proof) = original
.convolve_commit(suppl, msg)
.map_err(|_| ConvolveVerifyError::InvalidMessage)?;
.map_err(|_| ConvolveVerifyError::ImpossibleMessage)?;
if !self.verify_eq(&proof) {
return Err(ConvolveVerifyError::InvalidProof);
}
if !commitment.verify_eq(&commitment_prime) {
return Err(ConvolveVerifyError::InvalidCommitment);
return Err(ConvolveVerifyError::CommitmentMismatch);
}
Ok(())
}
Expand Down

0 comments on commit b853c22

Please sign in to comment.