Debian Codegraph @

src/commands/key/subkey/password.rs

raw
1 //! Changes the password protecting one or more keys.
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::NULL_POLICY;
11 use crate::common::key::get_keys;
12 use crate::common::key::password;
13 use crate::sq::TrustThreshold;
14
15 pub fn dispatch(sq: Sq, command: crate::cli::key::subkey::password::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_change = get_keys(&sq, &cert_source, &kas, false)?;
34
35 password(sq, &cert, cert_source, to_change,
36 command.clear_password, command.new_password_file.as_deref(),
37 command.output, false)
38 }
39