| 1 |
//! Command-line parser for `sq key`. |
| 2 |
|
| 3 |
use clap::{ValueEnum, Parser, Subcommand}; |
| 4 |
|
| 5 |
use sequoia_openpgp as openpgp; |
| 6 |
use openpgp::cert::CipherSuite as SqCipherSuite; |
| 7 |
use openpgp::types::ReasonForRevocation; |
| 8 |
|
| 9 |
pub mod approvals; |
| 10 |
pub mod delete; |
| 11 |
pub mod expire; |
| 12 |
pub mod export; |
| 13 |
pub mod generate; |
| 14 |
pub mod import; |
| 15 |
pub mod list; |
| 16 |
pub mod password; |
| 17 |
pub mod revoke; |
| 18 |
pub mod rotate; |
| 19 |
pub mod subkey; |
| 20 |
pub mod userid; |
| 21 |
|
| 22 |
/// The revocation reason for a certificate or subkey |
| 23 |
#[derive(ValueEnum, Clone, Debug)] |
| 24 |
pub enum KeyReasonForRevocation { |
| 25 |
/// The secret key material may have been compromised. Prefer |
| 26 |
/// this value if you suspect that the secret key has been leaked. |
| 27 |
Compromised, |
| 28 |
/// The owner of the certificate has a new certificate. Prefer |
| 29 |
/// `compromised` if the secret key material has been compromised |
| 30 |
/// even if the certificate is also being replaced! You should |
| 31 |
/// include the fingerprint of the new certificate in the message. |
| 32 |
Superseded, |
| 33 |
/// The certificate should not be used anymore, and there is no |
| 34 |
/// replacement. This is appropriate when someone leaves an |
| 35 |
/// organisation. Prefer `compromised` if the secret key material |
| 36 |
/// has been compromised even if the certificate is also being |
| 37 |
/// retired! You should include how to contact the owner, or who |
| 38 |
/// to contact instead in the message. |
| 39 |
Retired, |
| 40 |
/// None of the other reasons apply. OpenPGP implementations |
| 41 |
/// conservatively treat this type of revocation similar to a |
| 42 |
/// compromised key. |
| 43 |
Unspecified, |
| 44 |
} |
| 45 |
|
| 46 |
impl From<KeyReasonForRevocation> for ReasonForRevocation { |
| 47 |
fn from(rr: KeyReasonForRevocation) -> Self { |
| 48 |
match rr { |
| 49 |
KeyReasonForRevocation::Compromised => ReasonForRevocation::KeyCompromised, |
| 50 |
KeyReasonForRevocation::Superseded => ReasonForRevocation::KeySuperseded, |
| 51 |
KeyReasonForRevocation::Retired => ReasonForRevocation::KeyRetired, |
| 52 |
KeyReasonForRevocation::Unspecified => ReasonForRevocation::Unspecified, |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
#[derive(Parser, Debug)] |
| 58 |
#[clap( |
| 59 |
name = "key", |
| 60 |
about = "Manage keys", |
| 61 |
long_about = |
| 62 |
"Manage keys |
| 63 |
|
| 64 |
We use the term \"key\" to refer to OpenPGP keys that do contain \ |
| 65 |
secrets. This subcommand provides primitives to generate and \ |
| 66 |
otherwise manipulate keys. |
| 67 |
|
| 68 |
Conversely, we use the term \"certificate\", or \"cert\" for short, to refer \ |
| 69 |
to OpenPGP keys that do not contain secrets. See `sq cert` for operations on \ |
| 70 |
certificates. |
| 71 |
", |
| 72 |
subcommand_required = true, |
| 73 |
arg_required_else_help = true, |
| 74 |
disable_help_subcommand = true, |
| 75 |
)] |
| 76 |
pub struct Command { |
| 77 |
#[clap(subcommand)] |
| 78 |
pub subcommand: Subcommands, |
| 79 |
} |
| 80 |
|
| 81 |
#[derive(Debug, Subcommand)] |
| 82 |
pub enum Subcommands { |
| 83 |
List(list::Command), |
| 84 |
Generate(generate::Command), |
| 85 |
Rotate(rotate::Command), |
| 86 |
Import(import::Command), |
| 87 |
Export(export::Command), |
| 88 |
Delete(delete::Command), |
| 89 |
Password(password::Command), |
| 90 |
Expire(expire::Command), |
| 91 |
Revoke(revoke::Command), |
| 92 |
#[clap(subcommand)] |
| 93 |
Userid(userid::Command), |
| 94 |
#[clap(subcommand)] |
| 95 |
Subkey(subkey::Command), |
| 96 |
#[clap(subcommand)] |
| 97 |
Approvals(approvals::Command), |
| 98 |
} |
| 99 |
|
| 100 |
#[derive(ValueEnum, Clone, Debug, Default)] |
| 101 |
pub enum CipherSuite { |
| 102 |
Rsa2k, |
| 103 |
Rsa3k, |
| 104 |
Rsa4k, |
| 105 |
#[default] |
| 106 |
Cv25519 |
| 107 |
} |
| 108 |
|
| 109 |
impl CipherSuite { |
| 110 |
|
| 111 |
/// Return a matching `sequoia_openpgp::cert::CipherSuite` |
| 112 |
pub fn as_ciphersuite(&self) -> SqCipherSuite { |
| 113 |
match self { |
| 114 |
CipherSuite::Rsa2k => SqCipherSuite::RSA2k, |
| 115 |
CipherSuite::Rsa3k => SqCipherSuite::RSA3k, |
| 116 |
CipherSuite::Rsa4k => SqCipherSuite::RSA4k, |
| 117 |
CipherSuite::Cv25519 => SqCipherSuite::Cv25519, |
| 118 |
} |
| 119 |
} |
| 120 |
} |