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