commit f934fff380b682c7da1edaa352e54a3b49e5078c
parent 682b0f6a650151b18d0b86c656bde9f55da66f45
Author: Stefan Koch <programming@stefan-koch.name>
Date: Sun, 24 Nov 2019 13:06:48 +0100
always use .cinderella/secrets.toml for encrypted variables
Diffstat:
2 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
@@ -127,16 +127,19 @@ pub fn run(exec_config: &ExecutionConfig) {
}
}
-pub fn encrypt(filepath: String, password: &str) {
- let plaintext = "some data";
+pub fn encrypt(plainpath: &str, cipherpath: &str, password: &str) {
+ let plaintext = fs::read_to_string(plainpath)
+ .expect("Unable to read file");
- let cipher = crypto::encrypt_string(plaintext, password);
- fs::write(filepath, cipher).expect("Unable to write file");
+ let cipher = crypto::encrypt_string(&plaintext, password);
+ fs::write(cipherpath, cipher).expect("Unable to write file");
}
-pub fn decrypt(filepath: String, password: &str) {
- match crypto::decrypt_file(&filepath, password) {
- Ok(plaintext) => println!("{}", plaintext),
+pub fn decrypt(cipherpath: &str, plainpath: &str, password: &str) {
+ match crypto::decrypt_file(&cipherpath, password) {
+ Ok(plaintext) => {
+ fs::write(plainpath, plaintext).expect("Unable to write file");
+ },
_ => println!("Cannot decrypt, probably wrong password"),
}
}
diff --git a/src/main.rs b/src/main.rs
@@ -17,35 +17,23 @@ fn main() {
} else {
match args[1].as_ref() {
"run" => run(args),
- "encrypt" => encrypt(args),
- "decrypt" => decrypt(args),
+ "encrypt" => encrypt(),
+ "decrypt" => decrypt(),
_ => println!("Unknown command!"),
};
}
}
-fn encrypt(args: Vec<String>) {
- if args.len() < 3 {
- println!("Please provide the path to a file");
- } else {
- let filepath = args[2].clone();
-
- let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap();
+fn encrypt() {
+ let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap();
- cinderella::encrypt(filepath, &pass);
- }
+ cinderella::encrypt(".cinderella/secrets.toml", ".cinderella/secrets", &pass);
}
-fn decrypt(args: Vec<String>) {
- if args.len() < 3 {
- println!("Please provide the path to a file");
- } else {
- let filepath = args[2].clone();
-
- let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap();
+fn decrypt() {
+ let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap();
- cinderella::decrypt(filepath, &pass);
- }
+ cinderella::decrypt(".cinderella/secrets", ".cinderella/secrets.toml", &pass);
}
fn run(args: Vec<String>) {