diff --git a/src/cmd_hmac_decrypt.rs b/src/cmd_hmac_decrypt.rs index c778ef2..382d700 100644 --- a/src/cmd_hmac_decrypt.rs +++ b/src/cmd_hmac_decrypt.rs @@ -32,28 +32,26 @@ impl Command for CommandImpl { let ciphertext = sub_arg_matches.value_of("ciphertext").unwrap(); let auto_pbe = sub_arg_matches.is_present("auto-pbe"); - let text = if pbeutil::is_simple_pbe_encrypted(ciphertext) { - pbeutil::simple_pbe_decrypt_with_prompt_to_string(&ciphertext)? - } else { - hmac_decrypt(ciphertext, auto_pbe)? - }; + let text = try_decrypt_with_pbe_option(ciphertext, auto_pbe)?; if json_output { let mut json = BTreeMap::<&'_ str, String>::new(); json.insert("plaintext", text); - util::print_pretty_json(&json); } else { success!("Plaintext: {}", text); } - Ok(None) } } pub fn try_decrypt(ciphertext: &str) -> XResult { + try_decrypt_with_pbe_option(ciphertext, true) +} + +pub fn try_decrypt_with_pbe_option(ciphertext: &str, auto_pbe: bool) -> XResult { if is_hmac_encrypted(ciphertext) { - hmac_decrypt(ciphertext, true) + hmac_decrypt(ciphertext, auto_pbe) } else if pbeutil::is_simple_pbe_encrypted(ciphertext) { pbeutil::simple_pbe_decrypt_with_prompt_to_string(&ciphertext) } else {