rust-nex/prudpv0/src/crypto/mod.rs
Maple Nebel f1d16e40a1 progress
2026-07-13 23:47:15 +02:00

39 lines
1 KiB
Rust

use cfg_if::cfg_if;
use rnex_prudp::types_flags::TypesFlags;
use rnex_util::PID;
mod common_crypto;
pub trait CryptoInstance: Send + 'static {
fn decrypt_incoming(&mut self, data: &mut [u8]);
fn encrypt_outgoing(&mut self, data: &mut [u8]);
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4];
fn get_user_id(&self) -> PID;
}
pub trait Crypto: Send + Sync + 'static {
type Instance: CryptoInstance;
async fn new() -> Self;
fn calculate_checksum(&self, data: &[u8]) -> u8;
fn instantiate(
&self,
data: &[u8],
self_signat: [u8; 4],
remote_signat: [u8; 4],
) -> Option<(Self::Instance, Vec<u8>)>;
}
cfg_if! {
if #[cfg(feature = "friends")]{
pub mod friends_common;
pub mod friends_insecure;
pub use friends_insecure::*;
pub mod friends_secure;
pub use friends_secure::*;
} else {
pub mod secure;
pub use secure::*;
pub mod insecure;
pub use insecure::*;
}
}