feat: v1.12.9
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rust_util::util_clap::{Command, CommandError};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{cmdutil, hmacutil, pbeutil, util};
|
||||
use rust_util::XResult;
|
||||
use crate::{cmdutil, pbeutil, util};
|
||||
use crate::hmacutil::{hmac_decrypt_to_string, is_hmac_encrypted};
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -29,12 +30,9 @@ impl Command for CommandImpl {
|
||||
let json_output = cmdutil::check_json_output(sub_arg_matches);
|
||||
|
||||
let ciphertext = sub_arg_matches.value_of("ciphertext").unwrap();
|
||||
let mut text = hmacutil::hmac_decrypt_to_string(ciphertext)?;
|
||||
|
||||
let auto_pbe = sub_arg_matches.is_present("auto-pbe");
|
||||
if auto_pbe && pbeutil::is_simple_pbe_encrypted(&text) {
|
||||
text = pbeutil::simple_pbe_decrypt_with_prompt_to_string(&text)?;
|
||||
}
|
||||
|
||||
let text = hmac_decrypt(ciphertext, auto_pbe)?;
|
||||
|
||||
if json_output {
|
||||
let mut json = BTreeMap::<&'_ str, String>::new();
|
||||
@@ -48,3 +46,20 @@ impl Command for CommandImpl {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_hmac_decrypt(ciphertext: &str) -> XResult<String> {
|
||||
if is_hmac_encrypted(ciphertext) {
|
||||
hmac_decrypt(ciphertext, true)
|
||||
} else {
|
||||
Ok(ciphertext.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hmac_decrypt(ciphertext: &str, auto_pbe: bool) -> XResult<String> {
|
||||
let text = hmac_decrypt_to_string(ciphertext)?;
|
||||
if auto_pbe && pbeutil::is_simple_pbe_encrypted(&text) {
|
||||
Ok(pbeutil::simple_pbe_decrypt_with_prompt_to_string(&text)?)
|
||||
} else {
|
||||
Ok(text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user