#![cfg(feature = "mock")]
use crate::Error;
#[inline]
pub fn encrypt(_key: &[u8; 64], plaintext_bytes: &[u8]) -> Result<Vec<u8>, Error> {
if plaintext_bytes.is_empty() {
return Err(Error::EmptyPlaintext);
}
Ok(plaintext_bytes.iter().rev().copied().collect())
}
#[inline]
pub fn decrypt(_key: &[u8; 64], data: &[u8]) -> Result<Vec<u8>, Error> {
if data.is_empty() {
return Err(Error::EmptyPayload);
}
Ok(data.iter().rev().copied().collect())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mock2_roundtrip() {
let key = [0u8; 64];
let plaintext = b"hello world";
let ciphertext = encrypt(&key, plaintext).unwrap();
let decrypted = decrypt(&key, &ciphertext).unwrap();
assert_eq!(ciphertext, b"dlrow olleh");
assert_eq!(decrypted, plaintext);
}
#[test]
fn test_mock2_utf8() {
let key = [0u8; 64];
let plaintext = "Hello 世界".as_bytes();
let ciphertext = encrypt(&key, plaintext).unwrap();
let decrypted = decrypt(&key, &ciphertext).unwrap();
assert_eq!(decrypted, plaintext);
}
#[test]
fn test_mock2_empty() {
let key = [0u8; 64];
assert!(encrypt(&key, b"").is_err());
}
}