feat: update hmac decrypt
This commit is contained in:
@@ -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<String> {
|
||||
try_decrypt_with_pbe_option(ciphertext, true)
|
||||
}
|
||||
|
||||
pub fn try_decrypt_with_pbe_option(ciphertext: &str, auto_pbe: bool) -> XResult<String> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user