threshold_pairing/error.rs
1//! Crypto errors.
2
3use thiserror::Error;
4
5/// A crypto error.
6#[derive(Clone, Eq, PartialEq, Debug, Error)]
7pub enum Error {
8 /// Not enough signature shares.
9 #[error("Not enough signature shares")]
10 NotEnoughShares,
11 /// Signature shares contain a duplicated index.
12 #[error("Signature shares contain a duplicated index")]
13 DuplicateEntry,
14 /// The degree is too high for the coefficients to be indexed by `usize`.
15 #[error("The degree is too high for the coefficients to be indexed by usize.")]
16 DegreeTooHigh,
17 /// The ciphertext is invalid (failed integrity verification).
18 ///
19 /// This error is returned when a ciphertext fails the pairing-based integrity check.
20 /// It may indicate tampering, corruption, or a chosen-ciphertext attack attempt.
21 #[error("Invalid ciphertext: integrity verification failed")]
22 InvalidCiphertext,
23 /// A share index maps to the zero scalar, which would expose the master secret.
24 ///
25 /// This occurs when a signed index value (e.g. `-1i32`) is used that causes
26 /// `index + 1 == 0` in the scalar field, making the evaluated point equal to
27 /// `poly(0)` — the master secret.
28 #[error("Share index maps to zero scalar: this would expose the master secret")]
29 IndexMapsToZero,
30 /// A decryption share failed verification against its public key share.
31 ///
32 /// This error is returned by [`crate::PublicKeySet::decrypt_with_verification`] when a
33 /// submitted decryption share does not match the expected value for the corresponding
34 /// public key share. This may indicate a malicious or corrupted participant.
35 #[error("Decryption share failed verification against its public key share")]
36 InvalidShare,
37}
38
39/// A crypto result.
40pub type Result<T> = ::std::result::Result<T, Error>;
41
42#[cfg(test)]
43mod tests {
44 use super::Error;
45
46 /// No-op function that compiles only if its argument is `Send + Sync`.
47 fn is_send_and_sync<T: Send + Sync>(_: T) {}
48
49 #[test]
50 fn errors_are_send_and_sync() {
51 is_send_and_sync(Error::NotEnoughShares);
52 }
53}
54
55/// An error reading a structure from an array of bytes.
56#[derive(Clone, Eq, PartialEq, Debug, Error)]
57pub enum FromBytesError {
58 /// Invalid representation
59 #[error("Invalid representation.")]
60 Invalid,
61}
62
63/// The result of attempting to read a structure from an array of bytes.
64pub type FromBytesResult<T> = ::std::result::Result<T, FromBytesError>;