1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#[derive(Debug)]
pub enum Error {
InvalidInputLength,
IoError(std::io::Error),
Other(String),
CoinTossError(scuttlebutt::cointoss::Error),
CorrelationCheckFailed,
EqCheckFailed,
InvalidOpening,
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::IoError(e)
}
}
impl From<scuttlebutt::cointoss::Error> for Error {
fn from(e: scuttlebutt::cointoss::Error) -> Error {
Error::CoinTossError(e)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::InvalidInputLength => "invalid input length".fmt(f),
Error::IoError(e) => write!(f, "IO error: {}", e),
Error::Other(s) => write!(f, "other error: {}", s),
Error::CoinTossError(e) => write!(f, "coin toss error: {}", e),
Error::CorrelationCheckFailed => "Correlation check failed!, i.e, w != u'Δ + v".fmt(f),
Error::EqCheckFailed => "EQ check failed!".fmt(f),
Error::InvalidOpening => "Invalid commitment opening!".fmt(f),
}
}
}