1use core::fmt::{self, Display, Formatter};
7
8#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
10pub enum Error {
11 SharingMinThreshold,
13 SharingLimitLessThanThreshold,
15 InvalidSizeRequest,
18 SharingInvalidIdentifier,
20 SharingDuplicateIdentifier,
22 SharingMaxRequest,
24 InvalidShare,
26 InvalidGenerator(&'static str),
28 InvalidSecret,
30 InvalidShareConversion,
32 NotImplemented,
34 InvalidShareElement,
36 NotEnoughShareIdentifiers,
38}
39
40impl Display for Error {
41 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
42 match self {
43 Error::SharingMinThreshold => write!(f, "Threshold cannot be less than 2"),
44 Error::SharingLimitLessThanThreshold => write!(f, "Limit is less than threshold"),
45 Error::InvalidSizeRequest => write!(f, "Requested more shares than space was provided"),
46 Error::SharingInvalidIdentifier => write!(f, "An invalid share detected"),
47 Error::SharingDuplicateIdentifier => write!(f, "Duplicate share detected"),
48 Error::SharingMaxRequest => write!(
49 f,
50 "The maximum number of shares to be made when splitting was reached"
51 ),
52 Error::InvalidShare => write!(
53 f,
54 "An invalid share was supplied for verification or combine"
55 ),
56 Error::InvalidGenerator(s) => write!(
57 f,
58 "An invalid generator was supplied for share generation: {}",
59 s
60 ),
61 Error::InvalidSecret => write!(f, "An invalid secret was supplied for split"),
62 Error::InvalidShareConversion => {
63 write!(f, "A share cannot be converted to a group or field element")
64 }
65 Error::NotImplemented => write!(f, "Not implemented"),
66 Error::InvalidShareElement => write!(f, "Invalid share element"),
67 Error::NotEnoughShareIdentifiers => write!(f, "Not enough share identifiers available"),
68 }
69 }
70}
71
72pub type VsssResult<T> = Result<T, Error>;