diff --git a/Cargo.lock b/Cargo.lock index 9a6be18..8face2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -508,7 +508,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.12.0" +version = "1.12.1" dependencies = [ "aes-gcm-stream", "authenticator 0.3.1", diff --git a/Cargo.toml b/Cargo.toml index 817ae2d..e964652 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.12.0" +version = "1.12.1" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/argsutil.rs b/src/argsutil.rs index 2e17970..57f162a 100644 --- a/src/argsutil.rs +++ b/src/argsutil.rs @@ -12,6 +12,10 @@ pub fn get_sha256_digest_or_hash(sub_arg_matches: &ArgMatches) -> XResult XResult> { + get_digest_or_hash_with_file_opt(sub_arg_matches, &None, digest) +} + pub fn get_sha256_digest_or_hash_with_file_opt(sub_arg_matches: &ArgMatches, file_opt: &Option) -> XResult> { get_digest_or_hash_with_file_opt(sub_arg_matches, file_opt, DigestAlgorithm::Sha256) } diff --git a/src/cmd_piv_ecsign.rs b/src/cmd_piv_ecsign.rs index f21f47c..9bda0b1 100644 --- a/src/cmd_piv_ecsign.rs +++ b/src/cmd_piv_ecsign.rs @@ -8,6 +8,7 @@ use yubikey::YubiKey; use crate::util::base64_encode; use crate::{argsutil, cmdutil, pivutil, util}; +use crate::digestutil::DigestAlgorithm; pub struct CommandImpl; @@ -32,12 +33,12 @@ impl Command for CommandImpl { let mut json = BTreeMap::<&'_ str, String>::new(); let slot = opt_value_result!(sub_arg_matches.value_of("slot"), "--slot must assigned, e.g. 82, 83 ... 95, 9a, 9c, 9d, 9e"); - let hash_bytes = argsutil::get_sha256_digest_or_hash(sub_arg_matches)?; - let (algorithm, algorithm_str) = match sub_arg_matches.value_of("algorithm") { - None | Some("p256") => (AlgorithmId::EccP256, "ecdsa_p256_with_sha256"), - Some("p384") => (AlgorithmId::EccP384, "ecdsa_p384_with_sha256"), + let (algorithm, algorithm_str, digest_algorithm) = match sub_arg_matches.value_of("algorithm") { + None | Some("p256") => (AlgorithmId::EccP256, "ecdsa_p256_with_sha256", DigestAlgorithm::Sha256), + Some("p384") => (AlgorithmId::EccP384, "ecdsa_p384_with_sha384", DigestAlgorithm::Sha384), Some(unknown_algorithm) => return simple_error!("Unknown algorithm {}, e.g. p256 or p384", unknown_algorithm), }; + let hash_bytes = argsutil::get_digest_or_hash(sub_arg_matches, digest_algorithm)?; let mut yk = opt_result!(YubiKey::open(), "YubiKey not found: {}"); let slot_id = pivutil::get_slot_id(slot)?;