ruscrypt/
lib.rs

1//! # RusCrypt - Lightning-fast cryptography toolkit
2//! 
3//! RusCrypt is a comprehensive cryptography library and CLI tool built with Rust, featuring:
4//! 
5//! - **Classical ciphers**: Caesar, Vigenère, Playfair, Rail Fence
6//! - **Stream ciphers**: RC4
7//! - **Block ciphers**: AES (128/192/256-bit), DES
8//! - **Asymmetric encryption**: RSA, Diffie-Hellman key exchange
9//! - **Hash functions**: MD5, SHA-1, SHA-256
10//! 
11//! ## Library Usage
12//! 
13//! ```rust
14//! use ruscrypt::classical::caesar;
15//! use ruscrypt::hash::sha256;
16//! 
17//! // Caesar cipher encryption
18//! let encrypted = caesar::encrypt("Hello World", 3).unwrap();
19//! assert_eq!(encrypted, "Khoor Zruog");
20//! 
21//! // SHA-256 hashing
22//! let hash = sha256::hash("password").unwrap();
23//! println!("SHA-256: {}", hash);
24//! ```
25//! 
26//! ## CLI Usage
27//! 
28//! Install the binary:
29//! ```bash
30//! cargo install ruscrypt
31//! ```
32//! 
33//! Use the CLI:
34//! ```bash
35//! # Encrypt with Caesar cipher
36//! ruscrypt encrypt --caesar
37//! 
38//! # Hash with SHA-256
39//! ruscrypt hash --sha256
40//! 
41//! # Key exchange with Diffie-Hellman
42//! ruscrypt exchange --dh
43//! ```
44//! 
45//! ## Security Warning
46//! 
47//! ⚠️ **Important**: This library is designed for educational purposes and experimentation.
48//! Some algorithms (RC4, DES, MD5, SHA-1, classical ciphers) are not cryptographically
49//! secure for modern use. For production applications, use AES-256 and RSA with appropriate
50//! key sizes.
51//! 
52//! ## Features
53//! 
54//! - **Zero dependencies** for core crypto algorithms (implementations from scratch)
55//! - **Memory safe** - leverages Rust's ownership system
56//! - **Fast execution** - optimized for performance
57//! - **Educational focus** - clean, readable implementations
58//! - **CLI and library** - use as a command-line tool or integrate into your project
59
60#![warn(missing_docs)]
61#![warn(clippy::all)]
62#![deny(unsafe_code)]
63
64pub mod cli;
65pub mod dispatcher;
66pub mod interactive;
67pub mod utils;
68
69/// Classical cipher implementations (Caesar, Vigenère, Playfair, Rail Fence)
70/// 
71/// These are historical ciphers that are **not secure** for modern use but are
72/// excellent for learning cryptographic concepts.
73pub mod classical;
74
75/// Stream cipher implementations (RC4)
76/// 
77/// ⚠️ **Security Warning**: RC4 has known vulnerabilities and should not be used
78/// in production systems.
79pub mod stream;
80
81/// Block cipher implementations (AES, DES)
82/// 
83/// AES is secure for modern use; DES is deprecated but included for educational purposes.
84pub mod block;
85
86/// Asymmetric cryptography (RSA, Diffie-Hellman)
87/// 
88/// Implementations for public-key cryptography and key exchange protocols.
89pub mod asym;
90
91/// Cryptographic hash functions (MD5, SHA-1, SHA-256)
92/// 
93/// SHA-256 is recommended for modern use; MD5 and SHA-1 are deprecated.
94pub mod hash;
95
96mod tests;
97
98pub use classical::*;
99pub use hash::*;
100pub use stream::*;
101pub use block::*;
102pub use asym::*;
103
104/// Library version information
105/// 
106/// This constant contains the version string extracted from Cargo.toml
107/// at compile time, ensuring version consistency between the library
108/// and its metadata.
109pub const VERSION: &str = env!("CARGO_PKG_VERSION");
110
111/// Get the current library version
112/// 
113/// Returns the version string for the RusCrypt library. This can be used
114/// by applications to display version information or ensure compatibility.
115/// 
116/// # Returns
117/// 
118/// Returns a static string slice containing the semantic version number.
119/// 
120/// # Examples
121/// 
122/// ```rust
123/// use ruscrypt;
124/// 
125/// println!("RusCrypt version: {}", ruscrypt::version());
126/// ```
127pub fn version() -> &'static str {
128    VERSION
129}
130
131/// Quick example demonstrating basic library usage
132/// 
133/// This function provides a simple demonstration of core library functionality
134/// including classical ciphers and modern hash functions. It exists primarily
135/// to ensure documentation examples compile correctly.
136/// 
137/// # Examples
138/// 
139/// The following example shows basic usage patterns:
140/// 
141/// ```rust
142/// use ruscrypt::{classical::caesar, hash::sha256};
143/// 
144/// // Classical cipher encryption/decryption
145/// let encrypted = caesar::encrypt("Hello", 3).unwrap();
146/// let decrypted = caesar::decrypt(&encrypted, 3).unwrap();
147/// assert_eq!(decrypted, "Hello");
148/// 
149/// // Modern hash function
150/// let hash = sha256::hash("test").unwrap();
151/// assert_eq!(hash.len(), 64); // SHA-256 produces 64 hex characters
152/// ```
153/// 
154/// # Note
155/// 
156/// This function exists to validate documentation examples and does not
157/// perform any actual operations when called.
158pub fn quick_example() {
159    // This function exists to ensure the example in docs compiles
160}