Use more qualified names to reduce ambiguity.

- Don't import `ArgumentPrefix`, etc. from the `cert_designator`
    module, import the module and call it
    `cert_designator::ArgumentPrefix`.

  - This will reduce ambiguity when using other designator types.
This commit is contained in:
Neal H. Walfield 2024-11-05 13:25:37 +01:00
parent 26c70cad32
commit ab26585972
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3
2 changed files with 61 additions and 54 deletions

View File

@ -22,7 +22,8 @@ use examples::Action;
use examples::Actions;
use examples::Example;
use examples::Setup;
use crate::cli::types::cert_designator::*;
use crate::cli::types::CertDesignators;
use crate::cli::types::cert_designator;
#[derive(Debug, Subcommand)]
#[clap(
@ -114,10 +115,11 @@ time.
#[clap(group(ArgGroup::new("required-group").args(&["can_authenticate", "can_sign", "can_encrypt"]).required(true)))]
pub struct AddCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyAddDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyAddDoc>,
#[clap(
long,
@ -200,7 +202,7 @@ modified certificate to stdout.",
/// command.
pub struct SubkeyAddDoc {}
impl AdditionalDocs for SubkeyAddDoc {
impl cert_designator::AdditionalDocs for SubkeyAddDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>
@ -322,10 +324,11 @@ revoke the keys using `sq key subkey revoke`.
)]
pub struct DeleteCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyDeleteDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyDeleteDoc>,
#[clap(
long,
@ -368,7 +371,7 @@ file. When deleting secret key material managed by the key store using \
/// command.
pub struct SubkeyDeleteDoc {}
impl AdditionalDocs for SubkeyDeleteDoc {
impl cert_designator::AdditionalDocs for SubkeyDeleteDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>
@ -438,10 +441,11 @@ provided, the user is prompted.
)]
pub struct PasswordCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyPasswordDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyPasswordDoc>,
#[clap(
long,
@ -511,7 +515,7 @@ test_examples!(sq_key_subkey_expire, SQ_KEY_SUBKEY_EXPIRE_EXAMPLES);
/// Documentation for the cert designators for the key password.
pub struct SubkeyPasswordDoc {}
impl AdditionalDocs for SubkeyPasswordDoc {
impl cert_designator::AdditionalDocs for SubkeyPasswordDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>
@ -551,10 +555,11 @@ of a subkey is bound by the expiration of the certificate.
}))]
pub struct ExpireCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyExpireDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyExpireDoc>,
#[clap(
long,
@ -591,7 +596,7 @@ modified certificate to stdout.",
/// command.
pub struct SubkeyExpireDoc {}
impl AdditionalDocs for SubkeyExpireDoc {
impl cert_designator::AdditionalDocs for SubkeyExpireDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>
@ -670,16 +675,18 @@ instead of the current time.
)]
pub struct RevokeCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyRevokeCertDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyRevokeCertDoc>,
#[command(flatten)]
pub revoker: CertDesignators<CertUserIDEmailFileArgs,
RevokerPrefix,
OneOptionalValue,
SubkeyRevokeRevokerDoc>,
pub revoker: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::RevokerPrefix,
cert_designator::OneOptionalValue,
SubkeyRevokeRevokerDoc>,
#[clap(
long = "key",
@ -763,7 +770,7 @@ modified certificate to stdout.",
/// the key subkey revoke command.
pub struct SubkeyRevokeCertDoc {}
impl AdditionalDocs for SubkeyRevokeCertDoc {
impl cert_designator::AdditionalDocs for SubkeyRevokeCertDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>
@ -783,7 +790,7 @@ impl AdditionalDocs for SubkeyRevokeCertDoc {
/// the key subkey revoke command .
pub struct SubkeyRevokeRevokerDoc {}
impl AdditionalDocs for SubkeyRevokeRevokerDoc {
impl cert_designator::AdditionalDocs for SubkeyRevokeRevokerDoc {
fn help(_: &'static str, help: &'static str) -> clap::builder::StyledStr {
format!("{} to create the revocation certificate.
@ -821,10 +828,11 @@ respectively.
#[clap(group(ArgGroup::new("cap-encrypt").args(&["can_encrypt", "cannot_encrypt"])))]
pub struct BindCommand {
#[command(flatten)]
pub cert: CertDesignators<CertUserIDEmailFileArgs,
NoPrefix,
OneValueAndFileRequiresOutput,
SubkeyBindDoc>,
pub cert: CertDesignators<
cert_designator::CertUserIDEmailFileArgs,
cert_designator::NoPrefix,
cert_designator::OneValueAndFileRequiresOutput,
SubkeyBindDoc>,
#[clap(
long,
@ -955,7 +963,7 @@ test_examples!(sq_key_bind, BIND_EXAMPLES);
/// command.
pub struct SubkeyBindDoc {}
impl AdditionalDocs for SubkeyBindDoc {
impl cert_designator::AdditionalDocs for SubkeyBindDoc {
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
match arg {
"file" =>

View File

@ -45,10 +45,9 @@ use sequoia_keystore as keystore;
use keystore::Protection;
use crate::cli::types::CertDesignators;
use crate::cli::types::cert_designator::ArgumentPrefix;
use crate::cli::types::cert_designator::CertDesignator;
use crate::cli::types::FileStdinOrKeyHandle;
use crate::cli::types::StdinWarning;
use crate::cli::types::cert_designator;
use crate::common::password;
use crate::output::hint::Hint;
use crate::output::import::{ImportStats, ImportStatus};
@ -1674,7 +1673,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
)
-> Result<(Vec<Cert>, Vec<anyhow::Error>)>
where
Prefix: ArgumentPrefix
Prefix: cert_designator::ArgumentPrefix
{
self.resolve_certs_with_policy(designators, trust_amount,
self.policy, self.time)
@ -1690,7 +1689,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
)
-> Result<(Vec<Cert>, Vec<anyhow::Error>)>
where
Prefix: ArgumentPrefix,
Prefix: cert_designator::ArgumentPrefix,
{
tracer!(TRACE, "Sq::resolve_certs");
t!("{:?}", designators);
@ -1715,7 +1714,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
= BTreeMap::new();
// The list of user ID queries.
let mut userid_queries: Vec<(&CertDesignator, _, String)>
let mut userid_queries: Vec<(&cert_designator::CertDesignator, _, String)>
= Vec::new();
// Only open the cert store if we actually need it.
@ -1733,7 +1732,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
//
// `from_cert_store` is whether the certificate was read from
// the certificate store or not.
let mut ret = |designator: &CertDesignator,
let mut ret = |designator: &cert_designator::CertDesignator,
cert: Result<Arc<LazyCert>>,
from_cert_store: bool|
{
@ -1809,7 +1808,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
*matched.borrow_mut() = false;
match designator {
CertDesignator::Cert(kh) => {
cert_designator::CertDesignator::Cert(kh) => {
t!("Looking up certificate by handle {}", kh);
match cert_store()?.lookup_by_cert(kh) {
@ -1880,7 +1879,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
}
}
CertDesignator::UserID(userid) => {
cert_designator::CertDesignator::UserID(userid) => {
t!("Looking up certificate by userid {:?}", userid);
let q = UserIDQueryParams::new();
@ -1888,7 +1887,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
(designator, q, userid.to_string()));
}
CertDesignator::Email(email) => {
cert_designator::CertDesignator::Email(email) => {
t!("Looking up certificate by email {:?}", email);
match UserIDQueryParams::is_email(&email) {
@ -1904,7 +1903,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
}
}
CertDesignator::Domain(domain) => {
cert_designator::CertDesignator::Domain(domain) => {
t!("Looking up certificate by domain {:?}", domain);
match UserIDQueryParams::is_domain(&domain) {
@ -1921,7 +1920,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
}
}
CertDesignator::Grep(pattern) => {
cert_designator::CertDesignator::Grep(pattern) => {
t!("Looking up certificate by pattern {:?}", pattern);
let mut q = UserIDQueryParams::new();
@ -1931,7 +1930,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
userid_queries.push((designator, q, pattern.clone()));
}
CertDesignator::File(filename) => {
cert_designator::CertDesignator::File(filename) => {
t!("Reading certificates from the file {}",
filename.display());
@ -1959,7 +1958,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
}
}
CertDesignator::Stdin => {
cert_designator::CertDesignator::Stdin => {
t!("Reading certificates from stdin");
let parser = CertParser::from_reader(StdinWarning::certs())
.with_context(|| {
@ -2097,7 +2096,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
)
-> Result<Vec<Cert>>
where
Prefix: ArgumentPrefix,
Prefix: cert_designator::ArgumentPrefix,
{
let (certs, errors) = self.resolve_certs(designators, trust_amount)?;
@ -2123,7 +2122,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
)
-> Result<(Cert, FileStdinOrKeyHandle)>
where
Prefix: ArgumentPrefix
Prefix: cert_designator::ArgumentPrefix
{
self.resolve_cert_with_policy(designators, trust_amount,
self.policy, self.time)
@ -2139,7 +2138,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
)
-> Result<(Cert, FileStdinOrKeyHandle)>
where
Prefix: ArgumentPrefix,
Prefix: cert_designator::ArgumentPrefix,
{
// Assuming this is only called with OneValue, then the
// following are not required.
@ -2178,9 +2177,9 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
let handle = cert.key_handle();
Ok((cert,
match &designators.designators[0] {
CertDesignator::Stdin =>
cert_designator::CertDesignator::Stdin =>
FileStdinOrKeyHandle::FileOrStdin(Default::default()),
CertDesignator::File(p) =>
cert_designator::CertDesignator::File(p) =>
FileStdinOrKeyHandle::FileOrStdin(p.as_path().into()),
_ => handle.into()
}))