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]
byteorder = "1.2.3"
error-chain = "0.12.0"
failure = "0.1"
init_with = "1.1.0"
log = "0.4.1"
pairing = { version = "0.14.2", features = ["u128-support"] }

View File

@ -1,10 +1,13 @@
error_chain! {
errors {
NotEnoughShares {
description("not enough signature shares")
}
DuplicateEntry {
description("signature shares contain a duplicated index")
}
}
//! Crypto errors.
/// A crypto error.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
pub enum Error {
#[fail(display = "Not enough signature shares")]
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 byteorder;
#[macro_use]
extern crate error_chain;
extern crate failure;
extern crate init_with;
#[macro_use]
extern crate log;
@ -39,7 +39,7 @@ use pairing::{CurveAffine, CurveProjective, Engine, Field};
use rand::{ChaChaRng, OsRng, Rng, SeedableRng};
use ring::digest;
use error::{ErrorKind, Result};
use error::{Error, Result};
use into_fr::IntoFr;
use poly::{Commitment, Poly};
@ -499,13 +499,13 @@ where
.map(|(i, sample)| (into_fr_plus_1(i), sample))
.collect();
if samples.len() < t {
return Err(ErrorKind::NotEnoughShares.into());
return Err(Error::NotEnoughShares);
}
let mut result = C::zero();
let mut indexes = Vec::new();
for (x, sample) in samples.iter().take(t) {
if indexes.contains(x) {
return Err(ErrorKind::DuplicateEntry.into());
return Err(Error::DuplicateEntry);
}
indexes.push(x.clone());
// Compute the value at 0 of the Lagrange polynomial that is `0` at the other data