ark_crypto_primitives/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(
    unused,
    future_incompatible,
    nonstandard_style,
    rust_2018_idioms,
    // missing_docs
)]
#![forbid(unsafe_code)]

#[macro_use]
extern crate ark_std;

#[allow(unused_imports)]
#[macro_use]
extern crate derivative;

#[allow(unused_imports)]
pub(crate) use ark_std::{borrow::ToOwned, boxed::Box, vec::Vec};
mod macros;

#[cfg(feature = "commitment")]
pub mod commitment;

#[cfg(feature = "crh")]
pub mod crh;

#[cfg(feature = "merkle_tree")]
pub mod merkle_tree;

#[cfg(feature = "encryption")]
pub mod encryption;

#[cfg(feature = "prf")]
pub mod prf;

#[cfg(feature = "signature")]
pub mod signature;

#[cfg(feature = "snark")]
pub mod snark;

#[cfg(feature = "sponge")]
pub mod sponge;

#[derive(Debug)]
pub enum Error {
    IncorrectInputLength(usize),
    NotPrimeOrder,
    GenericError(Box<dyn ark_std::error::Error + Send>),
    SerializationError(ark_serialize::SerializationError),
}

impl ark_std::fmt::Display for Error {
    fn fmt(&self, f: &mut ark_std::fmt::Formatter<'_>) -> ark_std::fmt::Result {
        match self {
            Self::IncorrectInputLength(len) => write!(f, "incorrect input length: {len}"),
            Self::NotPrimeOrder => write!(f, "element is not prime order"),
            Self::GenericError(e) => write!(f, "{e}"),
            Self::SerializationError(e) => write!(f, "{e}"),
        }
    }
}

impl ark_std::error::Error for Error {}

impl From<ark_serialize::SerializationError> for Error {
    fn from(e: ark_serialize::SerializationError) -> Self {
        Self::SerializationError(e)
    }
}