aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2025-02-02 17:02:44 +0000
committersaturneric <[email protected]>2025-02-02 17:02:44 +0000
commit1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab (patch)
tree8c9cdb0cf18d5a81f68d26ff229a5618bfd5920d
parentfix: solve lower/upper case name conflict (diff)
downloadGpgFrontend-1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab.tar.gz
GpgFrontend-1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab.zip
feat: improve KeyGenerateDialog
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp44
-rw-r--r--src/core/function/gpg/GpgKeyOpera.h19
-rw-r--r--src/core/model/GpgKeyGenerateInfo.cpp (renamed from src/core/model/GpgGenKeyInfo.cpp)117
-rw-r--r--src/core/model/GpgKeyGenerateInfo.h (renamed from src/core/model/GpgGenKeyInfo.h)11
-rw-r--r--src/test/core/GpgCoreTestKeygen.cpp58
-rw-r--r--src/test/core/GpgCoreTestSubkeygen.cpp38
-rw-r--r--src/ui/dialog/Wizard.cpp2
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.cpp210
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.h23
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp127
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h6
-rw-r--r--src/ui/main_window/KeyMgmt.cpp2
-rw-r--r--ui/KeyGenDialog.ui44
13 files changed, 393 insertions, 308 deletions
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index cf4d1e3b..82001337 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -28,14 +28,12 @@
#include "GpgKeyOpera.h"
-#include <gpg-error.h>
-
#include "core/GpgModel.h"
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/DataObject.h"
-#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "core/module/ModuleManager.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/AsyncUtils.h"
@@ -163,8 +161,14 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
}});
}
-auto GenerateKeyImpl(GpgContext& ctx, const QSharedPointer<GenKeyInfo>& params,
+auto GenerateKeyImpl(GpgContext& ctx,
+ const QSharedPointer<KeyGenerateInfo>& params,
const DataObjectPtr& data_object) -> GpgError {
+ if (params == nullptr || params->GetAlgo() == KeyGenerateInfo::kNoneAlgo ||
+ params->IsSubKey()) {
+ return GPG_ERR_CANCELED;
+ }
+
const auto userid = params->GetUserid();
const auto algo = params->GetAlgo().Id();
@@ -204,7 +208,7 @@ auto GenerateKeyImpl(GpgContext& ctx, const QSharedPointer<GenKeyInfo>& params,
* @param params key generation args
* @return error information
*/
-void GpgKeyOpera::GenerateKey(const QSharedPointer<GenKeyInfo>& params,
+void GpgKeyOpera::GenerateKey(const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
@@ -213,7 +217,7 @@ void GpgKeyOpera::GenerateKey(const QSharedPointer<GenKeyInfo>& params,
callback, "gpgme_op_createkey", "2.1.0");
}
-auto GpgKeyOpera::GenerateKeySync(const QSharedPointer<GenKeyInfo>& params)
+auto GpgKeyOpera::GenerateKeySync(const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
@@ -223,12 +227,12 @@ auto GpgKeyOpera::GenerateKeySync(const QSharedPointer<GenKeyInfo>& params)
}
auto GenerateSubKeyImpl(GpgContext& ctx, const GpgKey& key,
- const QSharedPointer<GenKeyInfo>& params,
+ const QSharedPointer<KeyGenerateInfo>& params,
const DataObjectPtr& data_object) -> GpgError {
- if (!params->IsSubKey()) return GPG_ERR_CANCELED;
-
- LOG_D() << "generate subkey algo: " << params->GetAlgo().Name()
- << "key size: " << params->GetKeyLength();
+ if (params == nullptr || params->GetAlgo() == KeyGenerateInfo::kNoneAlgo ||
+ !params->IsSubKey()) {
+ return GPG_ERR_CANCELED;
+ }
auto algo = params->GetAlgo().Id();
unsigned long expires =
@@ -259,7 +263,7 @@ auto GenerateSubKeyImpl(GpgContext& ctx, const GpgKey& key,
}
void GpgKeyOpera::GenerateSubkey(const GpgKey& key,
- const QSharedPointer<GenKeyInfo>& params,
+ const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
@@ -268,8 +272,8 @@ void GpgKeyOpera::GenerateSubkey(const GpgKey& key,
callback, "gpgme_op_createsubkey", "2.1.13");
}
-auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key,
- const QSharedPointer<GenKeyInfo>& params)
+auto GpgKeyOpera::GenerateSubkeySync(
+ const GpgKey& key, const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
@@ -279,8 +283,8 @@ auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key,
}
auto GenerateKeyWithSubkeyImpl(GpgContext& ctx, GpgKeyGetter& key_getter,
- const QSharedPointer<GenKeyInfo>& p_params,
- const QSharedPointer<GenKeyInfo>& s_params,
+ const QSharedPointer<KeyGenerateInfo>& p_params,
+ const QSharedPointer<KeyGenerateInfo>& s_params,
const DataObjectPtr& data_object) -> GpgError {
auto err = GenerateKeyImpl(ctx, p_params, data_object);
@@ -306,8 +310,8 @@ auto GenerateKeyWithSubkeyImpl(GpgContext& ctx, GpgKeyGetter& key_getter,
}
void GpgKeyOpera::GenerateKeyWithSubkey(
- const QSharedPointer<GenKeyInfo>& p_params,
- const QSharedPointer<GenKeyInfo>& s_params,
+ const QSharedPointer<KeyGenerateInfo>& p_params,
+ const QSharedPointer<KeyGenerateInfo>& s_params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
@@ -318,8 +322,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey(
}
auto GpgKeyOpera::GenerateKeyWithSubkeySync(
- const QSharedPointer<GenKeyInfo>& p_params,
- const QSharedPointer<GenKeyInfo>& s_params)
+ const QSharedPointer<KeyGenerateInfo>& p_params,
+ const QSharedPointer<KeyGenerateInfo>& s_params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
diff --git a/src/core/function/gpg/GpgKeyOpera.h b/src/core/function/gpg/GpgKeyOpera.h
index d724f5f8..f6b7143e 100644
--- a/src/core/function/gpg/GpgKeyOpera.h
+++ b/src/core/function/gpg/GpgKeyOpera.h
@@ -39,7 +39,7 @@ namespace GpgFrontend {
* @brief
*
*/
-class GenKeyInfo;
+class KeyGenerateInfo;
/**
* @brief
@@ -115,7 +115,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param result
* @return GpgFrontend::GpgError
*/
- void GenerateKey(const QSharedPointer<GenKeyInfo>&,
+ void GenerateKey(const QSharedPointer<KeyGenerateInfo>&,
const GpgOperationCallback&);
/**
@@ -123,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
*
* @param params
*/
- auto GenerateKeySync(const QSharedPointer<GenKeyInfo>& params)
+ auto GenerateKeySync(const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr>;
/**
@@ -134,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @return GpgFrontend::GpgError
*/
void GenerateSubkey(const GpgKey& key,
- const QSharedPointer<GenKeyInfo>& params,
+ const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback&);
/**
@@ -144,7 +144,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param params
*/
auto GenerateSubkeySync(const GpgKey& key,
- const QSharedPointer<GenKeyInfo>& params)
+ const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr>;
/**
@@ -154,8 +154,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param subkey_params
* @param callback
*/
- void GenerateKeyWithSubkey(const QSharedPointer<GenKeyInfo>& p_params,
- const QSharedPointer<GenKeyInfo>& s_params,
+ void GenerateKeyWithSubkey(const QSharedPointer<KeyGenerateInfo>& p_params,
+ const QSharedPointer<KeyGenerateInfo>& s_params,
const GpgOperationCallback& callback);
/**
@@ -165,8 +165,9 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param subkey_params
* @param callback
*/
- auto GenerateKeyWithSubkeySync(const QSharedPointer<GenKeyInfo>& p_params,
- const QSharedPointer<GenKeyInfo>& s_params)
+ auto GenerateKeyWithSubkeySync(
+ const QSharedPointer<KeyGenerateInfo>& p_params,
+ const QSharedPointer<KeyGenerateInfo>& s_params)
-> std::tuple<GpgError, DataObjectPtr>;
private:
diff --git a/src/core/model/GpgGenKeyInfo.cpp b/src/core/model/GpgKeyGenerateInfo.cpp
index 2b8a3dbc..fda6d09a 100644
--- a/src/core/model/GpgGenKeyInfo.cpp
+++ b/src/core/model/GpgKeyGenerateInfo.cpp
@@ -26,7 +26,7 @@
*
*/
-#include "GpgGenKeyInfo.h"
+#include "GpgKeyGenerateInfo.h"
#include <cassert>
@@ -35,7 +35,12 @@
namespace GpgFrontend {
-const QContainer<KeyAlgo> GenKeyInfo::kPrimaryKeyAlgos = {
+const KeyAlgo KeyGenerateInfo::kNoneAlgo = {"none", "None", "None",
+ 0, 0, "0.0.0"};
+
+const QContainer<KeyAlgo> KeyGenerateInfo::kPrimaryKeyAlgos = {
+ kNoneAlgo,
+
/**
* Algorithm (DSA) as a government standard for digital signatures.
* Originally, it supported key lengths between 512 and 1024 bits.
@@ -63,7 +68,9 @@ const QContainer<KeyAlgo> GenKeyInfo::kPrimaryKeyAlgos = {
{"secp256k1", "ED448", "EdDSA", 256, kSIGN | kAUTH | kCERT, "2.3.0"},
};
-const QContainer<KeyAlgo> GenKeyInfo::kSubKeyAlgos = {
+const QContainer<KeyAlgo> KeyGenerateInfo::kSubKeyAlgos = {
+ kNoneAlgo,
+
{"rsa1024", "RSA", "RSA", 1024, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"rsa2048", "RSA", "RSA", 2048, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"rsa3072", "RSA", "RSA", 3072, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
@@ -91,7 +98,7 @@ const QContainer<KeyAlgo> GenKeyInfo::kSubKeyAlgos = {
{"elg4096", "ELG-E", "ELG-E", 4096, kENCRYPT, "2.2.0"},
};
-auto GenKeyInfo::GetSupportedKeyAlgo() -> QContainer<KeyAlgo> {
+auto KeyGenerateInfo::GetSupportedKeyAlgo() -> QContainer<KeyAlgo> {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
@@ -109,7 +116,7 @@ auto GenKeyInfo::GetSupportedKeyAlgo() -> QContainer<KeyAlgo> {
return algos;
}
-auto GenKeyInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> {
+auto KeyGenerateInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
@@ -127,7 +134,10 @@ auto GenKeyInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> {
return algos;
}
-auto GenKeyInfo::SearchPrimaryKeyAlgo(const QString &algo_id)
+KeyGenerateInfo::KeyGenerateInfo(bool is_subkey)
+ : subkey_(is_subkey), algo_(kNoneAlgo) {}
+
+auto KeyGenerateInfo::SearchPrimaryKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo> {
auto it =
std::find_if(kPrimaryKeyAlgos.cbegin(), kPrimaryKeyAlgos.cend(),
@@ -140,7 +150,7 @@ auto GenKeyInfo::SearchPrimaryKeyAlgo(const QString &algo_id)
return {false, KeyAlgo{}};
}
-auto GenKeyInfo::SearchSubKeyAlgo(const QString &algo_id)
+auto KeyGenerateInfo::SearchSubKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo> {
auto it =
std::find_if(kSubKeyAlgos.cbegin(), kSubKeyAlgos.cend(),
@@ -153,7 +163,7 @@ auto GenKeyInfo::SearchSubKeyAlgo(const QString &algo_id)
return {false, KeyAlgo{}};
}
-void GenKeyInfo::SetAlgo(const KeyAlgo &algo) {
+void KeyGenerateInfo::SetAlgo(const KeyAlgo &algo) {
// reset all options
reset_options();
@@ -172,7 +182,7 @@ void GenKeyInfo::SetAlgo(const KeyAlgo &algo) {
this->algo_ = algo;
}
-void GenKeyInfo::reset_options() {
+void KeyGenerateInfo::reset_options() {
allow_change_encryption_ = true;
SetAllowEncryption(true);
@@ -186,47 +196,42 @@ void GenKeyInfo::reset_options() {
SetAllowAuthentication(true);
}
-void GenKeyInfo::SetExpireTime(const QDateTime &m_expired) {
- GenKeyInfo::expired_ = m_expired;
+void KeyGenerateInfo::SetExpireTime(const QDateTime &m_expired) {
+ KeyGenerateInfo::expired_ = m_expired;
}
-void GenKeyInfo::SetNonExpired(bool m_non_expired) {
+void KeyGenerateInfo::SetNonExpired(bool m_non_expired) {
if (!m_non_expired) this->expired_ = QDateTime::fromSecsSinceEpoch(0);
- GenKeyInfo::non_expired_ = m_non_expired;
+ KeyGenerateInfo::non_expired_ = m_non_expired;
}
-void GenKeyInfo::SetAllowEncryption(bool m_allow_encryption) {
+void KeyGenerateInfo::SetAllowEncryption(bool m_allow_encryption) {
if (allow_change_encryption_) {
- GenKeyInfo::allow_encryption_ = m_allow_encryption;
+ KeyGenerateInfo::allow_encryption_ = m_allow_encryption;
}
}
-void GenKeyInfo::SetAllowCertification(bool m_allow_certification) {
+void KeyGenerateInfo::SetAllowCertification(bool m_allow_certification) {
if (allow_change_certification_) {
- GenKeyInfo::allow_certification_ = m_allow_certification;
+ KeyGenerateInfo::allow_certification_ = m_allow_certification;
}
}
-GenKeyInfo::GenKeyInfo(bool is_subkey) : subkey_(is_subkey) {
- assert(!GetSupportedKeyAlgo().empty());
- SetAlgo(GetSupportedKeyAlgo().front());
-}
-
/**
* @brief
*
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsSubKey() const -> bool { return subkey_; }
+[[nodiscard]] auto KeyGenerateInfo::IsSubKey() const -> bool { return subkey_; }
/**
* @brief Set the Is Sub Key object
*
* @param m_sub_key
*/
-void GenKeyInfo::SetIsSubKey(bool m_sub_key) {
- GenKeyInfo::subkey_ = m_sub_key;
+void KeyGenerateInfo::SetIsSubKey(bool m_sub_key) {
+ KeyGenerateInfo::subkey_ = m_sub_key;
}
/**
@@ -234,7 +239,7 @@ void GenKeyInfo::SetIsSubKey(bool m_sub_key) {
*
* @return QString
*/
-[[nodiscard]] auto GenKeyInfo::GetUserid() const -> QString {
+[[nodiscard]] auto KeyGenerateInfo::GetUserid() const -> QString {
return QString("%1(%2)<%3>").arg(name_).arg(comment_).arg(email_);
}
@@ -243,21 +248,23 @@ void GenKeyInfo::SetIsSubKey(bool m_sub_key) {
*
* @param m_name
*/
-void GenKeyInfo::SetName(const QString &m_name) { this->name_ = m_name; }
+void KeyGenerateInfo::SetName(const QString &m_name) { this->name_ = m_name; }
/**
* @brief Set the Email object
*
* @param m_email
*/
-void GenKeyInfo::SetEmail(const QString &m_email) { this->email_ = m_email; }
+void KeyGenerateInfo::SetEmail(const QString &m_email) {
+ this->email_ = m_email;
+}
/**
* @brief Set the Comment object
*
* @param m_comment
*/
-void GenKeyInfo::SetComment(const QString &m_comment) {
+void KeyGenerateInfo::SetComment(const QString &m_comment) {
this->comment_ = m_comment;
}
@@ -266,21 +273,23 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
*
* @return QString
*/
-[[nodiscard]] auto GenKeyInfo::GetName() const -> QString { return name_; }
+[[nodiscard]] auto KeyGenerateInfo::GetName() const -> QString { return name_; }
/**
* @brief Get the Email object
*
* @return QString
*/
-[[nodiscard]] auto GenKeyInfo::GetEmail() const -> QString { return email_; }
+[[nodiscard]] auto KeyGenerateInfo::GetEmail() const -> QString {
+ return email_;
+}
/**
* @brief Get the Comment object
*
* @return QString
*/
-[[nodiscard]] auto GenKeyInfo::GetComment() const -> QString {
+[[nodiscard]] auto KeyGenerateInfo::GetComment() const -> QString {
return comment_;
}
@@ -289,7 +298,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
*
* @return const QString&
*/
-[[nodiscard]] auto GenKeyInfo::GetAlgo() const -> const KeyAlgo & {
+[[nodiscard]] auto KeyGenerateInfo::GetAlgo() const -> const KeyAlgo & {
return algo_;
}
@@ -298,7 +307,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
*
* @return int
*/
-[[nodiscard]] auto GenKeyInfo::GetKeyLength() const -> int {
+[[nodiscard]] auto KeyGenerateInfo::GetKeyLength() const -> int {
return algo_.KeyLength();
}
@@ -307,7 +316,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
*
* @return const QDateTime&
*/
-[[nodiscard]] auto GenKeyInfo::GetExpireTime() const -> const QDateTime & {
+[[nodiscard]] auto KeyGenerateInfo::GetExpireTime() const -> const QDateTime & {
return expired_;
}
@@ -317,7 +326,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsNonExpired() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsNonExpired() const -> bool {
return non_expired_;
}
@@ -327,7 +336,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsNoPassPhrase() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsNoPassPhrase() const -> bool {
return this->no_passphrase_;
}
@@ -336,8 +345,8 @@ void GenKeyInfo::SetComment(const QString &m_comment) {
*
* @param m_non_pass_phrase
*/
-void GenKeyInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
- GenKeyInfo::no_passphrase_ = m_non_pass_phrase;
+void KeyGenerateInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
+ KeyGenerateInfo::no_passphrase_ = m_non_pass_phrase;
}
/**
@@ -346,7 +355,7 @@ void GenKeyInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowSigning() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowSigning() const -> bool {
return allow_signing_;
}
@@ -356,7 +365,7 @@ void GenKeyInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowNoPassPhrase() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowNoPassPhrase() const -> bool {
return allow_no_pass_phrase_;
}
@@ -365,8 +374,8 @@ void GenKeyInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
*
* @param m_allow_signing
*/
-void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
- if (allow_change_signing_) GenKeyInfo::allow_signing_ = m_allow_signing;
+void KeyGenerateInfo::SetAllowSigning(bool m_allow_signing) {
+ if (allow_change_signing_) KeyGenerateInfo::allow_signing_ = m_allow_signing;
}
/**
@@ -375,7 +384,7 @@ void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowEncryption() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowEncryption() const -> bool {
return allow_encryption_;
}
@@ -385,7 +394,7 @@ void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowCertification() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowCertification() const -> bool {
return allow_certification_;
}
@@ -395,7 +404,7 @@ void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowAuthentication() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowAuthentication() const -> bool {
return allow_authentication_;
}
@@ -404,9 +413,9 @@ void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
*
* @param m_allow_authentication
*/
-void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
+void KeyGenerateInfo::SetAllowAuthentication(bool m_allow_authentication) {
if (allow_change_authentication_) {
- GenKeyInfo::allow_authentication_ = m_allow_authentication;
+ KeyGenerateInfo::allow_authentication_ = m_allow_authentication;
}
}
@@ -416,7 +425,7 @@ void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowChangeSigning() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowChangeSigning() const -> bool {
return allow_change_signing_;
}
@@ -426,7 +435,7 @@ void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowChangeEncryption() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowChangeEncryption() const -> bool {
return allow_change_encryption_;
}
@@ -436,7 +445,7 @@ void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowChangeCertification() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowChangeCertification() const -> bool {
return allow_change_certification_;
}
@@ -446,7 +455,8 @@ void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
* @return true
* @return false
*/
-[[nodiscard]] auto GenKeyInfo::IsAllowChangeAuthentication() const -> bool {
+[[nodiscard]] auto KeyGenerateInfo::IsAllowChangeAuthentication() const
+ -> bool {
return allow_change_authentication_;
}
@@ -483,4 +493,7 @@ auto KeyAlgo::IsSupported(const QString &version) const -> bool {
return GFCompareSoftwareVersion(version, supported_version_) >= 0;
}
+auto KeyAlgo::operator==(const KeyAlgo &o) const -> bool {
+ return this->id_ == o.id_;
+}
} // namespace GpgFrontend
diff --git a/src/core/model/GpgGenKeyInfo.h b/src/core/model/GpgKeyGenerateInfo.h
index a6dd03b0..0f3f2d70 100644
--- a/src/core/model/GpgGenKeyInfo.h
+++ b/src/core/model/GpgKeyGenerateInfo.h
@@ -28,10 +28,7 @@
#pragma once
-#include <utility>
-
#include "core/GpgFrontendCoreExport.h"
-#include "core/function/gpg/GpgKeyOpera.h"
#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend {
@@ -47,6 +44,8 @@ class GPGFRONTEND_CORE_EXPORT KeyAlgo {
auto operator=(const KeyAlgo &) -> KeyAlgo & = default;
+ auto operator==(const KeyAlgo &o) const -> bool;
+
[[nodiscard]] auto Id() const -> QString;
[[nodiscard]] auto Name() const -> QString;
@@ -77,10 +76,10 @@ class GPGFRONTEND_CORE_EXPORT KeyAlgo {
QString supported_version_;
};
-class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
+class GPGFRONTEND_CORE_EXPORT KeyGenerateInfo {
public:
+ static const KeyAlgo kNoneAlgo;
static const QContainer<KeyAlgo> kPrimaryKeyAlgos;
-
static const QContainer<KeyAlgo> kSubKeyAlgos;
/**
@@ -89,7 +88,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @param m_is_sub_key
* @param m_standalone
*/
- explicit GenKeyInfo(bool is_subkey = false);
+ explicit KeyGenerateInfo(bool is_subkey = false);
/**
* @brief Get the Supported Key Algo object
diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp
index aa4de244..63b6ad17 100644
--- a/src/test/core/GpgCoreTestKeygen.cpp
+++ b/src/test/core/GpgCoreTestKeygen.cpp
@@ -29,16 +29,16 @@
#include "GpgCoreTest.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
#include "core/model/GpgKey.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend::Test {
TEST_F(GpgCoreTest, SearchPrimaryKeyAlgoTest) {
- auto [find, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048");
+ auto [find, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
ASSERT_TRUE(find);
ASSERT_EQ(algo.Id(), "rsa2048");
ASSERT_EQ(algo.Id(), "rsa2048");
@@ -48,7 +48,7 @@ TEST_F(GpgCoreTest, SearchPrimaryKeyAlgoTest) {
}
TEST_F(GpgCoreTest, SearchSubKeyAlgoTest) {
- auto [find, algo] = GenKeyInfo::SearchSubKeyAlgo("rsa2048");
+ auto [find, algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
ASSERT_TRUE(find);
ASSERT_EQ(algo.Id(), "rsa2048");
ASSERT_EQ(algo.Name(), "RSA");
@@ -57,12 +57,12 @@ TEST_F(GpgCoreTest, SearchSubKeyAlgoTest) {
}
TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_0");
p_info->SetEmail("[email protected]");
p_info->SetComment("foobar");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa2048");
p_info->SetAlgo(algo);
@@ -107,12 +107,12 @@ TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
}
TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_1");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa4096");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa4096");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa4096");
p_info->SetAlgo(algo);
@@ -146,12 +146,12 @@ TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
}
TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_1");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("dsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "dsa2048");
p_info->SetAlgo(algo);
@@ -200,12 +200,12 @@ TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
}
TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
@@ -254,12 +254,12 @@ TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
}
TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec");
p_info->SetEmail("[email protected]");
p_info->SetComment("ecccc");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
@@ -267,9 +267,9 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- std::tie(found, algo) = GenKeyInfo::SearchSubKeyAlgo("cv25519");
+ std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "cv25519");
s_info->SetAlgo(algo);
@@ -329,12 +329,12 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
}
TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec2");
p_info->SetEmail("[email protected]");
p_info->SetComment("ecccc");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
@@ -342,9 +342,9 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- std::tie(found, algo) = GenKeyInfo::SearchSubKeyAlgo("nistp256");
+ std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
s_info->SetAlgo(algo);
@@ -404,12 +404,12 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
}
TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec3");
p_info->SetEmail("[email protected]");
p_info->SetComment("ecccc3");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
@@ -417,9 +417,9 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- std::tie(found, algo) = GenKeyInfo::SearchSubKeyAlgo("brainpoolp256r1");
+ std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("brainpoolp256r1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "brainpoolp256r1");
s_info->SetAlgo(algo);
@@ -479,12 +479,12 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
}
TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("nistp256");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
p_info->SetAlgo(algo);
@@ -534,12 +534,12 @@ TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
}
TEST_F(GpgCoreTest, GenerateKeyED448Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed448");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed448");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed448");
p_info->SetAlgo(algo);
@@ -589,12 +589,12 @@ TEST_F(GpgCoreTest, GenerateKeyED448Test) {
}
TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
- auto p_info = QSharedPointer<GenKeyInfo>::create();
+ auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("[email protected]");
p_info->SetComment("hello gpgfrontend");
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("secp256k1");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("secp256k1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "secp256k1");
p_info->SetAlgo(algo);
diff --git a/src/test/core/GpgCoreTestSubkeygen.cpp b/src/test/core/GpgCoreTestSubkeygen.cpp
index 886a6f04..af78a953 100644
--- a/src/test/core/GpgCoreTestSubkeygen.cpp
+++ b/src/test/core/GpgCoreTestSubkeygen.cpp
@@ -29,9 +29,9 @@
#include "GpgCoreTest.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
#include "core/model/GpgKey.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/MemoryUtils.h"
@@ -42,9 +42,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("rsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa2048");
s_info->SetAlgo(algo);
@@ -85,9 +85,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("dsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("dsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "dsa2048");
s_info->SetAlgo(algo);
@@ -128,9 +128,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("elg2048");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "elg2048");
s_info->SetAlgo(algo);
@@ -171,9 +171,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
s_info->SetAlgo(algo);
@@ -214,9 +214,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("cv25519");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "cv25519");
s_info->SetAlgo(algo);
@@ -257,9 +257,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("nistp256");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
s_info->SetAlgo(algo);
@@ -299,9 +299,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("brainpoolp256r1");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("brainpoolp256r1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "brainpoolp256r1");
s_info->SetAlgo(algo);
@@ -341,9 +341,9 @@ TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("x448");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("x448");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "x448");
s_info->SetAlgo(algo);
@@ -383,9 +383,9 @@ TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(p_key.IsGood());
- auto s_info = QSharedPointer<GenKeyInfo>::create(true);
+ auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
- auto [found, algo] = GenKeyInfo::SearchSubKeyAlgo("secp256k1");
+ auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("secp256k1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "secp256k1");
s_info->SetAlgo(algo);
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp
index 243fb846..8e77dada 100644
--- a/src/ui/dialog/Wizard.cpp
+++ b/src/ui/dialog/Wizard.cpp
@@ -195,7 +195,7 @@ KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) {
int KeyGenPage::nextId() const { return Wizard::kPAGE_CONCLUSION; }
void KeyGenPage::slot_generate_key_dialog() {
- (new KeyGenDialog(kGpgFrontendDefaultChannel, this))->show();
+ (new KeyGenerateDialog(kGpgFrontendDefaultChannel, this))->show();
wizard()->next();
}
diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
index 49425e5b..27c587a1 100644
--- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
@@ -95,13 +95,13 @@ void SetKeyLengthComboxBoxByAlgo(QComboBox* combo,
combo->addItems(key_lengths);
}
-KeyGenDialog::KeyGenDialog(int channel, QWidget* parent)
- : GeneralDialog(typeid(KeyGenDialog).name(), parent),
+KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent)
+ : GeneralDialog(typeid(KeyGenerateDialog).name(), parent),
ui_(QSharedPointer<Ui_KeyGenDialog>::create()),
- gen_key_info_(QSharedPointer<GenKeyInfo>::create()),
+ gen_key_info_(QSharedPointer<KeyGenerateInfo>::create()),
gen_subkey_info_(nullptr),
- supported_primary_key_algos_(GenKeyInfo::GetSupportedKeyAlgo()),
- supported_subkey_algos_(GenKeyInfo::GetSupportedSubkeyAlgo()),
+ supported_primary_key_algos_(KeyGenerateInfo::GetSupportedKeyAlgo()),
+ supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()),
channel_(channel) {
ui_->setupUi(this);
@@ -128,6 +128,42 @@ KeyGenDialog::KeyGenDialog(int channel, QWidget* parent)
tr("Non Expired"),
});
+ ui_->easyCombinationComboBox->addItems({
+ tr("Primary Key Only"),
+ tr("Primary Key With Subkey"),
+ });
+
+ ui_->nameLabel->setText(tr("Name"));
+ ui_->emailLabel->setText(tr("Email"));
+ ui_->commentLabel->setText(tr("Comment"));
+ ui_->keyDBLabel->setText(tr("Key Database"));
+ ui_->easyAlgoLabel->setText(tr("Algorithm"));
+ ui_->easyValidPeriodLabel->setText(tr("Validity Period"));
+
+ ui_->pAlgoLabel->setText(tr("Algorithm"));
+ ui_->pValidPeriodLabel->setText(tr("Validity Period"));
+ ui_->pKeyLengthLabel->setText(tr("Key Length"));
+ ui_->pUsageLabel->setText(tr("Usage"));
+ ui_->pEncrCheckBox->setText(tr("Encrypt"));
+ ui_->pSignCheckBox->setText(tr("Sign"));
+ ui_->pAuthCheckBox->setText(tr("Authentication"));
+ ui_->noPassphraseCheckBox->setText(tr("No Passphrase"));
+ ui_->pExpireCheckBox->setText(tr("Non Expired"));
+
+ ui_->sAlgoLabel->setText(tr("Algorithm"));
+ ui_->sValidPeriodLabel->setText(tr("Validity Period"));
+ ui_->sKeyLengthLabel->setText(tr("Key Length"));
+ ui_->sUsageLabel->setText(tr("Usage"));
+ ui_->sEncrCheckBox->setText(tr("Encrypt"));
+ ui_->sSignCheckBox->setText(tr("Sign"));
+ ui_->sAuthCheckBox->setText(tr("Authentication"));
+ ui_->sExpireCheckBox->setText(tr("Non Expired"));
+
+ ui_->tabWidget->setTabText(0, tr("Easy Mode"));
+ ui_->tabWidget->setTabText(0, tr("Primary Key"));
+ ui_->tabWidget->setTabText(0, tr("Subkey"));
+ ui_->generateButton->setText(tr("Generate"));
+
QSet<QString> p_algo_set;
for (const auto& algo : supported_primary_key_algos_) {
p_algo_set.insert(algo.Name());
@@ -156,21 +192,32 @@ KeyGenDialog::KeyGenDialog(int channel, QWidget* parent)
this->setModal(true);
}
-void KeyGenDialog::slot_key_gen_accept() {
+void KeyGenerateDialog::slot_key_gen_accept() {
QString buffer;
- QTextStream error_stream(&buffer);
+ QTextStream err_stream(&buffer);
if (ui_->nameEdit->text().size() < 5) {
- error_stream << " -> " << tr("Name must contain at least five characters.")
- << Qt::endl;
+ err_stream << " -> " << tr("Name must contain at least five characters.")
+ << Qt::endl;
}
if (ui_->emailEdit->text().isEmpty() ||
!check_email_address(ui_->emailEdit->text())) {
- error_stream << " -> " << tr("Please give a valid email address.")
- << Qt::endl;
+ err_stream << " -> " << tr("Please give a valid email address.")
+ << Qt::endl;
+ }
+
+ if (gen_key_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) {
+ err_stream << " -> " << tr("Please give a valid primary key algorithm.")
+ << Qt::endl;
}
- const auto err_string = error_stream.readAll();
+ if (gen_subkey_info_ != nullptr &&
+ gen_subkey_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) {
+ err_stream << " -> " << tr("Please give a valid subkey algorithm.")
+ << Qt::endl;
+ }
+
+ const auto err_string = err_stream.readAll();
if (!err_string.isEmpty()) {
ui_->statusPlainTextEdit->clear();
ui_->statusPlainTextEdit->appendPlainText(err_string);
@@ -199,44 +246,13 @@ void KeyGenDialog::slot_key_gen_accept() {
}
}
- if (!GetSettings()
- .value("gnupg/use_pinentry_as_password_input_dialog",
- QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
- .toBool() &&
- !ui_->noPassphraseCheckBox->isChecked()) {
- SetCacheValue("PinentryContext", "NEW_PASSPHRASE");
- }
-
LOG_D() << "try to generate key at gpg context channel: " << channel_;
- GpgOperaHelper::WaitForOpera(
- this, tr("Generating"),
- [this, gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) {
- GpgKeyOpera::GetInstance(channel_).GenerateKeyWithSubkey(
- gen_key_info, gen_subkey_info_,
- [this, hd](GpgError err, const DataObjectPtr&) {
- // stop showing waiting dialog
- hd();
-
- if (CheckGpgError(err) == GPG_ERR_USER_1) {
- QMessageBox::critical(this, tr("Error"),
- tr("Unknown error occurred"));
- return;
- }
-
- CommonUtils::RaiseMessageBox(
- this->parentWidget() != nullptr ? this->parentWidget() : this,
- err);
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- emit SignalKeyGenerated();
- }
- });
- });
-
+ do_generate();
this->done(0);
}
-void KeyGenDialog::refresh_widgets_state() {
+void KeyGenerateDialog::refresh_widgets_state() {
ui_->pAlgoComboBox->blockSignals(true);
ui_->pAlgoComboBox->setCurrentText(gen_key_info_->GetAlgo().Name());
ui_->pAlgoComboBox->blockSignals(false);
@@ -280,7 +296,7 @@ void KeyGenDialog::refresh_widgets_state() {
ui_->pExpireCheckBox->blockSignals(false);
if (gen_subkey_info_ == nullptr) {
- ui_->tab_3->setDisabled(true);
+ ui_->sTab->setDisabled(true);
ui_->sAlgoComboBox->blockSignals(true);
ui_->sAlgoComboBox->setCurrentText(tr("None"));
@@ -310,10 +326,14 @@ void KeyGenDialog::refresh_widgets_state() {
ui_->sExpireCheckBox->blockSignals(true);
ui_->sExpireCheckBox->setCheckState(Qt::Unchecked);
ui_->sExpireCheckBox->blockSignals(false);
+
+ ui_->easyCombinationComboBox->blockSignals(true);
+ ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key Only"));
+ ui_->easyCombinationComboBox->blockSignals(false);
return;
}
- ui_->tab_3->setDisabled(false);
+ ui_->sTab->setDisabled(false);
ui_->sAlgoComboBox->blockSignals(true);
ui_->sAlgoComboBox->setCurrentText(gen_subkey_info_->GetAlgo().Name());
@@ -357,11 +377,15 @@ void KeyGenDialog::refresh_widgets_state() {
ui_->sExpireCheckBox->blockSignals(true);
ui_->sExpireCheckBox->setChecked(gen_subkey_info_->IsNonExpired());
ui_->sExpireCheckBox->blockSignals(false);
+
+ ui_->easyCombinationComboBox->blockSignals(true);
+ ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key With Subkey"));
+ ui_->easyCombinationComboBox->blockSignals(false);
}
-void KeyGenDialog::set_signal_slot_config() {
+void KeyGenerateDialog::set_signal_slot_config() {
connect(ui_->generateButton, &QPushButton::clicked, this,
- &KeyGenDialog::slot_key_gen_accept);
+ &KeyGenerateDialog::slot_key_gen_accept);
connect(ui_->pExpireCheckBox, &QCheckBox::stateChanged, this,
[this](int state) {
@@ -425,10 +449,10 @@ void KeyGenDialog::set_signal_slot_config() {
});
connect(ui_->easyAlgoComboBox, &QComboBox::currentTextChanged, this,
- &KeyGenDialog::slot_easy_mode_changed);
+ &KeyGenerateDialog::slot_easy_mode_changed);
connect(ui_->easyValidityPeriodComboBox, &QComboBox::currentTextChanged, this,
- &KeyGenDialog::slot_easy_valid_date_changed);
+ &KeyGenerateDialog::slot_easy_valid_date_changed);
connect(ui_->pValidityPeriodDateTimeEdit, &QDateTimeEdit::dateTimeChanged,
this, [=](const QDateTime& dt) {
@@ -447,16 +471,19 @@ void KeyGenDialog::set_signal_slot_config() {
connect(ui_->keyDBIndexComboBox, &QComboBox::currentIndexChanged, this,
[=](int index) { channel_ = index; });
- connect(this, &KeyGenDialog::SignalKeyGenerated,
+ connect(ui_->easyCombinationComboBox, &QComboBox::currentTextChanged, this,
+ &KeyGenerateDialog::slot_easy_combination_changed);
+
+ connect(this, &KeyGenerateDialog::SignalKeyGenerated,
UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefresh);
}
-auto KeyGenDialog::check_email_address(const QString& str) -> bool {
+auto KeyGenerateDialog::check_email_address(const QString& str) -> bool {
return re_email_.match(str).hasMatch();
}
-void KeyGenDialog::sync_gen_key_info() {
+void KeyGenerateDialog::sync_gen_key_info() {
auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(),
supported_primary_key_algos_);
@@ -468,7 +495,7 @@ void KeyGenDialog::sync_gen_key_info() {
}
}
-void KeyGenDialog::sync_gen_subkey_info() {
+void KeyGenerateDialog::sync_gen_subkey_info() {
if (gen_subkey_info_ != nullptr) {
auto [s_found, algo] = GetAlgoByName(ui_->sAlgoComboBox->currentText(),
supported_subkey_algos_);
@@ -478,54 +505,54 @@ void KeyGenDialog::sync_gen_subkey_info() {
}
}
-void KeyGenDialog::slot_easy_mode_changed(const QString& mode) {
+void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) {
if (mode == "RSA") {
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
if (found) gen_key_info_->SetAlgo(algo);
gen_subkey_info_ = nullptr;
}
else if (mode == "DSA") {
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("dsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048");
if (found) gen_key_info_->SetAlgo(algo);
if (gen_subkey_info_ == nullptr) {
- gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true);
+ gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true);
}
- auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("elg2048");
+ auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048");
if (s_found) gen_subkey_info_->SetAlgo(s_algo);
}
else if (mode == "ECC (25519)") {
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
if (found) gen_key_info_->SetAlgo(algo);
if (gen_subkey_info_ == nullptr) {
- gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true);
+ gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true);
}
- auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("cv25519");
+ auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
if (s_found) gen_subkey_info_->SetAlgo(s_algo);
}
else {
- auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048");
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
if (found) gen_key_info_->SetAlgo(algo);
if (gen_subkey_info_ == nullptr) {
- gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true);
+ gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true);
}
- auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("rsa2048");
+ auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
if (s_found) gen_subkey_info_->SetAlgo(s_algo);
}
refresh_widgets_state();
}
-void KeyGenDialog::slot_easy_valid_date_changed(const QString& mode) {
+void KeyGenerateDialog::slot_easy_valid_date_changed(const QString& mode) {
if (mode == tr("3 Months")) {
gen_key_info_->SetNonExpired(false);
gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addMonths(3));
@@ -575,15 +602,60 @@ void KeyGenDialog::slot_easy_valid_date_changed(const QString& mode) {
refresh_widgets_state();
}
-void KeyGenDialog::slot_set_easy_valid_date_2_custom() {
+void KeyGenerateDialog::slot_set_easy_valid_date_2_custom() {
ui_->easyValidityPeriodComboBox->blockSignals(true);
ui_->easyValidityPeriodComboBox->setCurrentText(tr("Custom"));
ui_->easyValidityPeriodComboBox->blockSignals(false);
}
-void KeyGenDialog::slot_set_easy_key_algo_2_custom() {
+void KeyGenerateDialog::slot_set_easy_key_algo_2_custom() {
ui_->easyAlgoComboBox->blockSignals(true);
ui_->easyAlgoComboBox->setCurrentText(tr("Custom"));
ui_->easyAlgoComboBox->blockSignals(false);
}
+
+void KeyGenerateDialog::slot_easy_combination_changed(const QString& mode) {
+ if (mode == tr("Primary Key Only")) {
+ gen_subkey_info_ = nullptr;
+ } else {
+ gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true);
+ }
+
+ slot_set_easy_key_algo_2_custom();
+ refresh_widgets_state();
+}
+
+void KeyGenerateDialog::do_generate() {
+ if (!GetSettings()
+ .value("gnupg/use_pinentry_as_password_input_dialog",
+ QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
+ .toBool() &&
+ !ui_->noPassphraseCheckBox->isChecked()) {
+ SetCacheValue("PinentryContext", "NEW_PASSPHRASE");
+ }
+
+ auto f = [this,
+ gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) {
+ GpgKeyOpera::GetInstance(channel_).GenerateKeyWithSubkey(
+ gen_key_info, gen_subkey_info_,
+ [this, hd](GpgError err, const DataObjectPtr&) {
+ // stop showing waiting dialog
+ hd();
+
+ if (CheckGpgError(err) == GPG_ERR_USER_1) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Unknown error occurred"));
+ return;
+ }
+
+ CommonUtils::RaiseMessageBox(
+ this->parentWidget() != nullptr ? this->parentWidget() : this,
+ err);
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
+ emit SignalKeyGenerated();
+ }
+ });
+ };
+ GpgOperaHelper::WaitForOpera(this, tr("Generating"), f);
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h
index 63690831..a4d27900 100644
--- a/src/ui/dialog/key_generate/KeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h
@@ -28,7 +28,7 @@
#pragma once
-#include "core/model/GpgGenKeyInfo.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "ui/dialog/GeneralDialog.h"
class Ui_KeyGenDialog;
@@ -39,7 +39,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyGenDialog : public GeneralDialog {
+class KeyGenerateDialog : public GeneralDialog {
Q_OBJECT
public:
@@ -50,7 +50,7 @@ class KeyGenDialog : public GeneralDialog {
* @param key The key to show details of
* @param parent The parent of this widget
*/
- explicit KeyGenDialog(int channel, QWidget* parent = nullptr);
+ explicit KeyGenerateDialog(int channel, QWidget* parent = nullptr);
signals:
/**
@@ -93,6 +93,13 @@ class KeyGenDialog : public GeneralDialog {
*/
void slot_set_easy_key_algo_2_custom();
+ /**
+ * @brief
+ *
+ * @param mode
+ */
+ void slot_easy_combination_changed(const QString& mode);
+
private:
/**
* @brief
@@ -109,8 +116,8 @@ class KeyGenDialog : public GeneralDialog {
///< entries of line edits
QSharedPointer<Ui_KeyGenDialog> ui_;
- QSharedPointer<GenKeyInfo> gen_key_info_; ///<
- QSharedPointer<GenKeyInfo> gen_subkey_info_; ///<
+ QSharedPointer<KeyGenerateInfo> gen_key_info_; ///<
+ QSharedPointer<KeyGenerateInfo> gen_subkey_info_; ///<
QContainer<KeyAlgo> supported_primary_key_algos_;
QContainer<KeyAlgo> supported_subkey_algos_;
@@ -148,6 +155,12 @@ class KeyGenDialog : public GeneralDialog {
*
*/
void sync_gen_subkey_info();
+
+ /**
+ * @brief
+ *
+ */
+ void do_generate();
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index b55e4b28..a2f7a4ae 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -127,10 +127,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
key_type_combo_box_ = new QComboBox(this);
no_pass_phrase_check_box_ = new QCheckBox(this);
- for (const auto& algo : GenKeyInfo::GetSupportedSubkeyAlgo()) {
+ for (const auto& algo : KeyGenerateInfo::GetSupportedSubkeyAlgo()) {
key_type_combo_box_->addItem(algo.Name());
}
- if (!GenKeyInfo::GetSupportedSubkeyAlgo().empty()) {
+ if (!KeyGenerateInfo::GetSupportedSubkeyAlgo().empty()) {
key_type_combo_box_->setCurrentIndex(0);
}
@@ -189,7 +189,7 @@ void SubkeyGenerateDialog::set_signal_slot() {
connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this,
[this](int state) -> void {
- gen_key_info_->SetNonPassPhrase(state != 0);
+ gen_subkey_info_->SetNonPassPhrase(state != 0);
});
}
@@ -202,49 +202,49 @@ void SubkeyGenerateDialog::slot_expire_box_changed() {
}
void SubkeyGenerateDialog::refresh_widgets_state() {
- if (gen_key_info_->IsAllowEncryption()) {
+ if (gen_subkey_info_->IsAllowEncryption()) {
key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked);
} else {
key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Unchecked);
}
- if (gen_key_info_->IsAllowChangeEncryption()) {
+ if (gen_subkey_info_->IsAllowChangeEncryption()) {
key_usage_check_boxes_[0]->setDisabled(false);
} else {
key_usage_check_boxes_[0]->setDisabled(true);
}
- if (gen_key_info_->IsAllowSigning()) {
+ if (gen_subkey_info_->IsAllowSigning()) {
key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Checked);
} else {
key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Unchecked);
}
- if (gen_key_info_->IsAllowChangeSigning()) {
+ if (gen_subkey_info_->IsAllowChangeSigning()) {
key_usage_check_boxes_[1]->setDisabled(false);
} else {
key_usage_check_boxes_[1]->setDisabled(true);
}
- if (gen_key_info_->IsAllowCertification()) {
+ if (gen_subkey_info_->IsAllowCertification()) {
key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Checked);
} else {
key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Unchecked);
}
- if (gen_key_info_->IsAllowChangeCertification()) {
+ if (gen_subkey_info_->IsAllowChangeCertification()) {
key_usage_check_boxes_[2]->setDisabled(false);
} else {
key_usage_check_boxes_[2]->setDisabled(true);
}
- if (gen_key_info_->IsAllowAuthentication()) {
+ if (gen_subkey_info_->IsAllowAuthentication()) {
key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Checked);
} else {
key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Unchecked);
}
- if (gen_key_info_->IsAllowChangeAuthentication()) {
+ if (gen_subkey_info_->IsAllowChangeAuthentication()) {
key_usage_check_boxes_[3]->setDisabled(false);
} else {
key_usage_check_boxes_[3]->setDisabled(true);
@@ -252,103 +252,76 @@ void SubkeyGenerateDialog::refresh_widgets_state() {
}
void SubkeyGenerateDialog::slot_key_gen_accept() {
- QString buffer;
- QTextStream err_stream(&buffer);
-
- /**
- * primary keys should have a reasonable expiration date (no more than 2 years
- * in the future)
- */
- if (date_edit_->dateTime() > QDateTime::currentDateTime().addYears(2)) {
- err_stream << " " << tr("Expiration time no more than 2 years.") << " ";
- }
-
- auto err_string = err_stream.readAll();
-
- if (err_string.isEmpty()) {
- if (expire_check_box_->checkState() != 0U) {
- gen_key_info_->SetNonExpired(true);
- } else {
- gen_key_info_->SetExpireTime(date_edit_->dateTime());
- }
-
- GpgOperaHelper::WaitForOpera(
- this, tr("Generating"),
- [this, key = this->key_,
- gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) {
- GpgKeyOpera::GetInstance(current_gpg_context_channel_)
- .GenerateSubkey(key, gen_key_info,
- [this, hd](GpgError err, const DataObjectPtr&) {
- // stop showing waiting dialog
- hd();
-
- if (CheckGpgError(err) == GPG_ERR_USER_1) {
- QMessageBox::critical(
- this, tr("Error"),
- tr("Unknown error occurred"));
- return;
- }
-
- CommonUtils::RaiseMessageBox(this, err);
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- emit UISignalStation::GetInstance()
- -> SignalKeyDatabaseRefresh();
- }
- });
- });
- this->done(0);
-
+ if (expire_check_box_->checkState() != 0U) {
+ gen_subkey_info_->SetNonExpired(true);
} else {
- /**
- * create error message
- */
- error_label_->setAutoFillBackground(true);
- QPalette error = error_label_->palette();
- error.setColor(QPalette::Window, "#ff8080");
- error_label_->setPalette(error);
- error_label_->setText(err_string);
-
- this->show();
+ gen_subkey_info_->SetExpireTime(date_edit_->dateTime());
}
+
+ GpgOperaHelper::WaitForOpera(
+ this, tr("Generating"),
+ [this, key = this->key_,
+ gen_key_info = this->gen_subkey_info_](const OperaWaitingHd& hd) {
+ GpgKeyOpera::GetInstance(current_gpg_context_channel_)
+ .GenerateSubkey(key, gen_key_info,
+ [this, hd](GpgError err, const DataObjectPtr&) {
+ // stop showing waiting dialog
+ hd();
+
+ if (CheckGpgError(err) == GPG_ERR_USER_1) {
+ QMessageBox::critical(
+ this, tr("Error"),
+ tr("Unknown error occurred"));
+ return;
+ }
+
+ CommonUtils::RaiseMessageBox(this, err);
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
+ emit UISignalStation::GetInstance()
+ -> SignalKeyDatabaseRefresh();
+ }
+ });
+ });
+ this->done(0);
}
void SubkeyGenerateDialog::slot_encryption_box_changed(int state) {
if (state == 0) {
- gen_key_info_->SetAllowEncryption(false);
+ gen_subkey_info_->SetAllowEncryption(false);
} else {
- gen_key_info_->SetAllowEncryption(true);
+ gen_subkey_info_->SetAllowEncryption(true);
}
}
void SubkeyGenerateDialog::slot_signing_box_changed(int state) {
if (state == 0) {
- gen_key_info_->SetAllowSigning(false);
+ gen_subkey_info_->SetAllowSigning(false);
} else {
- gen_key_info_->SetAllowSigning(true);
+ gen_subkey_info_->SetAllowSigning(true);
}
}
void SubkeyGenerateDialog::slot_certification_box_changed(int state) {
if (state == 0) {
- gen_key_info_->SetAllowCertification(false);
+ gen_subkey_info_->SetAllowCertification(false);
} else {
- gen_key_info_->SetAllowCertification(true);
+ gen_subkey_info_->SetAllowCertification(true);
}
}
void SubkeyGenerateDialog::slot_authentication_box_changed(int state) {
if (state == 0) {
- gen_key_info_->SetAllowAuthentication(false);
+ gen_subkey_info_->SetAllowAuthentication(false);
} else {
- gen_key_info_->SetAllowAuthentication(true);
+ gen_subkey_info_->SetAllowAuthentication(true);
}
}
void SubkeyGenerateDialog::slot_activated_key_type(int index) {
// check
- assert(gen_key_info_->GetSupportedSubkeyAlgo().size() >
+ assert(gen_subkey_info_->GetSupportedSubkeyAlgo().size() >
static_cast<size_t>(index));
- gen_key_info_->SetAlgo(gen_key_info_->GetSupportedSubkeyAlgo()[index]);
+ gen_subkey_info_->SetAlgo(gen_subkey_info_->GetSupportedSubkeyAlgo()[index]);
refresh_widgets_state();
}
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index b8c525bd..ad47bbf2 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -31,8 +31,8 @@
#include <memory>
#include "core/function/gpg/GpgContext.h"
-#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgKey.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/MemoryUtils.h"
#include "ui/GpgFrontendUI.h"
@@ -60,8 +60,8 @@ class SubkeyGenerateDialog : public GeneralDialog {
int current_gpg_context_channel_; ///<
GpgKey key_; ///<
- QSharedPointer<GenKeyInfo> gen_key_info_ =
- QSharedPointer<GenKeyInfo>::create(true); ///<
+ QSharedPointer<KeyGenerateInfo> gen_subkey_info_ =
+ QSharedPointer<KeyGenerateInfo>::create(true); ///<
QGroupBox* key_usage_group_box_{};
QDialogButtonBox* button_box_; ///< Box for standard buttons
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index f83226ed..38a5399c 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -441,7 +441,7 @@ void KeyMgmt::SlotExportKeyToClipboard() {
}
void KeyMgmt::SlotGenerateKeyDialog() {
- (new KeyGenDialog(key_list_->GetCurrentGpgContextChannel(), this))->exec();
+ (new KeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), this))->exec();
this->raise();
}
diff --git a/ui/KeyGenDialog.ui b/ui/KeyGenDialog.ui
index 254cdb92..8e850f1b 100644
--- a/ui/KeyGenDialog.ui
+++ b/ui/KeyGenDialog.ui
@@ -32,21 +32,21 @@
<number>5</number>
</property>
<item row="4" column="0">
- <widget class="QLabel" name="label_3">
+ <widget class="QLabel" name="commentLabel">
<property name="text">
<string>Comment</string>
</property>
</widget>
</item>
<item row="3" column="0">
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="emailLabel">
<property name="text">
<string>Email</string>
</property>
</widget>
</item>
<item row="2" column="0">
- <widget class="QLabel" name="label">
+ <widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name</string>
</property>
@@ -62,7 +62,7 @@
<widget class="QLineEdit" name="emailEdit"/>
</item>
<item row="5" column="0">
- <widget class="QLabel" name="label_6">
+ <widget class="QLabel" name="keyDBLabel">
<property name="text">
<string>Key Database</string>
</property>
@@ -86,7 +86,7 @@
<property name="documentMode">
<bool>true</bool>
</property>
- <widget class="QWidget" name="tab">
+ <widget class="QWidget" name="easyTab">
<attribute name="title">
<string>Easy Mode</string>
</attribute>
@@ -94,7 +94,7 @@
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
- <widget class="QLabel" name="label_4">
+ <widget class="QLabel" name="easyValidPeriodLabel">
<property name="text">
<string>Validity Period</string>
</property>
@@ -107,12 +107,22 @@
<widget class="QComboBox" name="easyValidityPeriodComboBox"/>
</item>
<item row="0" column="0">
- <widget class="QLabel" name="label_5">
+ <widget class="QLabel" name="easyAlgoLabel">
<property name="text">
<string>Algorithm</string>
</property>
</widget>
</item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="combinationLabel">
+ <property name="text">
+ <string>Combination</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" colspan="2">
+ <widget class="QComboBox" name="easyCombinationComboBox"/>
+ </item>
</layout>
</item>
<item>
@@ -130,7 +140,7 @@
</item>
</layout>
</widget>
- <widget class="QWidget" name="tab_2">
+ <widget class="QWidget" name="pTab">
<attribute name="title">
<string>Primary Key</string>
</attribute>
@@ -138,28 +148,28 @@
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
- <widget class="QLabel" name="label_13">
+ <widget class="QLabel" name="pKeyLengthLabel">
<property name="text">
<string>Key Length</string>
</property>
</widget>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="label_7">
+ <widget class="QLabel" name="pValidPeriodLabel">
<property name="text">
<string>Validity Period</string>
</property>
</widget>
</item>
<item row="0" column="0">
- <widget class="QLabel" name="label_9">
+ <widget class="QLabel" name="pAlgoLabel">
<property name="text">
<string>Algorithm</string>
</property>
</widget>
</item>
<item row="4" column="0">
- <widget class="QLabel" name="label_8">
+ <widget class="QLabel" name="pUsageLabel">
<property name="text">
<string>Usage</string>
</property>
@@ -230,7 +240,7 @@
</item>
</layout>
</widget>
- <widget class="QWidget" name="tab_3">
+ <widget class="QWidget" name="sTab">
<attribute name="title">
<string>Subkey</string>
</attribute>
@@ -238,14 +248,14 @@
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
- <widget class="QLabel" name="label_10">
+ <widget class="QLabel" name="sValidPeriodLabel">
<property name="text">
<string>Validity Period</string>
</property>
</widget>
</item>
<item row="4" column="0">
- <widget class="QLabel" name="label_12">
+ <widget class="QLabel" name="sUsageLabel">
<property name="text">
<string>Usage</string>
</property>
@@ -255,7 +265,7 @@
<widget class="QDateTimeEdit" name="sValidityPeriodDateTimeEdit"/>
</item>
<item row="3" column="0">
- <widget class="QLabel" name="label_14">
+ <widget class="QLabel" name="sKeyLengthLabel">
<property name="text">
<string>Key Length</string>
</property>
@@ -293,7 +303,7 @@
</layout>
</item>
<item row="0" column="0">
- <widget class="QLabel" name="label_11">
+ <widget class="QLabel" name="sAlgoLabel">
<property name="text">
<string>Algorithm</string>
</property>