feat: update argument output-type to output-format
This commit is contained in:
@@ -63,9 +63,9 @@ pub struct CmdSimpleDecrypt {
|
||||
#[arg(long, short = 'v')]
|
||||
pub value: Option<String>,
|
||||
|
||||
/// Decrypt result output type (plain, hex, bse64)
|
||||
/// Decrypt result output format (plain, hex, bse64)
|
||||
#[arg(long, short = 'o')]
|
||||
pub output_type: Option<String>,
|
||||
pub output_format: Option<String>,
|
||||
}
|
||||
|
||||
impl CmdSimpleEncrypt {
|
||||
@@ -180,10 +180,10 @@ pub fn inner_simple_decrypt(cmd_simple_decrypt: CmdSimpleDecrypt) -> XResult<()>
|
||||
let pin = cmd_simple_decrypt.pin.clone().or_else(util_env::get_pin);
|
||||
let slot = cmd_simple_decrypt.slot.clone();
|
||||
|
||||
let output_type = cmd_simple_decrypt.output_type.as_deref().unwrap_or("plain");
|
||||
match output_type {
|
||||
let output_format = cmd_simple_decrypt.output_format.as_deref().unwrap_or("plain");
|
||||
match output_format {
|
||||
"plain" | "hex" | "base64" => (),
|
||||
_ => return simple_error!("not supported output type: {}", output_type),
|
||||
_ => return simple_error!("not supported output format: {}", output_format),
|
||||
};
|
||||
|
||||
let value = match cmd_simple_decrypt.get_value()? {
|
||||
@@ -216,11 +216,11 @@ pub fn inner_simple_decrypt(cmd_simple_decrypt: CmdSimpleDecrypt) -> XResult<()>
|
||||
return simple_error!("too many envelops: {:?}, len: {}", cmd_simple_decrypt.key_id, filter_envelops.len());
|
||||
}
|
||||
let value = try_decrypt_key(&config, filter_envelops[0], &pin, &slot, false)?;
|
||||
let value = match output_type {
|
||||
let value = match output_format {
|
||||
"plain" => opt_result!(String::from_utf8(value), "bad value encoding: {}"),
|
||||
"hex" => hex::encode(&value),
|
||||
"base64" => STANDARD.encode(&value),
|
||||
_ => return simple_error!("not supported output type: {}", output_type),
|
||||
_ => return simple_error!("not supported output format: {}", output_format),
|
||||
};
|
||||
CmdResult::success(&value).print_exit();
|
||||
}
|
||||
Reference in New Issue
Block a user