| 1 |
//! Deletes one or more key's secret key material. |
| 2 |
|
| 3 |
use anyhow::Context; |
| 4 |
|
| 5 |
use sequoia_openpgp as openpgp; |
| 6 |
use openpgp::Cert; |
| 7 |
|
| 8 |
use crate::Result; |
| 9 |
use crate::Sq; |
| 10 |
use crate::common::key::delete; |
| 11 |
use crate::common::NULL_POLICY; |
| 12 |
use crate::common::key::get_keys; |
| 13 |
use crate::sq::TrustThreshold; |
| 14 |
|
| 15 |
pub fn dispatch(sq: Sq, command: crate::cli::key::subkey::delete::Command) |
| 16 |
-> Result<()> |
| 17 |
{ |
| 18 |
assert!(! command.keys.is_empty()); |
| 19 |
|
| 20 |
let (cert, cert_source) |
| 21 |
= sq.resolve_cert(&command.cert, TrustThreshold::Full)?; |
| 22 |
|
| 23 |
let vc = Cert::with_policy(&cert, NULL_POLICY, sq.time) |
| 24 |
.with_context(|| { |
| 25 |
format!("The certificate {} is not valid under the \ |
| 26 |
null policy.", |
| 27 |
cert.fingerprint()) |
| 28 |
})?; |
| 29 |
|
| 30 |
let kas = sq.resolve_keys(&vc, &cert_source, &command.keys, true)?; |
| 31 |
let kas = kas.iter().collect::<Vec<_>>(); |
| 32 |
|
| 33 |
let to_delete = get_keys(&sq, &cert_source, &kas, false)?; |
| 34 |
|
| 35 |
delete::delete(sq, &cert, cert_source, to_delete, |
| 36 |
command.output, false) |
| 37 |
} |