mirror of
https://codeberg.org/tyy/aspm
synced 2024-12-22 20:39:29 -07:00
Add success text to import gpg
This commit is contained in:
parent
91a4a42fe6
commit
4f83bb9a3f
1 changed files with 31 additions and 21 deletions
|
@ -9,6 +9,7 @@ use data_encoding::{BASE64URL_NOPAD, BASE64_NOPAD};
|
|||
use dialoguer::{theme::ColorfulTheme, Password};
|
||||
use elliptic_curve::sec1::{Coordinates, ToEncodedPoint};
|
||||
use gpgme::{Context as GpgContext, PassphraseRequest};
|
||||
use indoc::printdoc;
|
||||
use pgp::{
|
||||
crypto::ecc_curve::ECCCurve,
|
||||
types::{EcdsaPublicParams, KeyTrait, PlainSecretParams, PublicParams, SecretParams},
|
||||
|
@ -38,9 +39,7 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
.secret_keys()
|
||||
.context("Unable to fetch GPG secret keys")?
|
||||
{
|
||||
let Ok(key) = key else {
|
||||
continue
|
||||
};
|
||||
let Ok(key) = key else { continue };
|
||||
|
||||
if key.fingerprint().unwrap_or("") != self.fingerprint
|
||||
&& key
|
||||
|
@ -54,9 +53,9 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
break;
|
||||
}
|
||||
let Some(found_key) = found_key else {
|
||||
eprintln!("No key was found matching the provided fingerprint");
|
||||
std::process::exit(1);
|
||||
};
|
||||
eprintln!("No key was found matching the provided fingerprint");
|
||||
std::process::exit(1);
|
||||
};
|
||||
|
||||
// For some reason, when exporting secret keys, GPG will prompt for a password but then still
|
||||
// export the key in an encrypted form. In order to prevent a password needing to be entered
|
||||
|
@ -104,8 +103,8 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
let parsed = parsed.next().context("Invalid GPG data")?;
|
||||
|
||||
let Ok(key) = parsed else {
|
||||
bail!("GPG data was unable to be parsed");
|
||||
};
|
||||
bail!("GPG data was unable to be parsed");
|
||||
};
|
||||
|
||||
let key = key.into_secret();
|
||||
let Some(uid) = key
|
||||
|
@ -113,16 +112,17 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
.users
|
||||
.iter()
|
||||
.find(|uid| uid.is_primary())
|
||||
.or_else(|| {
|
||||
if key.details.users.len() == 1 {
|
||||
Some(&key.details.users[0])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) else {
|
||||
eprintln!("Key being imported has no primary uid. This must be set, as it is used for the key alias.");
|
||||
std::process::exit(1);
|
||||
};
|
||||
.or_else(|| {
|
||||
if key.details.users.len() == 1 {
|
||||
Some(&key.details.users[0])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
else {
|
||||
eprintln!("Key being imported has no primary uid. This must be set, as it is used for the key alias.");
|
||||
std::process::exit(1);
|
||||
};
|
||||
let (algorithm, public_params, secret_params) = {
|
||||
if key
|
||||
.primary_key
|
||||
|
@ -193,8 +193,8 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
|
||||
let encoded = public_key.to_encoded_point(false);
|
||||
let Coordinates::Uncompressed { x, y } = encoded.coordinates() else {
|
||||
bail!("EC key coordinates were not uncompressed")
|
||||
};
|
||||
bail!("EC key coordinates were not uncompressed")
|
||||
};
|
||||
map.insert("x".to_string(), BASE64URL_NOPAD.encode(x.as_slice()).into());
|
||||
map.insert("y".to_string(), BASE64URL_NOPAD.encode(y.as_slice()).into());
|
||||
map
|
||||
|
@ -255,7 +255,7 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
|
||||
let entry = keys::ActiveModel {
|
||||
fingerprint: ActiveValue::Set(asp_key.fingerprint.clone()),
|
||||
key_type: ActiveValue::Set(asp_key.key_type.into()),
|
||||
key_type: ActiveValue::Set(asp_key.key_type.clone().into()),
|
||||
alias: ActiveValue::Set(format!("{uid}", uid = uid.id.id())),
|
||||
encrypted: ActiveValue::Set(encrypted),
|
||||
};
|
||||
|
@ -267,6 +267,16 @@ impl AspmSubcommand for KeysImportGpgCommand {
|
|||
bail!("The key was unable to be saved to the database")
|
||||
}
|
||||
|
||||
printdoc! {
|
||||
"
|
||||
Successfully imported key!
|
||||
ASP Fingerprint: {fpr}
|
||||
Type: {type:?}
|
||||
",
|
||||
fpr = asp_key.fingerprint,
|
||||
r#type = asp_key.key_type
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue