From 1c08f1c264478f0c6d2354b7cbc9919850437161 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 5 Oct 2023 17:24:57 +0800 Subject: [PATCH] feat: v1.7.4 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd_pgpcarddecrypt.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 199fc20..2509ffb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,7 +320,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.7.3" +version = "1.7.4" dependencies = [ "authenticator", "base64 0.21.4", diff --git a/Cargo.toml b/Cargo.toml index 3833125..d094f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.7.3" +version = "1.7.4" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/cmd_pgpcarddecrypt.rs b/src/cmd_pgpcarddecrypt.rs index 0e7fc05..3e8c6ca 100644 --- a/src/cmd_pgpcarddecrypt.rs +++ b/src/cmd_pgpcarddecrypt.rs @@ -19,6 +19,7 @@ impl Command for CommandImpl { .arg(Arg::with_name("pass").long("pass").takes_value(true).help("[deprecated] now OpenPGP card user pin")) .arg(Arg::with_name("cipher").short("c").long("cipher").takes_value(true).help("Cipher text HEX")) .arg(Arg::with_name("cipher-base64").short("b").long("cipher-base64").takes_value(true).help("Cipher text base64")) + .arg(Arg::with_name("algo").long("algo").takes_value(true).help("Algo: RSA, X25519/ECDH")) .arg(Arg::with_name("json").long("json").help("JSON output")) } @@ -33,6 +34,8 @@ impl Command for CommandImpl { let cipher = sub_arg_matches.value_of("cipher"); let cipher_base64 = sub_arg_matches.value_of("cipher-base64"); + let algo = sub_arg_matches.value_of("algo").unwrap_or("rsa").to_lowercase(); + let cipher_bytes = if let Some(cipher) = cipher { opt_result!(hex::decode(cipher), "Decode cipher failed: {}") } else if let Some(cipher_base64) = cipher_base64 { @@ -48,7 +51,12 @@ impl Command for CommandImpl { opt_result!(trans.verify_pw1_user(pin.as_ref()), "User pin verify failed: {}"); success!("User pin verify success!"); - let text = trans.decipher(Cryptogram::RSA(&cipher_bytes))?; + let text = match algo.as_str() { + "rsa" => trans.decipher(Cryptogram::RSA(&cipher_bytes))?, + "x25519" | "ecdh" => trans.decipher(Cryptogram::ECDH(&cipher_bytes))?, + _ => return simple_error!("Unknown algo: {}", &algo), + }; + // 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 UTF-8: {}", String::from_utf8_lossy(&text));