converted errors from error_chain to failure

This commit is contained in:
Vladimir Komendantskiy 2018-07-31 11:02:22 +01:00
parent 394e4ce140
commit b7ab849a16
3 changed files with 17 additions and 14 deletions

View File

@ -12,7 +12,7 @@ categories = ["cryptography"]
[dependencies] [dependencies]
byteorder = "1.2.3" byteorder = "1.2.3"
error-chain = "0.12.0" failure = "0.1"
init_with = "1.1.0" init_with = "1.1.0"
log = "0.4.1" log = "0.4.1"
pairing = { version = "0.14.2", features = ["u128-support"] } pairing = { version = "0.14.2", features = ["u128-support"] }

View File

@ -1,10 +1,13 @@
error_chain! { //! Crypto errors.
errors {
NotEnoughShares { /// A crypto error.
description("not enough signature shares") #[derive(Clone, Eq, PartialEq, Debug, Fail)]
} pub enum Error {
DuplicateEntry { #[fail(display = "Not enough signature shares")]
description("signature shares contain a duplicated index") NotEnoughShares,
} #[fail(display = "Signature shares contain a duplicated index")]
} DuplicateEntry,
} }
/// A crypto result.
pub type Result<T> = ::std::result::Result<T, Error>;

View File

@ -6,7 +6,7 @@
extern crate bincode; extern crate bincode;
extern crate byteorder; extern crate byteorder;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate failure;
extern crate init_with; extern crate init_with;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
@ -39,7 +39,7 @@ use pairing::{CurveAffine, CurveProjective, Engine, Field};
use rand::{ChaChaRng, OsRng, Rng, SeedableRng}; use rand::{ChaChaRng, OsRng, Rng, SeedableRng};
use ring::digest; use ring::digest;
use error::{ErrorKind, Result}; use error::{Error, Result};
use into_fr::IntoFr; use into_fr::IntoFr;
use poly::{Commitment, Poly}; use poly::{Commitment, Poly};
@ -499,13 +499,13 @@ where
.map(|(i, sample)| (into_fr_plus_1(i), sample)) .map(|(i, sample)| (into_fr_plus_1(i), sample))
.collect(); .collect();
if samples.len() < t { if samples.len() < t {
return Err(ErrorKind::NotEnoughShares.into()); return Err(Error::NotEnoughShares);
} }
let mut result = C::zero(); let mut result = C::zero();
let mut indexes = Vec::new(); let mut indexes = Vec::new();
for (x, sample) in samples.iter().take(t) { for (x, sample) in samples.iter().take(t) {
if indexes.contains(x) { if indexes.contains(x) {
return Err(ErrorKind::DuplicateEntry.into()); return Err(Error::DuplicateEntry);
} }
indexes.push(x.clone()); indexes.push(x.clone());
// Compute the value at 0 of the Lagrange polynomial that is `0` at the other data // Compute the value at 0 of the Lagrange polynomial that is `0` at the other data