Add signkey create
- Add a CLI command for creating a new signing key.
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user