Skip to main content

rust_ev_crypto_primitives/basic_crypto_functions/
mod.rs

1// Copyright © 2023 Denis Morel
2
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the GNU General Public License as published by the Free
5// Software Foundation, either version 3 of the License, or (at your option) any
6// later version.
7//
8// This program is distributed in the hope that it will be useful, but WITHOUT
9// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11// details.
12//
13// You should have received a copy of the GNU General Public License and
14// a copy of the GNU General Public License along with this program. If not, see
15// <https://www.gnu.org/licenses/>.
16
17//! Module to wrap the openssl library for crypto functions
18
19mod aes;
20mod argon2;
21mod certificate;
22mod hash;
23mod rand;
24mod signature;
25
26use aes::AESError;
27pub use aes::{Decrypter, Encrypter, CRYPTER_TAG_SIZE};
28pub use argon2::*;
29pub use certificate::*;
30pub use hash::*;
31pub(crate) use rand::*;
32pub use signature::*;
33
34use openssl::error::ErrorStack;
35use thiserror::Error;
36
37#[derive(Error, Debug)]
38#[error(transparent)]
39/// Error in the basis crypto methods
40pub struct BasisCryptoError(#[from] BasisCryptoErrorRepr);
41
42// Enum with the type of error generated by openSSL_wrapper
43#[derive(Error, Debug)]
44enum BasisCryptoErrorRepr {
45    #[error("Error in argon2")]
46    Argon2(#[from] Argon2Error),
47    #[error("Error in generating random bytes")]
48    RandomError { source: ErrorStack },
49    #[error(transparent)]
50    HashError(#[from] HashError),
51    #[error(transparent)]
52    AESError(#[from] AESError),
53    #[error(transparent)]
54    CertificateError(#[from] CertificateError),
55    #[error(transparent)]
56    SignatureError(#[from] SignatureError),
57    #[error("Input too small, since the tag size is 16")]
58    TooSmallInput,
59}