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 ciphertext = sub_arg_matches.value_of("ciphertext").unwrap();
|
||||||
let auto_pbe = sub_arg_matches.is_present("auto-pbe");
|
let auto_pbe = sub_arg_matches.is_present("auto-pbe");
|
||||||
|
|
||||||
let text = if pbeutil::is_simple_pbe_encrypted(ciphertext) {
|
let text = try_decrypt_with_pbe_option(ciphertext, auto_pbe)?;
|
||||||
pbeutil::simple_pbe_decrypt_with_prompt_to_string(&ciphertext)?
|
|
||||||
} else {
|
|
||||||
hmac_decrypt(ciphertext, auto_pbe)?
|
|
||||||
};
|
|
||||||
|
|
||||||
if json_output {
|
if json_output {
|
||||||
let mut json = BTreeMap::<&'_ str, String>::new();
|
let mut json = BTreeMap::<&'_ str, String>::new();
|
||||||
json.insert("plaintext", text);
|
json.insert("plaintext", text);
|
||||||
|
|
||||||
util::print_pretty_json(&json);
|
util::print_pretty_json(&json);
|
||||||
} else {
|
} else {
|
||||||
success!("Plaintext: {}", text);
|
success!("Plaintext: {}", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_decrypt(ciphertext: &str) -> XResult<String> {
|
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) {
|
if is_hmac_encrypted(ciphertext) {
|
||||||
hmac_decrypt(ciphertext, true)
|
hmac_decrypt(ciphertext, auto_pbe)
|
||||||
} else if pbeutil::is_simple_pbe_encrypted(ciphertext) {
|
} else if pbeutil::is_simple_pbe_encrypted(ciphertext) {
|
||||||
pbeutil::simple_pbe_decrypt_with_prompt_to_string(&ciphertext)
|
pbeutil::simple_pbe_decrypt_with_prompt_to_string(&ciphertext)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user