voided_core/lib.rs
1//! # voided-core
2//!
3//! Core cryptographic primitives for the Voided encryption library.
4//!
5//! This crate provides the source-of-truth implementation for all crypto operations,
6//! ensuring identical behavior across Node.js (native binding) and browser (WASM) targets.
7//!
8//! ## Features
9//!
10//! - `backend` - Full feature set for Node.js backend (default)
11//! - `browser` - Browser-compatible subset for WASM
12//! - `compression` - Brotli and Gzip compression
13//! - `signing` - Digital signatures (Ed25519, ECDSA, RSA-PSS)
14//! - `obfuscation` - Map-based character obfuscation
15//!
16//! ## Example
17//!
18//! ```rust
19//! use voided_core::encryption;
20//!
21//! // Generate a key
22//! let key = encryption::generate_key();
23//!
24//! // Encrypt some data
25//! let plaintext = b"Hello, World!";
26//! let encrypted = encryption::encrypt(plaintext, &key, None).unwrap();
27//!
28//! // Decrypt it back
29//! let decrypted = encryption::decrypt(&encrypted, &key).unwrap();
30//! assert_eq!(plaintext, &decrypted[..]);
31//! ```
32
33#![cfg_attr(not(feature = "std"), no_std)]
34#![deny(unsafe_code)]
35#![warn(missing_docs)]
36#![warn(clippy::all)]
37
38extern crate alloc;
39
40pub mod encryption;
41pub mod hash;
42pub mod formats;
43pub mod util;
44
45#[cfg(feature = "compression")]
46pub mod compression;
47
48#[cfg(feature = "signing")]
49pub mod signing;
50
51#[cfg(feature = "signing")]
52pub use signing::{generate_ed25519_key_pair, sign_ed25519, verify_ed25519};
53
54#[cfg(feature = "obfuscation")]
55pub mod obfuscation;
56
57mod error;
58pub use error::{Error, Result};
59
60/// Library version
61pub const VERSION: &str = env!("CARGO_PKG_VERSION");
62
63/// Wire format version
64pub const FORMAT_VERSION: u8 = 0x01;
65
66/// Magic bytes for encrypted payloads
67pub const MAGIC_ENCRYPTED: &[u8; 4] = b"VOI1";
68
69/// Magic bytes for obfuscation maps
70pub const MAGIC_MAP: &[u8; 4] = b"VOIM";
71
72/// Magic bytes for signatures
73pub const MAGIC_SIGNATURE: &[u8; 4] = b"VOIS";
74
75/// Magic bytes for compression header
76pub const MAGIC_COMPRESSED: &[u8; 2] = b"VC";
77