From 7acb50e4174cd7ae0e0c48c881a47508fbd1bd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gonz=C3=A1lez?= Date: Mon, 18 Mar 2024 11:32:47 +0000 Subject: [PATCH] Cargo.toml: structopt: Migrate to clap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to https://github.com/TeXitoi/structopt/issues/525, structopt has entered maintenance mode, and clap should be used for new development. * Migrate to clap so that nightly builds succeed as well. Signed-off-by: Tomás González --- Cargo.lock | 126 ++++++++++++++++--------- Cargo.toml | 2 +- src/cli/mod.rs | 6 +- src/main.rs | 2 +- src/subcommands/create_csr.rs | 4 +- src/subcommands/create_ecc_key.rs | 4 +- src/subcommands/create_rsa_key.rs | 10 +- src/subcommands/decrypt.rs | 4 +- src/subcommands/delete_client.rs | 4 +- src/subcommands/delete_key.rs | 4 +- src/subcommands/encrypt.rs | 4 +- src/subcommands/export_public_key.rs | 4 +- src/subcommands/generate_random.rs | 4 +- src/subcommands/list_authenticators.rs | 2 +- src/subcommands/list_clients.rs | 2 +- src/subcommands/list_keys.rs | 2 +- src/subcommands/list_opcodes.rs | 5 +- src/subcommands/list_providers.rs | 2 +- src/subcommands/mod.rs | 2 +- src/subcommands/ping.rs | 2 +- src/subcommands/sign.rs | 4 +- 21 files changed, 116 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 041be59..f125a34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -172,13 +183,41 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ + "atty", "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", "textwrap", - "unicode-width", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -437,13 +476,25 @@ dependencies = [ "walkdir", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "heck" -version = "0.3.3" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ - "unicode-segmentation", + "libc", ] [[package]] @@ -468,6 +519,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -483,7 +544,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.3", "rustix", "windows-sys", ] @@ -755,6 +816,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "parking_lot" version = "0.11.2" @@ -821,6 +888,7 @@ name = "parsec-tool" version = "0.7.0" dependencies = [ "base64 0.13.1", + "clap", "env_logger", "log", "oid", @@ -832,7 +900,6 @@ dependencies = [ "rcgen", "serde", "sha2", - "structopt", "thiserror", ] @@ -1263,28 +1330,10 @@ dependencies = [ ] [[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -1331,12 +1380,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.11.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" @@ -1427,18 +1473,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - [[package]] name = "unicode-xid" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 488b688..f53b529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.66.0" [dependencies] parsec-client = "0.16.0" -structopt = { version = "0.3.17", default-features = false } +clap = { version = "3.2.22", features = ["derive", "std"] } thiserror = "1.0.20" env_logger = "0.10.0" oid = { version = "0.2", features = ["serde_support"] } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 41d9f31..287fb1d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -5,19 +5,19 @@ use crate::common::{PROJECT_AUTHOR, PROJECT_DESC, PROJECT_NAME, PROJECT_VERSION}; use crate::subcommands::Subcommand; -use structopt::StructOpt; +use clap::StructOpt; /// Struct representing the command-line interface of parsec-tool. #[derive(Debug, StructOpt)] #[structopt(name=PROJECT_NAME, about=PROJECT_DESC, author=PROJECT_AUTHOR, version=PROJECT_VERSION)] pub struct ParsecToolApp { /// The ID of the provider to target for the command. Will use the default provider if not specified. - #[structopt(short = "p", long = "provider")] + #[structopt(short = 'p', long = "provider")] pub provider: Option, /// The timeout time used for all commands in seconds. Will use the client's default if not specified. If /// set to 0, will not use any timeout and will block indefinitely. - #[structopt(short = "t", long = "timeout")] + #[structopt(short = 't', long = "timeout")] pub timeout: Option, /// The subcommand -- e.g., ping. diff --git a/src/main.rs b/src/main.rs index e01e4b7..ee161df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,11 @@ //! parsec-tool: a tool for interfacing with the Parsec service from the command-line. +use clap::StructOpt; use log::error; use parsec_tool::cli; use parsec_tool::common::PROJECT_NAME; use std::convert::TryInto; -use structopt::StructOpt; fn main() { let mut env_log_builder = env_logger::Builder::new(); diff --git a/src/subcommands/create_csr.rs b/src/subcommands/create_csr.rs index c956b6d..8a209c9 100644 --- a/src/subcommands/create_csr.rs +++ b/src/subcommands/create_csr.rs @@ -5,6 +5,7 @@ use crate::error::{Error, Result, ToolErrorKind}; use crate::util::sign_message_with_policy; +use clap::StructOpt; use log::error; use parsec_client::core::interface::operations::psa_algorithm::{ Algorithm, AsymmetricSignature, Hash, SignHash, @@ -16,7 +17,6 @@ use rcgen::{ SignatureAlgorithm, PKCS_ECDSA_P256_SHA256, PKCS_ECDSA_P384_SHA384, PKCS_RSA_SHA256, PKCS_RSA_SHA384, PKCS_RSA_SHA512, }; -use structopt::StructOpt; /// Creates an X509 Certificate Signing Request (CSR) from a keypair, using the signing algorithm /// that is associated with the key. @@ -28,7 +28,7 @@ pub struct CreateCsr { /// to the user, and it must be a signing key (either an RSA key or an elliptic curve key). /// /// Elliptic curve keys must use the NIST P256 or P384 curves. - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// The common name to be used within the Distinguished Name (DN) specification of diff --git a/src/subcommands/create_ecc_key.rs b/src/subcommands/create_ecc_key.rs index aa3e3cf..ee4846d 100644 --- a/src/subcommands/create_ecc_key.rs +++ b/src/subcommands/create_ecc_key.rs @@ -4,6 +4,7 @@ //! Create an ECC key pair. //! use crate::error::Result; +use clap::StructOpt; use log::info; /// The curve will be secp256r1. Used by default for asymmetric signing with ECDSA (SHA-256). use parsec_client::core::interface::operations::psa_algorithm::{AsymmetricSignature, Hash}; @@ -11,12 +12,11 @@ use parsec_client::core::interface::operations::psa_key_attributes::{ Attributes, EccFamily, Lifetime, Policy, Type, UsageFlags, }; use parsec_client::BasicClient; -use structopt::StructOpt; /// Create an ECC key pair. #[derive(Debug, StructOpt)] pub struct CreateEccKey { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, } diff --git a/src/subcommands/create_rsa_key.rs b/src/subcommands/create_rsa_key.rs index 61b0396..4b1a65c 100644 --- a/src/subcommands/create_rsa_key.rs +++ b/src/subcommands/create_rsa_key.rs @@ -6,6 +6,7 @@ //! The key will be 2048 bits long. Used by default for asymmetric encryption with RSA PKCS#1 v1.5. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::core::interface::operations::psa_algorithm::{ AsymmetricEncryption, AsymmetricSignature, Hash, SignHash, @@ -14,26 +15,25 @@ use parsec_client::core::interface::operations::psa_key_attributes::{ Attributes, Lifetime, Policy, Type, UsageFlags, }; use parsec_client::BasicClient; -use structopt::StructOpt; /// Create a RSA key pair. #[derive(Debug, StructOpt)] pub struct CreateRsaKey { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// This command creates RSA encryption keys by default. Supply this flag to create a signing key instead. /// Signing keys, by default, will specify the SHA-256 hash algorithm and use PKCS#1 v1.5. - #[structopt(short = "s", long = "for-signing")] + #[structopt(short = 's', long = "for-signing")] is_for_signing: bool, /// Specifies the size (strength) of the key in bits. The default size for RSA keys is 2048 bits. - #[structopt(short = "b", long = "bits")] + #[structopt(short = 'b', long = "bits")] bits: Option, /// Specifies if the RSA key should be created with permitted RSA OAEP (SHA256) encryption algorithm /// instead of the default RSA PKCS#1 v1.5 one. - #[structopt(short = "o", long = "oaep")] + #[structopt(short = 'o', long = "oaep")] oaep: bool, } diff --git a/src/subcommands/decrypt.rs b/src/subcommands/decrypt.rs index c4b803b..a32bd3d 100644 --- a/src/subcommands/decrypt.rs +++ b/src/subcommands/decrypt.rs @@ -6,15 +6,15 @@ //! Will use the algorithm set to the key's policy during creation. use crate::error::{Result, ToolErrorKind}; +use clap::StructOpt; use log::{error, info}; use parsec_client::core::interface::operations::psa_algorithm::Algorithm; use parsec_client::BasicClient; -use structopt::StructOpt; /// Decrypts data. #[derive(Debug, StructOpt)] pub struct Decrypt { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// Ciphertext base64 encoded diff --git a/src/subcommands/delete_client.rs b/src/subcommands/delete_client.rs index cae3e38..e51d566 100644 --- a/src/subcommands/delete_client.rs +++ b/src/subcommands/delete_client.rs @@ -5,14 +5,14 @@ use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Delete all data a client has in the service (admin operation). #[derive(Debug, StructOpt)] pub struct DeleteClient { - #[structopt(short = "c", long = "client")] + #[structopt(short = 'c', long = "client")] client: String, } diff --git a/src/subcommands/delete_key.rs b/src/subcommands/delete_key.rs index 19790d4..1d38bd3 100644 --- a/src/subcommands/delete_key.rs +++ b/src/subcommands/delete_key.rs @@ -4,14 +4,14 @@ //! Delete a key. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Delete a key. #[derive(Debug, StructOpt)] pub struct DeleteKey { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, } diff --git a/src/subcommands/encrypt.rs b/src/subcommands/encrypt.rs index 182a42a..c39ff18 100644 --- a/src/subcommands/encrypt.rs +++ b/src/subcommands/encrypt.rs @@ -16,15 +16,15 @@ //! The output is base64-encoded ciphertext. use crate::error::{Result, ToolErrorKind}; +use clap::StructOpt; use log::{error, info}; use parsec_client::core::interface::operations::psa_algorithm::Algorithm; use parsec_client::BasicClient; -use structopt::StructOpt; /// Encrypts data. #[derive(Debug, StructOpt)] pub struct Encrypt { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// Plaintext input string. diff --git a/src/subcommands/export_public_key.rs b/src/subcommands/export_public_key.rs index 0666789..2ef4e30 100644 --- a/src/subcommands/export_public_key.rs +++ b/src/subcommands/export_public_key.rs @@ -4,6 +4,7 @@ //! Exports a public key. use crate::error::{Result, ToolErrorKind}; +use clap::StructOpt; use log::error; use oid::prelude::*; use parsec_client::core::interface::operations::psa_key_attributes::{EccFamily, Type}; @@ -12,12 +13,11 @@ use picky_asn1::bit_string::BitString; use picky_asn1_x509::{ AlgorithmIdentifier, EcParameters, PublicKey, RsaPublicKey, SubjectPublicKeyInfo, }; -use structopt::StructOpt; /// Exports a PEM-encoded public key. #[derive(Debug, StructOpt)] pub struct ExportPublicKey { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// Export RSA Public Key in PKCS#1 format. diff --git a/src/subcommands/generate_random.rs b/src/subcommands/generate_random.rs index 4b4d7fd..49047bf 100644 --- a/src/subcommands/generate_random.rs +++ b/src/subcommands/generate_random.rs @@ -4,14 +4,14 @@ //! Generates a sequence of random bytes. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Generates a sequence of random bytes. #[derive(Debug, StructOpt)] pub struct GenerateRandom { - #[structopt(short = "n", long = "nbytes")] + #[structopt(short = 'n', long = "nbytes")] nbytes: usize, } diff --git a/src/subcommands/list_authenticators.rs b/src/subcommands/list_authenticators.rs index a0747b5..b13b606 100644 --- a/src/subcommands/list_authenticators.rs +++ b/src/subcommands/list_authenticators.rs @@ -4,9 +4,9 @@ //! List the authenticators supported by the Parsec service. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// List the authenticators supported by the Parsec service. #[derive(Debug, StructOpt)] diff --git a/src/subcommands/list_clients.rs b/src/subcommands/list_clients.rs index 8c613a9..ff5c2b0 100644 --- a/src/subcommands/list_clients.rs +++ b/src/subcommands/list_clients.rs @@ -4,9 +4,9 @@ //! Lists all clients currently having data in the service (admin operation). use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Lists all clients currently having data in the service (admin operation). #[derive(Debug, StructOpt)] diff --git a/src/subcommands/list_keys.rs b/src/subcommands/list_keys.rs index 06029be..401ed18 100644 --- a/src/subcommands/list_keys.rs +++ b/src/subcommands/list_keys.rs @@ -4,9 +4,9 @@ //! Lists all keys belonging to the application. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Lists all keys belonging to the application. #[derive(Debug, StructOpt)] diff --git a/src/subcommands/list_opcodes.rs b/src/subcommands/list_opcodes.rs index 82c51da..fceba09 100644 --- a/src/subcommands/list_opcodes.rs +++ b/src/subcommands/list_opcodes.rs @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 //! Lists the supported opcodes for a given provider. - use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; use std::convert::TryInto; -use structopt::StructOpt; /// Lists the supported opcodes for a given provider. #[derive(Debug, StructOpt)] pub struct ListOpcodes { /// ID of the provider. - #[structopt(short = "p", long = "provider")] + #[structopt(short = 'p', long = "provider")] pub provider: Option, } diff --git a/src/subcommands/list_providers.rs b/src/subcommands/list_providers.rs index 4a458e2..cdb8bf7 100644 --- a/src/subcommands/list_providers.rs +++ b/src/subcommands/list_providers.rs @@ -4,9 +4,9 @@ //! Lists the available providers supported by the Parsec service. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Lists the available providers supported by the Parsec service. #[derive(Debug, StructOpt)] diff --git a/src/subcommands/mod.rs b/src/subcommands/mod.rs index 2cb414a..6eb5356 100644 --- a/src/subcommands/mod.rs +++ b/src/subcommands/mod.rs @@ -28,8 +28,8 @@ use crate::subcommands::{ list_authenticators::ListAuthenticators, list_clients::ListClients, list_keys::ListKeys, list_opcodes::ListOpcodes, list_providers::ListProviders, ping::Ping, sign::Sign, }; +use clap::StructOpt; use parsec_client::BasicClient; -use structopt::StructOpt; /// Command-line interface to Parsec operations. #[derive(Debug, StructOpt)] diff --git a/src/subcommands/ping.rs b/src/subcommands/ping.rs index 92cad20..e47dad0 100644 --- a/src/subcommands/ping.rs +++ b/src/subcommands/ping.rs @@ -4,9 +4,9 @@ //! Pings the Parsec service. use crate::error::Result; +use clap::StructOpt; use log::info; use parsec_client::BasicClient; -use structopt::StructOpt; /// Pings the Parsec service. #[derive(Debug, StructOpt)] diff --git a/src/subcommands/sign.rs b/src/subcommands/sign.rs index 9cfc5df..f5929ad 100644 --- a/src/subcommands/sign.rs +++ b/src/subcommands/sign.rs @@ -7,13 +7,13 @@ use crate::error::Result; use crate::util::sign_message_with_policy; +use clap::StructOpt; use parsec_client::BasicClient; -use structopt::StructOpt; /// Signs data. #[derive(Debug, StructOpt)] pub struct Sign { - #[structopt(short = "k", long = "key-name")] + #[structopt(short = 'k', long = "key-name")] key_name: String, /// String of UTF-8 text