Skip to main content

streaming_crypto/
lib.rs

1// ## 📝 streaming-crypto/src/lib.rs
2
3// --- MODULES PUBLISH START ---
4#[cfg(feature = "core-api")]
5pub mod core_api;
6
7#[cfg(feature = "ffi-api")]
8pub mod ffi_api;
9
10#[cfg(feature = "pyo3-api")]
11pub mod pyo3_api;
12// --- MODULES PUBLISH END ---
13
14/// Encrypts data by XORing each byte with 0xAA.
15///
16/// # Examples
17///
18/// ```
19/// use streaming_crypto::encrypt;
20///
21/// let data = vec![1, 2, 3];
22/// let encrypted = encrypt(&data);
23/// assert_eq!(encrypted[0], 1 ^ 0xAA);
24/// assert_eq!(encrypted[1], 2 ^ 0xAA);
25/// assert_eq!(encrypted[2], 3 ^ 0xAA);
26/// ```
27#[cfg(feature = "core-api")]
28pub use core_api::encrypt; // re-export everything from core_api
29
30// /// FFI wrapper for encryption.
31// ///
32// /// # Safety
33// /// Returns a raw pointer. Caller must manage memory.
34// ///
35// /// FFI wrapper for encryption.
36// ///
37// /// # Safety
38// /// This function returns a raw pointer. The caller must manage memory.
39// ///
40// /// # Examples
41// ///
42// /// ```
43// /// use std::slice;
44// /// use ffi_api::encrypt;
45// ///
46// /// let data = vec![1, 2, 3];
47// /// let ptr = encrypt(data.as_ptr(), data.len());
48// /// let encrypted = unsafe { slice::from_raw_parts(ptr, data.len()) };
49// /// assert_eq!(encrypted[0], 1 ^ 0xAA);
50// /// ```
51// #[cfg(feature = "ffi-api")]
52// pub use ffi_api::encrypt; // re-export the FFI wrapper
53
54// /// # Examples
55// ///
56// /// ```
57// /// use pyo3::prelude::*;
58// /// use pyo3_api::encrypt;
59// /// use pyo3::types::PyBytes;
60// ///
61// /// Python::with_gil(|py| {
62// ///     let data = PyBytes::new_bound(py, &[1, 2, 3]);
63// ///     
64// ///     let encrypted = encrypt(py, &data).unwrap();
65// /// 
66// ///     assert_eq!(encrypted[0], 1 ^ 0xAA);
67// ///     assert_eq!(encrypted[1], 2 ^ 0xAA);
68// ///     assert_eq!(encrypted[2], 3 ^ 0xAA);
69// /// });
70// /// ```
71// #[cfg(feature = "pyo3-api")]
72// pub use pyo3_api::encrypt; // re-export the PyO3 wrapper
73
74// #[cfg(feature = "pyo3-api")]
75// pub use pyo3_api::streaming_crypto; // re-export the #[pymodule]