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 group_element_vs_paillier_encryption_in_range;
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;
17
18#[cfg(test)]
19mod curve;
20
21#[cfg(all(doctest, not(feature = "__internal_doctest")))]
22compile_error!("doctest require that `__internal_doctest` feature is turned on");
23
24#[cfg(feature = "__internal_doctest")]
25pub mod _doctest;
26
27use common::InvalidProofReason;
28pub use common::{BadExponent, IntegerExt, InvalidProof, PaillierError};
29pub use {fast_paillier, rug, rug::Integer};
30
31#[derive(Debug, Error)]
33#[error(transparent)]
34pub struct Error(#[from] ErrorReason);
35
36#[derive(Debug, Error)]
37enum ErrorReason {
38 #[error("couldn't evaluate modpow")]
39 ModPow(
40 #[source]
41 #[from]
42 BadExponent,
43 ),
44 #[error("couldn't find residue")]
45 FindResidue,
46 #[error("couldn't encrypt a message")]
47 Encryption,
48 #[error("can't find multiplicative inverse")]
49 Invert,
50 #[error("paillier error")]
51 Paillier(#[source] fast_paillier::Error),
52 #[error("bug: vec has unexpected length")]
53 Length,
54}
55
56impl From<BadExponent> for Error {
57 fn from(err: BadExponent) -> Self {
58 Error(ErrorReason::ModPow(err))
59 }
60}
61
62impl From<PaillierError> for Error {
63 fn from(_err: PaillierError) -> Self {
64 Error(ErrorReason::Encryption)
65 }
66}
67
68impl From<fast_paillier::Error> for Error {
69 fn from(err: fast_paillier::Error) -> Self {
70 Self(ErrorReason::Paillier(err))
71 }
72}