//! introducer remove subcommand use anyhow::Result; use sequoia_openpgp::{Fingerprint, KeyHandle}; use sequoia_openpgp::cert::ValidCert; use sequoia_cert_store::Store; use crate::cli::cli_args::IntroducerRemoveCommand; use crate::commands::CommandError; use crate::config::HuskConfigContainer; use crate::types::husk_context::HuskContext; use crate::types::introducer::Introducer; pub async fn dispatch(cmd: IntroducerRemoveCommand, config: HuskConfigContainer) -> Result<()> { let context = HuskContext::new(&config.into())?; let policy = &context.policy; let cert_store = &context.cert_store; // Get the certificate let fpr = Fingerprint::from_hex(&cmd.cert)?; let certs = cert_store.lookup_by_cert(&KeyHandle::try_from(&fpr)?) .map_err(|_| CommandError::CertNotFound(fpr.clone()))?; // Filter out valid certificates. If the certificate is not // valid according to the policy, it is already no introducer. let certs: Vec = certs.iter() .filter_map(|c| c.with_policy(policy, None).ok() ) .collect(); if let Some(cert) = certs.first() { Introducer::remove(&context, cert, cmd.demote)?; } else { return Err(CommandError::CertNotUsable(fpr).into()); } Ok(()) }