Skip to main content

fur_cli/security/
io.rs

1use std::fs;
2use std::io::{self, Write};
3use std::path::Path;
4
5use crate::security::crypto;
6use crate::security::state;
7
8pub fn encrypt_file(path: &Path, password: &str) {
9    if let Ok(bytes) = fs::read(path) {
10        if let Ok(enc) = crypto::encrypt(&bytes, password) {
11            let _ = fs::write(path, enc);
12        }
13    }
14}
15
16pub fn decrypt_file(path: &Path, password: &str) {
17    if let Ok(bytes) = fs::read(path) {
18        if let Ok(dec) = crypto::decrypt(&bytes, password) {
19            let _ = fs::write(path, dec);
20        }
21    }
22}
23
24pub fn read_text_file(path: &Path) -> Option<String> {
25    if state::is_locked() {
26        eprintln!("🔒 Project locked. Run `fur unlock`.");
27        return None;
28    }
29
30    fs::read_to_string(path).ok()
31}
32
33pub fn read_visible_password() -> String {
34    print!("🔑 Enter password: ");
35    io::stdout().flush().unwrap();
36
37    let mut pass = String::new();
38    io::stdin().read_line(&mut pass).unwrap();
39
40    pass.trim().to_string()
41}