feat: update base64 version

This commit is contained in:
2023-08-26 12:02:45 +08:00
parent 2ada122834
commit 1698e2d9f8
12 changed files with 47 additions and 24 deletions

View File

@@ -1,11 +1,13 @@
use std::collections::BTreeMap;
use clap::{App, Arg, ArgMatches, SubCommand};
use openpgp_card::OpenPgp;
use openpgp_card::crypto_data::Cryptogram;
use openpgp_card::OpenPgp;
use rust_util::util_clap::{Command, CommandError};
use rust_util::util_msg;
use crate::util::{base64_decode, base64_encode};
pub struct CommandImpl;
impl Command for CommandImpl {
@@ -34,7 +36,7 @@ impl Command for CommandImpl {
let cipher_bytes = if let Some(cipher) = cipher {
opt_result!(hex::decode(cipher), "Decode cipher failed: {}")
} else if let Some(cipher_base64) = cipher_base64 {
opt_result!(base64::decode(cipher_base64), "Decode cipher-base64 failed: {}")
opt_result!(base64_decode(cipher_base64), "Decode cipher-base64 failed: {}")
} else {
return simple_error!("cipher or cipher-base64 must assign one");
};
@@ -48,15 +50,15 @@ impl Command for CommandImpl {
let text = trans.decipher(Cryptogram::RSA(&cipher_bytes))?;
success!("Clear text HEX: {}", hex::encode(&text));
success!("Clear text base64: {}", base64::encode(&text));
success!("Clear text base64: {}", base64_encode(&text));
success!("Clear text UTF-8: {}", String::from_utf8_lossy(&text));
if json_output {
let mut json = BTreeMap::<&'_ str, String>::new();
json.insert("cipher_hex", hex::encode(&cipher_bytes));
json.insert("cipher_base64", base64::encode(&cipher_bytes));
json.insert("cipher_base64", base64_encode(&cipher_bytes));
json.insert("text_hex", hex::encode(&text));
json.insert("text_base64", base64::encode(&text));
json.insert("text_base64", base64_encode(&text));
json.insert("text_utf8", String::from_utf8_lossy(&text).to_string());
println!("{}", serde_json::to_string_pretty(&json).unwrap());