#[cfg(feature = "std")]
use thiserror::Error;
#[cfg(not(feature = "std"))]
use thiserror_nostd_notrait::Error;
use crate::{Ciphersuite, Identifier};
#[derive(Error, Debug, Clone, Copy, Eq, PartialEq)]
pub struct ParticipantError<C: Ciphersuite>(Identifier<C>);
#[non_exhaustive]
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum Error<C: Ciphersuite> {
#[error("min_signers must be at least 2 and not larger than max_signers")]
InvalidMinSigners,
#[error("max_signers must be at least 2")]
InvalidMaxSigners,
#[error("coefficients must have min_signers-1 elements")]
InvalidCoefficients,
#[error("Malformed identifier is unserializable.")]
MalformedIdentifier,
#[error("Duplicated identifier.")]
DuplicatedIdentifier,
#[error("Unknown identifier.")]
UnknownIdentifier,
#[error("Incorrect number of identifiers.")]
IncorrectNumberOfIdentifiers,
#[error("Malformed signing key encoding.")]
MalformedSigningKey,
#[error("Malformed verifying key encoding.")]
MalformedVerifyingKey,
#[error("Malformed signature encoding.")]
MalformedSignature,
#[error("Invalid signature.")]
InvalidSignature,
#[error("Duplicated shares provided.")]
DuplicatedShares,
#[error("Incorrect number of shares.")]
IncorrectNumberOfShares,
#[error("Commitment equals the identity.")]
IdentityCommitment,
#[error("The Signing Package must contain the participant's Commitment.")]
MissingCommitment,
#[error("The participant's commitment is incorrect.")]
IncorrectCommitment,
#[error("Incorrect number of commitments.")]
IncorrectNumberOfCommitments,
#[error("Invalid signature share.")]
InvalidSignatureShare {
culprit: Identifier<C>,
},
#[error("Invalid secret share.")]
InvalidSecretShare,
#[error("Round 1 package not found for Round 2 participant.")]
PackageNotFound,
#[error("Incorrect number of packages.")]
IncorrectNumberOfPackages,
#[error("The incorrect package was specified.")]
IncorrectPackage,
#[error("The ciphersuite does not support DKG.")]
DKGNotSupported,
#[error("The proof of knowledge is not valid.")]
InvalidProofOfKnowledge {
culprit: Identifier<C>,
},
#[error("Error in scalar Field.")]
FieldError(#[from] FieldError),
#[error("Error in elliptic curve Group.")]
GroupError(#[from] GroupError),
#[error("Invalid coefficient")]
InvalidCoefficient,
#[error("The ciphersuite does not support deriving identifiers from strings.")]
IdentifierDerivationNotSupported,
#[error("Error serializing value.")]
SerializationError,
#[error("Error deserializing value.")]
DeserializationError,
}
impl<C> Error<C>
where
C: Ciphersuite,
{
pub fn culprit(&self) -> Option<Identifier<C>> {
match self {
Error::InvalidSignatureShare {
culprit: identifier,
}
| Error::InvalidProofOfKnowledge {
culprit: identifier,
} => Some(*identifier),
Error::InvalidSecretShare
| Error::InvalidMinSigners
| Error::InvalidMaxSigners
| Error::InvalidCoefficients
| Error::MalformedIdentifier
| Error::MalformedSigningKey
| Error::MalformedVerifyingKey
| Error::MalformedSignature
| Error::InvalidSignature
| Error::DuplicatedShares
| Error::IncorrectNumberOfShares
| Error::IdentityCommitment
| Error::MissingCommitment
| Error::IncorrectCommitment
| Error::PackageNotFound
| Error::IncorrectNumberOfPackages
| Error::IncorrectPackage
| Error::DKGNotSupported
| Error::FieldError(_)
| Error::GroupError(_)
| Error::DuplicatedIdentifier
| Error::InvalidCoefficient
| Error::UnknownIdentifier
| Error::IncorrectNumberOfIdentifiers
| Error::IncorrectNumberOfCommitments
| Error::SerializationError
| Error::DeserializationError
| Error::IdentifierDerivationNotSupported => None,
}
}
}
#[non_exhaustive]
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum FieldError {
#[error("Malformed scalar encoding.")]
MalformedScalar,
#[error("Invalid for this scalar to be zero.")]
InvalidZeroScalar,
}
#[non_exhaustive]
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum GroupError {
#[error("Malformed group element encoding.")]
MalformedElement,
#[error("Invalid for this element to be the identity.")]
InvalidIdentityElement,
#[error("Invalid for this element to not have large prime order.")]
InvalidNonPrimeOrderElement,
}