use core::fmt::{self, Display, Formatter};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub enum Error {
SharingMinThreshold,
SharingLimitLessThanThreshold,
InvalidSizeRequest,
SharingInvalidIdentifier,
SharingDuplicateIdentifier,
SharingMaxRequest,
InvalidShare,
InvalidGenerator(&'static str),
InvalidSecret,
InvalidShareConversion,
NotImplemented,
InvalidShareElement,
NotEnoughShareIdentifiers,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::SharingMinThreshold => write!(f, "Threshold cannot be less than 2"),
Error::SharingLimitLessThanThreshold => write!(f, "Limit is less than threshold"),
Error::InvalidSizeRequest => write!(f, "Requested more shares than space was provided"),
Error::SharingInvalidIdentifier => write!(f, "An invalid share detected"),
Error::SharingDuplicateIdentifier => write!(f, "Duplicate share detected"),
Error::SharingMaxRequest => write!(
f,
"The maximum number of shares to be made when splitting was reached"
),
Error::InvalidShare => write!(
f,
"An invalid share was supplied for verification or combine"
),
Error::InvalidGenerator(s) => write!(
f,
"An invalid generator was supplied for share generation: {}",
s
),
Error::InvalidSecret => write!(f, "An invalid secret was supplied for split"),
Error::InvalidShareConversion => {
write!(f, "A share cannot be converted to a group or field element")
}
Error::NotImplemented => write!(f, "Not implemented"),
Error::InvalidShareElement => write!(f, "Invalid share element"),
Error::NotEnoughShareIdentifiers => write!(f, "Not enough share identifiers available"),
}
}
}
pub type VsssResult<T> = Result<T, Error>;