diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-08-09 19:02:51 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-08-11 11:52:38 +0200 |
commit | c5dc911c4bce2edfc85df7fa68ccbfd7e114fd83 (patch) | |
tree | bae002bf3073996f7931875e79c2bdb01751926f /sq | |
parent | 73531db090f97f67eef714e29b26d1b88a5f5701 (diff) |
sq: Unify ArmorKind.
- ArmorKind and PacketKind represent the same values to the cli and
are basically identical.
- Unify them to ArmorKind.
Diffstat (limited to 'sq')
-rw-r--r-- | sq/src/sq_cli/armor.rs | 32 | ||||
-rw-r--r-- | sq/src/sq_cli/mod.rs | 37 | ||||
-rw-r--r-- | sq/src/sq_cli/packet.rs | 6 |
3 files changed, 24 insertions, 51 deletions
diff --git a/sq/src/sq_cli/armor.rs b/sq/src/sq_cli/armor.rs index 78d05de7..034a68e9 100644 --- a/sq/src/sq_cli/armor.rs +++ b/sq/src/sq_cli/armor.rs @@ -1,6 +1,6 @@ -use clap::{ArgEnum, Parser}; +use clap::Parser; -use super::IoArgs; +use super::{ArmorKind, IoArgs}; // TODO?: Option<_> conflicts with default value // TODO: Use PathBuf as input type for more type safety? Investigate conversion @@ -41,31 +41,3 @@ pub struct Command { )] pub kind: ArmorKind, } - -#[derive(ArgEnum)] -#[derive(Debug, Clone)] -pub enum ArmorKind { - Auto, - Message, - #[clap(name = "cert")] - PublicKey, - #[clap(name = "key")] - SecretKey, - #[clap(name = "sig")] - Signature, - File, -} - -use sequoia_openpgp::armor::Kind as OpenPGPArmorKind; -impl From<ArmorKind> for Option<OpenPGPArmorKind> { - fn from(c: ArmorKind) -> Self { - match c { - ArmorKind::Auto => None, - ArmorKind::Message => Some(OpenPGPArmorKind::Message), - ArmorKind::PublicKey => Some(OpenPGPArmorKind::PublicKey), - ArmorKind::SecretKey => Some(OpenPGPArmorKind::SecretKey), - ArmorKind::Signature => Some(OpenPGPArmorKind::Signature), - ArmorKind::File => Some(OpenPGPArmorKind::File), - } - } -} diff --git a/sq/src/sq_cli/mod.rs b/sq/src/sq_cli/mod.rs index 30c68da8..65cce7bd 100644 --- a/sq/src/sq_cli/mod.rs +++ b/sq/src/sq_cli/mod.rs @@ -3,6 +3,7 @@ use clap::{Command, ArgEnum, Args, Subcommand}; use clap::{CommandFactory, Parser}; use sequoia_openpgp as openpgp; +use openpgp::armor::Kind as OpenPGPArmorKind; use openpgp::crypto::SessionKey as OpenPGPSessionKey; use openpgp::types::SymmetricAlgorithm; use openpgp::fmt::hex; @@ -221,29 +222,29 @@ pub struct IoArgs { pub output: Option<String>, } -// TODO: reuse ArmorKind, requires changes in sq.rs -#[derive(ArgEnum, Clone, Debug)] -pub enum PacketKind { +#[derive(ArgEnum, Debug, Clone)] +pub enum ArmorKind { Auto, Message, - Cert, - Key, - Sig, - File + #[clap(name = "cert")] + PublicKey, + #[clap(name = "key")] + SecretKey, + #[clap(name = "sig")] + Signature, + File, } -impl From<PacketKind> for Option<openpgp::armor::Kind> { - - fn from(pk: PacketKind) -> Self { - use openpgp::armor::Kind as OpenpgpArmorKind; +impl From<ArmorKind> for Option<OpenPGPArmorKind> { - match pk { - PacketKind::Auto => None, - PacketKind::Message => Some(OpenpgpArmorKind::Message), - PacketKind::Cert => Some(OpenpgpArmorKind::PublicKey), - PacketKind::Key => Some(OpenpgpArmorKind::SecretKey), - PacketKind::Sig => Some(OpenpgpArmorKind::Signature), - PacketKind::File => Some(OpenpgpArmorKind::File), + fn from(c: ArmorKind) -> Self { + match c { + ArmorKind::Auto => None, + ArmorKind::Message => Some(OpenPGPArmorKind::Message), + ArmorKind::PublicKey => Some(OpenPGPArmorKind::PublicKey), + ArmorKind::SecretKey => Some(OpenPGPArmorKind::SecretKey), + ArmorKind::Signature => Some(OpenPGPArmorKind::Signature), + ArmorKind::File => Some(OpenPGPArmorKind::File), } } } diff --git a/sq/src/sq_cli/packet.rs b/sq/src/sq_cli/packet.rs index 02933322..2fb20c81 100644 --- a/sq/src/sq_cli/packet.rs +++ b/sq/src/sq_cli/packet.rs @@ -1,6 +1,6 @@ use clap::{Args, Parser, Subcommand}; -use super::{IoArgs, SessionKey, PacketKind}; +use super::{ArmorKind, IoArgs, SessionKey}; #[derive(Parser, Debug)] #[clap( @@ -199,12 +199,12 @@ pub struct JoinCommand { #[clap( long = "label", value_name = "LABEL", - default_value_t = PacketKind::Auto, + default_value_t = ArmorKind::Auto, conflicts_with = "binary", help = "Selects the kind of armor header", arg_enum, )] - pub kind: PacketKind, + pub kind: ArmorKind, #[clap( short = 'B', long, |