sekrit 1.0.0

Encrypt any file, decrypt anywhere. File encryption that doesn't suck.
Documentation
//! # sekrit 🤫
//!
//! **Encrypt any file, decrypt anywhere. File encryption that doesn't suck.**
//!
//! ## Quick Start
//!
//! ```rust
//! use sekrit::{CryptoEngine, EncryptedFile, FileOps};
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Encrypt some data
//! let data = b"secret information";
//! let password = "super_secret_password";
//! let encrypted_file = CryptoEngine::encrypt_file_data(data, password)?;
//!
//! // Save to disk
//! let path = Path::new("secret.enc");
//! FileOps::write_encrypted_file(&path, &encrypted_file)?;
//!
//! // Load and decrypt
//! let loaded_file = FileOps::read_encrypted_file(&path)?;
//! let decrypted_data = CryptoEngine::decrypt_file_data(&loaded_file, password)?;
//!
//! assert_eq!(data, decrypted_data.as_slice());
//! # std::fs::remove_file(path).ok(); // cleanup for doctest
//! # Ok(())
//! # }
//! ```
//!
//! ## Security Features
//!
//! - **ChaCha20-Poly1305**: Authenticated encryption with 256-bit keys
//! - **Argon2id**: Memory-hard key derivation with random salts
//! - **Memory safety**: Automatic key zeroization after use
//! - **Authenticated**: Built-in integrity protection via AEAD
//!
//! ## Modules
//!
//! - [`crypto`] - Core encryption/decryption engine
//! - [`file_ops`] - File I/O operations for encrypted files
//! - [`types`] - Data structures for encrypted file metadata
//! - [`utils`] - Utility functions for file handling

pub mod crypto;
pub mod file_ops;
pub mod types;
pub mod utils;

// Re-export main types for convenience
pub use crypto::CryptoEngine;
pub use file_ops::FileOps;
pub use types::EncryptedFile;
pub use utils::restore_original_extension;

/// Result type alias for sekrit operations
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";

        // Encrypt
        let encrypted_file = CryptoEngine::encrypt_file_data(original_data, password)
            .expect("Encryption should succeed");

        // Save to file
        FileOps::write_encrypted_file(&file_path, &encrypted_file)
            .expect("File write should succeed");

        // Load from file
        let loaded_encrypted_file =
            FileOps::read_encrypted_file(&file_path).expect("File read should succeed");

        // Decrypt
        let decrypted_data = CryptoEngine::decrypt_file_data(&loaded_encrypted_file, password)
            .expect("Decryption should succeed");

        // Verify
        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");

        // Create original file
        std::fs::write(&original_file, "Confidential document content").unwrap();

        // Read, encrypt, and save
        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();

        // Load, decrypt, and verify
        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);

        // Test file extension restoration
        let restored_path = restore_original_extension(&encrypted_file_path);
        assert_eq!(restored_path, original_file);
    }
}