pub use crate::core::{
CargoCrypt, CargoCryptBuilder, CryptoConfig, SecretBytes,
ResilienceManager, ResilienceConfig
};
pub use crate::crypto::{
CryptoEngine, DerivedKey, EncryptedSecret, PlaintextSecret,
SecretMetadata, SecretType as CryptoSecretType, PerformanceProfile, EncryptionOptions,
CryptoError, CryptoResult as CryptoCoreResult
};
pub use crate::error::{CargoCryptError, ErrorKind, CryptoResult};
pub use crate::detection::{
SecretDetector, ScanOptions, DetectionConfig, Finding, FoundSecret,
SecretType as DetectionSecretType, PatternMatch, EntropyResult, CustomRule, RuleEngine,
};
pub mod core;
pub mod crypto;
pub mod error;
pub mod validation;
pub mod resilience;
pub mod monitoring;
pub mod detection;
pub mod git;
pub mod tui {
pub mod monitoring;
}
pub mod tui_simple;
pub fn default_config() -> CryptoConfig {
CryptoConfig::default()
}
pub async fn init() -> CryptoResult<()> {
CargoCrypt::init_project().await
}
pub async fn encrypt<P: AsRef<std::path::Path>>(path: P, password: &str) -> CryptoResult<std::path::PathBuf> {
let crypt = CargoCrypt::new().await?;
crypt.encrypt_file(path, password).await
}
pub async fn decrypt<P: AsRef<std::path::Path>>(path: P, password: &str) -> CryptoResult<std::path::PathBuf> {
let crypt = CargoCrypt::new().await?;
crypt.decrypt_file(path, password).await
}
pub mod utils {
use crate::CryptoResult;
use std::path::Path;
pub fn is_encrypted<P: AsRef<Path>>(path: P) -> bool {
path.as_ref()
.extension()
.map(|ext| ext == "enc")
.unwrap_or(false)
}
pub fn original_filename<P: AsRef<Path>>(encrypted_path: P) -> Option<String> {
encrypted_path
.as_ref()
.file_stem()
.and_then(|stem| stem.to_str())
.map(|s| s.to_string())
}
pub fn is_rust_project() -> bool {
Path::new("Cargo.toml").exists()
}
pub fn find_project_root() -> CryptoResult<std::path::PathBuf> {
let mut current = std::env::current_dir()?;
loop {
if current.join("Cargo.toml").exists() {
return Ok(current);
}
if !current.pop() {
break;
}
}
Err(crate::error::CargoCryptError::project_not_found())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_encrypted() {
assert!(utils::is_encrypted("file.txt.enc"));
assert!(!utils::is_encrypted("file.txt"));
assert!(!utils::is_encrypted("file"));
}
#[test]
fn test_original_filename() {
assert_eq!(utils::original_filename("file.txt.enc"), Some("file.txt".to_string()));
assert_eq!(utils::original_filename("secrets.rs.enc"), Some("secrets.rs".to_string()));
assert_eq!(utils::original_filename("file.txt"), Some("file".to_string()));
}
#[test]
fn test_default_config() {
let config = default_config();
assert!(!config.performance_profiles().is_empty());
}
}