pub mod crypto;
pub mod file_ops;
pub mod types;
pub mod utils;
pub use crypto::CryptoEngine;
pub use file_ops::FileOps;
pub use types::EncryptedFile;
pub use utils::restore_original_extension;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[cfg(test)]
mod integration_tests {
use super::*;
use tempfile::TempDir;
#[test]
fn test_full_encryption_cycle() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let file_path = temp_dir.path().join("test.enc");
let original_data = b"Hello, World! This is integration test data.";
let password = "integration_test_password";
let encrypted_file = CryptoEngine::encrypt_file_data(original_data, password)
.expect("Encryption should succeed");
FileOps::write_encrypted_file(&file_path, &encrypted_file)
.expect("File write should succeed");
let loaded_encrypted_file =
FileOps::read_encrypted_file(&file_path).expect("File read should succeed");
let decrypted_data = CryptoEngine::decrypt_file_data(&loaded_encrypted_file, password)
.expect("Decryption should succeed");
assert_eq!(original_data, decrypted_data.as_slice());
}
#[test]
fn test_library_api_workflow() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let original_file = temp_dir.path().join("document.txt");
let encrypted_file_path = temp_dir.path().join("document.txt.sekrit");
std::fs::write(&original_file, "Confidential document content").unwrap();
let file_data = FileOps::read_file(&original_file).unwrap();
let encrypted_file = CryptoEngine::encrypt_file_data(&file_data, "password123").unwrap();
FileOps::write_encrypted_file(&encrypted_file_path, &encrypted_file).unwrap();
let loaded_file = FileOps::read_encrypted_file(&encrypted_file_path).unwrap();
let decrypted_data = CryptoEngine::decrypt_file_data(&loaded_file, "password123").unwrap();
assert_eq!(file_data, decrypted_data);
let restored_path = restore_original_extension(&encrypted_file_path);
assert_eq!(restored_path, original_file);
}
}