Skip to content

Commit

Permalink
Cargo.toml: structopt: Migrate to clap
Browse files Browse the repository at this point in the history
According to TeXitoi/structopt#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 <tomasagustin.gonzalezorlando@arm.com>
  • Loading branch information
tgonzalezorlandoarm committed Mar 18, 2024
1 parent 6592b92 commit 7acb50e
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 83 deletions.
126 changes: 80 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 3 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,

/// 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<u32>,

/// The subcommand -- e.g., ping.
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/create_csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/create_ecc_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
//! 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};
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,
}

Expand Down
10 changes: 5 additions & 5 deletions src/subcommands/create_rsa_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<usize>,

/// 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,
}

Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/delete_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/delete_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 7acb50e

Please sign in to comment.