arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/crypto-primitives/src/lib.rs
crypto-primitives/src/lib.rsRaw
 1#[macro_use]
 2extern crate bench_utils;
 3
 4#[macro_use]
 5extern crate derivative;
 6
 7pub mod commitment;
 8pub mod crh;
 9pub mod merkle_tree;
10pub mod nizk;
11pub mod prf;
12pub mod signature;
13
14pub use self::{
15    commitment::CommitmentScheme,
16    crh::FixedLengthCRH,
17    merkle_tree::{MerkleHashTree, MerkleTreePath},
18    nizk::NIZK,
19    prf::PRF,
20    signature::SignatureScheme,
21};
22
23#[cfg(feature = "r1cs")]
24pub use self::{
25    commitment::CommitmentGadget, crh::FixedLengthCRHGadget,
26    merkle_tree::constraints::MerkleTreePathGadget, nizk::NIZKVerifierGadget, prf::PRFGadget,
27    signature::SigRandomizePkGadget,
28};
29
30pub type Error = Box<dyn std::error::Error>;
31
32#[derive(Debug)]
33pub enum CryptoError {
34    IncorrectInputLength(usize),
35    NotPrimeOrder,
36}
37
38impl std::fmt::Display for CryptoError {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        let msg = match self {
41            CryptoError::IncorrectInputLength(len) => format!("input length is wrong: {}", len),
42            CryptoError::NotPrimeOrder => "element is not prime order".to_owned(),
43        };
44        write!(f, "{}", msg)
45    }
46}
47
48impl std::error::Error for CryptoError {
49    #[inline]
50    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
51        None
52    }
53}