Skip to main content

streaming_crypto/core_api/
mod.rs

1// ## 📝 core-api/src/lib.rs
2
3/// Encrypts data by XORing each byte with 0xAA.
4///
5/// # Examples
6///
7/// ```
8/// use core_api::encrypt;
9///
10/// let data = vec![1, 2, 3];
11/// let encrypted = encrypt(&data);
12/// assert_eq!(encrypted[0], 1 ^ 0xAA);
13/// ```
14pub fn encrypt(data: &[u8]) -> Vec<u8> {
15    data.iter().map(|b| b ^ 0xAA).collect()
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn test_encrypt_core_api() {
24        let data = vec![1, 2, 3];
25        let encrypted = encrypt(&data);
26
27        // Check length matches
28        assert_eq!(encrypted.len(), data.len());
29
30        // Check XOR transformation
31        assert_eq!(encrypted[0], 1 ^ 0xAA);
32        assert_eq!(encrypted[1], 2 ^ 0xAA);
33        assert_eq!(encrypted[2], 3 ^ 0xAA);
34    }
35}