1#![doc = include_str!("../README.md")]
2#![deny(clippy::disallowed_methods)]
3#![cfg_attr(
4 not(test),
5 deny(clippy::panic, clippy::unwrap_used, clippy::expect_used)
6)]
7
8use thiserror::Error;
9
10mod common;
11pub mod dlog_with_el_gamal_commitment;
12pub mod multiexp;
13pub mod no_small_factor;
14pub mod paillier_affine_operation_in_range;
15pub mod paillier_blum_modulus;
16pub mod paillier_encryption_in_range;
17pub mod paillier_encryption_in_range_with_el_gamal;
18
19#[cfg(test)]
20mod curve;
21
22#[cfg(all(doctest, not(feature = "__internal_doctest")))]
23compile_error!("doctest require that `__internal_doctest` feature is turned on");
24
25#[cfg(feature = "__internal_doctest")]
26#[doc(hidden)]
27pub mod _doctest;
28
29use common::InvalidProofReason;
30pub use common::{BadExponent, IntegerExt, InvalidProof, PaillierError};
31pub use fast_paillier::{self, backend};
32
33#[derive(Debug, Error)]
35#[error(transparent)]
36pub struct Error(#[from] ErrorReason);
37
38#[derive(Debug, Error)]
39enum ErrorReason {
40 #[error("couldn't evaluate modpow")]
41 ModPow(
42 #[source]
43 #[from]
44 BadExponent,
45 ),
46 #[error("couldn't find residue")]
47 FindResidue,
48 #[error("couldn't encrypt a message")]
49 Encryption,
50 #[error("can't find multiplicative inverse")]
51 Invert,
52 #[error("paillier error")]
53 Paillier(#[source] fast_paillier::Error),
54 #[error("bug: vec has unexpected length")]
55 Length,
56}
57
58impl From<BadExponent> for Error {
59 fn from(err: BadExponent) -> Self {
60 Error(ErrorReason::ModPow(err))
61 }
62}
63
64impl From<PaillierError> for Error {
65 fn from(_err: PaillierError) -> Self {
66 Error(ErrorReason::Encryption)
67 }
68}
69
70impl From<fast_paillier::Error> for Error {
71 fn from(err: fast_paillier::Error) -> Self {
72 Self(ErrorReason::Paillier(err))
73 }
74}