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 Lesser 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 Lesser 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
26pub use aes::Decrypter;
27pub use argon2::*;
28pub use certificate::*;
29pub use hash::*;
30pub(crate) use rand::*;
31pub use signature::*;
32
33use openssl::error::ErrorStack;
34use std::{io, path::PathBuf};
35use thiserror::Error;
36
37// Enum with the type of error generated by openSSL_wrapper
38#[derive(Error, Debug)]
39pub enum BasisCryptoError {
40    #[error("Path is not a directory {path}")]
41    Dir { path: String },
42    #[error("IO error caused by {source}: {msg}")]
43    IO { msg: String, source: io::Error },
44    #[error("Keystore error {msg} caused by {source}")]
45    Keystore { msg: String, source: ErrorStack },
46    #[error("Keystore has a wrong format: {0}")]
47    KeystoreWrongFormat(String),
48    #[error("Keystore {0} has no secret key")]
49    KeyStoreMissingSecretKey(PathBuf),
50    #[error("Keystore {0} has no certificate for the secret key")]
51    KeyStoreMissingCertSecretKey(PathBuf),
52    #[error("Keystore {0} has no list of CA")]
53    KeyStoreMissingCAList(PathBuf),
54    #[error("The ca with name {name} is not present in the Keystore {path}")]
55    KeyStoreMissingCA { path: PathBuf, name: String },
56    #[error("Error reading public key in the certificate {name} caused by {source}")]
57    CertificateErrorPK { name: String, source: ErrorStack },
58    #[error("Error of time during time check of the certificate {name} caused by {source}")]
59    CertificateErrorTime { name: String, source: ErrorStack },
60    #[error("Digest (Fingerprint) error caused by {source}: {msg}")]
61    CertificateDigest { msg: String, source: ErrorStack },
62    #[error("PublicKey error caused by {source}: {msg}")]
63    PublicKeyError { msg: String, source: ErrorStack },
64    #[error("Secretkey error caused by {source}: {msg}")]
65    SecretKeyError { msg: String, source: ErrorStack },
66    #[error("{msg} caused by {source}")]
67    SignatureVerify { msg: String, source: ErrorStack },
68    #[error("{msg} caused by {source}")]
69    Sign { msg: String, source: ErrorStack },
70    #[error("Hash error caused by {source}: {msg}")]
71    HashError { msg: String, source: ErrorStack },
72    #[error("Buffer Hash error caused by {source}: {msg}")]
73    BufferHashError { msg: String, source: std::io::Error },
74    #[error("Argon2 error caused by {argon2_error_source}: {msg}")]
75    Argon2Error {
76        msg: String,
77        argon2_error_source: Argon2Error,
78    },
79    #[error("Random error caused by {source}: {msg}")]
80    RandomError { msg: String, source: ErrorStack },
81    #[error("Secretkey error caused by {source}: {msg}")]
82    AesGcmError { msg: String, source: ErrorStack },
83}