rust-nex/prudpv0/src/crypto/mod.rs

38 lines
1,017 B
Rust
Raw Normal View History

2026-01-20 20:26:44 +01:00
use cfg_if::cfg_if;
2026-01-27 14:44:10 +01:00
use rnex_core::prudp::types_flags::TypesFlags;
2026-01-20 20:26:44 +01:00
mod common_crypto;
pub trait CryptoInstance: Send + 'static {
fn decrypt_incoming(&mut self, data: &mut [u8]);
fn encrypt_outgoing(&mut self, data: &mut [u8]);
2026-01-27 14:44:10 +01:00
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4];
2026-01-20 20:26:44 +01:00
fn get_user_id(&self) -> u32;
}
pub trait Crypto: Send + Sync + 'static {
type Instance: CryptoInstance;
fn new() -> Self;
fn calculate_checksum(&self, data: &[u8]) -> u8;
2026-01-27 14:44:10 +01:00
fn instantiate(
&self,
data: &[u8],
self_signat: [u8; 4],
remote_signat: [u8; 4],
2026-02-01 21:10:03 +01:00
) -> Option<(Self::Instance, Vec<u8>)>;
2026-01-20 20:26:44 +01:00
}
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::*;
}
}