Add signkey create

- Add a CLI command for creating a new signing key.
This commit is contained in:
Malte Meiboom
2026-06-19 12:27:43 +02:00
parent e47b1b837c
commit 7688e6c5a2
5 changed files with 113 additions and 4 deletions
+35
View File
@@ -0,0 +1,35 @@
//! signkey create command
use std::path::PathBuf;
use anyhow::Result;
use sequoia_openpgp::cert::CertBuilder;
use sequoia_directories::Home;
use crate::cli::cli_args::SignkeyCreateCommand;
use crate::common::crypto;
use crate::config::{HuskConfig, HuskConfigContainer};
use crate::types::husk_context::HuskContext;
pub async fn dispatch(cmd: SignkeyCreateCommand, config: HuskConfigContainer)
-> Result<()> {
let config: HuskConfig = config.into();
let context = HuskContext::new(&config)?;
let sequoia_home = Home::new(PathBuf::from(&config.sequoia_home))?;
// XXX: cleanup the userid before using
let (cert, _) = CertBuilder::new()
.add_signing_subkey()
.add_userid(cmd.userid)
.generate()?;
if crypto::import_key(sequoia_home, &cert) {
let vc = cert.with_policy(&context.policy, None)?;
crypto::set_signing_key(&context, &vc)?;
println!("New signing key: {}", vc.fingerprint());
}
Ok(())
}