Skip to main content

threshold_crypto/
error.rs

1//! Crypto errors.
2
3use failure::Fail;
4
5/// A crypto error.
6#[derive(Clone, Eq, PartialEq, Debug, Fail)]
7pub enum Error {
8    /// Not enough signature shares.
9    #[fail(display = "Not enough signature shares")]
10    NotEnoughShares,
11    /// Signature shares contain a duplicated index.
12    #[fail(display = "Signature shares contain a duplicated index")]
13    DuplicateEntry,
14    /// The degree is too high for the coefficients to be indexed by `usize`.
15    #[fail(display = "The degree is too high for the coefficients to be indexed by usize.")]
16    DegreeTooHigh,
17}
18
19/// A crypto result.
20pub type Result<T> = ::std::result::Result<T, Error>;
21
22#[cfg(test)]
23mod tests {
24    use super::Error;
25
26    /// No-op function that compiles only if its argument is `Send + Sync`.
27    fn is_send_and_sync<T: Send + Sync>(_: T) {}
28
29    #[test]
30    fn errors_are_send_and_sync() {
31        is_send_and_sync(Error::NotEnoughShares);
32    }
33}
34
35/// An error reading a structure from an array of bytes.
36#[derive(Clone, Eq, PartialEq, Debug, Fail)]
37pub enum FromBytesError {
38    /// Invalid representation
39    #[fail(display = "Invalid representation.")]
40    Invalid,
41}
42
43/// The result of attempting to read a structure from an array of bytes.
44pub type FromBytesResult<T> = ::std::result::Result<T, FromBytesError>;