From 6aa48355084db2cb6b507fec60b7fec5a2a1fb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sun, 11 Feb 2024 19:03:32 +1300 Subject: [PATCH] refactor(crypto): Rename sign command to crypto --- .vscode/settings.json | 3 ++ Cargo.toml | 4 +-- src/actions.rs | 12 +++---- src/actions/crypto.rs | 34 +++++++++++++++++++ src/actions/{sign => crypto}/check.rs | 0 src/actions/{sign => crypto}/inout_args.rs | 0 src/actions/{sign => crypto}/key_args.rs | 0 src/actions/{sign => crypto}/keygen.rs | 0 src/actions/{sign/files.rs => crypto/sign.rs} | 8 ++--- src/actions/sign.rs | 34 ------------------- 10 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/actions/crypto.rs rename src/actions/{sign => crypto}/check.rs (100%) rename src/actions/{sign => crypto}/inout_args.rs (100%) rename src/actions/{sign => crypto}/key_args.rs (100%) rename src/actions/{sign => crypto}/keygen.rs (100%) rename src/actions/{sign/files.rs => crypto/sign.rs} (95%) delete mode 100644 src/actions/sign.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8e619a4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.showUnlinkedFileNotification": false +} diff --git a/Cargo.toml b/Cargo.toml index 03c06be..8d65fd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,14 +55,14 @@ build-data = "0.1.5" windows_exe_info = { version = "0.4.1", features = ["manifest"] } [features] -default = ["dyndns", "sign", "tamanu", "upload"] +default = ["dyndns", "crypto", "tamanu", "upload"] ## Common dep groups (not meant to be used directly) aws = ["dep:aws-config", "dep:aws-credential-types", "dep:aws-sdk-route53", "dep:aws-sdk-s3", "dep:aws-sdk-sts"] ## Subcommands dyndns = ["aws", "dep:local-ip-address", "dep:ip_network"] -sign = ["dep:hex", "dep:leon", "dep:minisign"] +crypto = ["dep:hex", "dep:leon", "dep:minisign"] tamanu = ["dep:leon", "dep:leon-macros"] upload = ["aws"] wifisetup = ["dep:networkmanager"] diff --git a/src/actions.rs b/src/actions.rs index 4025ea7..60473ef 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -11,8 +11,8 @@ pub mod completions; pub mod context; #[cfg(feature = "dyndns")] pub mod dyndns; -#[cfg(feature = "sign")] -pub mod sign; +#[cfg(feature = "crypto")] +pub mod crypto; #[cfg(feature = "tamanu")] pub mod tamanu; #[cfg(feature = "upload")] @@ -25,8 +25,8 @@ pub enum Action { Completions(completions::CompletionsArgs), #[cfg(feature = "dyndns")] Dyndns(dyndns::DyndnsArgs), - #[cfg(feature = "sign")] - Sign(sign::SignArgs), + #[cfg(feature = "crypto")] + Crypto(crypto::CryptoArgs), #[cfg(feature = "tamanu")] Tamanu(tamanu::TamanuArgs), #[cfg(feature = "upload")] @@ -44,8 +44,8 @@ pub async fn run() -> Result<()> { (Action::Completions(args), ctx) => completions::run(ctx.with_top(args)).await, #[cfg(feature = "dyndns")] (Action::Dyndns(args), ctx) => dyndns::run(ctx.with_top(args)).await, - #[cfg(feature = "sign")] - (Action::Sign(args), ctx) => sign::run(ctx.with_top(args)).await, + #[cfg(feature = "crypto")] + (Action::Crypto(args), ctx) => crypto::run(ctx.with_top(args)).await, #[cfg(feature = "tamanu")] (Action::Tamanu(args), ctx) => tamanu::run(ctx.with_top(args)).await, #[cfg(feature = "upload")] diff --git a/src/actions/crypto.rs b/src/actions/crypto.rs new file mode 100644 index 0000000..21cdac6 --- /dev/null +++ b/src/actions/crypto.rs @@ -0,0 +1,34 @@ +use clap::{Parser, Subcommand}; +use miette::Result; + +use super::Context; + +pub mod check; +pub mod sign; +pub mod keygen; + +mod inout_args; +mod key_args; + +/// Cryptographic operations. +#[derive(Debug, Clone, Parser)] +pub struct CryptoArgs { + /// Crypto subcommand + #[command(subcommand)] + pub action: CryptoAction, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum CryptoAction { + Verify(check::CheckArgs), + Sign(sign::SignArgs), + Keygen(keygen::KeygenArgs), +} + +pub async fn run(ctx: Context) -> Result<()> { + match ctx.args_top.action.clone() { + CryptoAction::Check(subargs) => check::run(ctx.with_sub(subargs)).await, + CryptoAction::Sign(subargs) => sign::run(ctx.with_sub(subargs)).await, + CryptoAction::Keygen(subargs) => keygen::run(ctx.with_sub(subargs)).await, + } +} diff --git a/src/actions/sign/check.rs b/src/actions/crypto/check.rs similarity index 100% rename from src/actions/sign/check.rs rename to src/actions/crypto/check.rs diff --git a/src/actions/sign/inout_args.rs b/src/actions/crypto/inout_args.rs similarity index 100% rename from src/actions/sign/inout_args.rs rename to src/actions/crypto/inout_args.rs diff --git a/src/actions/sign/key_args.rs b/src/actions/crypto/key_args.rs similarity index 100% rename from src/actions/sign/key_args.rs rename to src/actions/crypto/key_args.rs diff --git a/src/actions/sign/keygen.rs b/src/actions/crypto/keygen.rs similarity index 100% rename from src/actions/sign/keygen.rs rename to src/actions/crypto/keygen.rs diff --git a/src/actions/sign/files.rs b/src/actions/crypto/sign.rs similarity index 95% rename from src/actions/sign/files.rs rename to src/actions/crypto/sign.rs index 15b7901..8071edb 100644 --- a/src/actions/sign/files.rs +++ b/src/actions/crypto/sign.rs @@ -9,9 +9,9 @@ use tracing::debug; use super::{inout_args::inout_files, key_args::SecretKeyArgs, Context, SignArgs}; -/// Sign a file or data with a secret key. +/// Sign files with a secret key. #[derive(Debug, Clone, Parser)] -pub struct FilesArgs { +pub struct SignArgs { /// A file to sign. /// /// You can provide this multiple times to sign multiple files. @@ -45,8 +45,8 @@ pub struct FilesArgs { pub comment: Option, } -pub async fn run(ctx: Context) -> Result<()> { - let FilesArgs { +pub async fn run(ctx: Context) -> Result<()> { + let SignArgs { files, key, output, diff --git a/src/actions/sign.rs b/src/actions/sign.rs deleted file mode 100644 index f91a798..0000000 --- a/src/actions/sign.rs +++ /dev/null @@ -1,34 +0,0 @@ -use clap::{Parser, Subcommand}; -use miette::Result; - -use super::Context; - -pub mod check; -pub mod files; -pub mod keygen; - -mod inout_args; -mod key_args; - -/// Sign and verify files. -#[derive(Debug, Clone, Parser)] -pub struct SignArgs { - /// Sign subcommand - #[command(subcommand)] - pub action: SignAction, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum SignAction { - Check(check::CheckArgs), - Files(files::FilesArgs), - Keygen(keygen::KeygenArgs), -} - -pub async fn run(ctx: Context) -> Result<()> { - match ctx.args_top.action.clone() { - SignAction::Check(subargs) => check::run(ctx.with_sub(subargs)).await, - SignAction::Files(subargs) => files::run(ctx.with_sub(subargs)).await, - SignAction::Keygen(subargs) => keygen::run(ctx.with_sub(subargs)).await, - } -}