datex_core/crypto/
crypto.rs

1use crate::stdlib::{future::Future, pin::Pin, usize};
2
3pub trait CryptoTrait: Send + Sync {
4    fn encrypt_rsa(
5        &self,
6        data: Vec<u8>,
7        public_key: Vec<u8>,
8    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, CryptoError>>>>;
9
10    fn decrypt_rsa(
11        &self,
12        data: Vec<u8>,
13        private_key: Vec<u8>,
14    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, CryptoError>>>>;
15
16    fn sign_rsa(
17        &self,
18        data: Vec<u8>,
19        private_key: Vec<u8>,
20    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, CryptoError>>>>;
21
22    fn verify_rsa(
23        &self,
24        data: Vec<u8>,
25        signature: Vec<u8>,
26        public_key: Vec<u8>,
27    ) -> Pin<Box<dyn Future<Output = Result<bool, CryptoError>>>>;
28
29    fn create_uuid(&self) -> String;
30    fn random_bytes(&self, length: usize) -> Vec<u8>;
31
32    fn new_encryption_key_pair(
33        &self,
34    ) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, Vec<u8>), CryptoError>>>>;
35    fn new_sign_key_pair(
36        &self,
37    ) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, Vec<u8>), CryptoError>>>>;
38}
39
40pub struct Crypto;
41
42#[derive(Debug, Clone)]
43pub enum CryptoError {
44    Other(String),
45    KeyGeneratorFailed,
46    KeyExportFailed,
47    KeyImportFailed,
48    EncryptionError,
49    DecryptionError,
50    SigningError,
51    VerificationError,
52}