1use crate::{Ciphersuite, Identifier};
4use thiserror::Error;
5
6#[non_exhaustive]
8#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
9pub enum Error<C: Ciphersuite> {
10 #[error("min_signers must be at least 2 and not larger than max_signers")]
12 InvalidMinSigners,
13 #[error("max_signers must be at least 2")]
15 InvalidMaxSigners,
16 #[error("coefficients must have min_signers-1 elements")]
18 InvalidCoefficients,
19 #[error("Malformed identifier is unserializable.")]
21 MalformedIdentifier,
22 #[error("Duplicated identifier.")]
24 DuplicatedIdentifier,
25 #[error("Unknown identifier.")]
27 UnknownIdentifier,
28 #[error("Incorrect number of identifiers.")]
30 IncorrectNumberOfIdentifiers,
31 #[error("Malformed signing key encoding.")]
33 MalformedSigningKey,
34 #[error("Malformed verifying key encoding.")]
36 MalformedVerifyingKey,
37 #[error("Malformed signature encoding.")]
39 MalformedSignature,
40 #[error("Invalid signature.")]
42 InvalidSignature,
43 #[error("Duplicated shares provided.")]
45 DuplicatedShares,
46 #[error("Incorrect number of shares.")]
48 IncorrectNumberOfShares,
49 #[error("Commitment equals the identity.")]
51 IdentityCommitment,
52 #[error("The Signing Package must contain the participant's Commitment.")]
54 MissingCommitment,
55 #[error("The participant's commitment is incorrect.")]
57 IncorrectCommitment,
58 #[error("Incorrect number of commitments.")]
60 IncorrectNumberOfCommitments,
61 #[error("Invalid signature share.")]
63 InvalidSignatureShare {
64 culprit: Identifier<C>,
66 },
67 #[error("Invalid secret share.")]
69 InvalidSecretShare {
70 culprit: Option<Identifier<C>>,
73 },
74 #[error("Round 1 package not found for Round 2 participant.")]
76 PackageNotFound,
77 #[error("Incorrect number of packages.")]
79 IncorrectNumberOfPackages,
80 #[error("The incorrect package was specified.")]
82 IncorrectPackage,
83 #[error("The ciphersuite does not support DKG.")]
85 DKGNotSupported,
86 #[error("The proof of knowledge is not valid.")]
88 InvalidProofOfKnowledge {
89 culprit: Identifier<C>,
91 },
92 #[error("Error in scalar Field.")]
94 FieldError(#[from] FieldError),
95 #[error("Error in elliptic curve Group.")]
97 GroupError(#[from] GroupError),
98 #[error("Invalid coefficient")]
100 InvalidCoefficient,
101 #[error("The ciphersuite does not support deriving identifiers from strings.")]
103 IdentifierDerivationNotSupported,
104 #[error("Error serializing value.")]
106 SerializationError,
107 #[error("Error deserializing value.")]
109 DeserializationError,
110}
111
112impl<C> Error<C>
113where
114 C: Ciphersuite,
115{
116 pub fn culprit(&self) -> Option<Identifier<C>> {
122 match self {
125 Error::InvalidSignatureShare {
126 culprit: identifier,
127 }
128 | Error::InvalidProofOfKnowledge {
129 culprit: identifier,
130 } => Some(*identifier),
131 Error::InvalidSecretShare {
132 culprit: identifier,
133 } => *identifier,
134 Error::InvalidMinSigners
135 | Error::InvalidMaxSigners
136 | Error::InvalidCoefficients
137 | Error::MalformedIdentifier
138 | Error::MalformedSigningKey
139 | Error::MalformedVerifyingKey
140 | Error::MalformedSignature
141 | Error::InvalidSignature
142 | Error::DuplicatedShares
143 | Error::IncorrectNumberOfShares
144 | Error::IdentityCommitment
145 | Error::MissingCommitment
146 | Error::IncorrectCommitment
147 | Error::PackageNotFound
148 | Error::IncorrectNumberOfPackages
149 | Error::IncorrectPackage
150 | Error::DKGNotSupported
151 | Error::FieldError(_)
152 | Error::GroupError(_)
153 | Error::DuplicatedIdentifier
154 | Error::InvalidCoefficient
155 | Error::UnknownIdentifier
156 | Error::IncorrectNumberOfIdentifiers
157 | Error::IncorrectNumberOfCommitments
158 | Error::SerializationError
159 | Error::DeserializationError
160 | Error::IdentifierDerivationNotSupported => None,
161 }
162 }
163}
164
165#[non_exhaustive]
167#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
168pub enum FieldError {
169 #[error("Malformed scalar encoding.")]
171 MalformedScalar,
172 #[error("Invalid for this scalar to be zero.")]
174 InvalidZeroScalar,
175}
176
177#[non_exhaustive]
179#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
180pub enum GroupError {
181 #[error("Malformed group element encoding.")]
183 MalformedElement,
184 #[error("Invalid for this element to be the identity.")]
186 InvalidIdentityElement,
187 #[error("Invalid for this element to not have large prime order.")]
189 InvalidNonPrimeOrderElement,
190}