diff options
author | saturneric <[email protected]> | 2025-02-01 23:21:59 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-02-01 23:21:59 +0000 |
commit | d06c31abe7e2540518c4d3471acd381edfababa3 (patch) | |
tree | 7efec63216119a6a3b77208328ba59419acd905f /src/core | |
parent | fix: issues found on unit test mode (diff) | |
download | GpgFrontend-d06c31abe7e2540518c4d3471acd381edfababa3.tar.gz GpgFrontend-d06c31abe7e2540518c4d3471acd381edfababa3.zip |
feat: upgrade KeyGenDialog to meet easy and advanced requirements
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/GpgCoreInit.cpp | 2 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.cpp | 411 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.h | 21 | ||||
-rw-r--r-- | src/core/model/GpgGenKeyInfo.cpp | 423 | ||||
-rw-r--r-- | src/core/model/GpgGenKeyInfo.h | 142 | ||||
-rw-r--r-- | src/core/typedef/GpgTypedef.h | 2 |
6 files changed, 369 insertions, 632 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index b564307a..5018b8e4 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -637,7 +637,7 @@ void StartMonitorCoreInitializationStatus() { "core", "env.state.basic", 0); LOG_D() << "monitor: core env is still initializing, waiting..."; - QThread::msleep(15); + QThread::msleep(100); } if (core_init_state < 0) return -1; diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 800a6708..cf4d1e3b 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -163,337 +163,168 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key, }}); } +auto GenerateKeyImpl(GpgContext& ctx, const QSharedPointer<GenKeyInfo>& params, + const DataObjectPtr& data_object) -> GpgError { + const auto userid = params->GetUserid(); + const auto algo = params->GetAlgo().Id(); + + unsigned long expires = + QDateTime::currentDateTime().secsTo(params->GetExpireTime()); + + GpgError err; + unsigned int flags = 0; + + if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; + if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; + if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; + if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; + if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; + if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; + + LOG_D() << "key generation args: " << userid << algo << expires << flags; + LOG_D() << "key generation flags" << params->IsAllowEncryption() + << params->IsAllowSigning() << params->IsAllowAuthentication() + << !params->IsSubKey(); + + err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), algo.toUtf8(), + 0, expires, nullptr, flags); + + if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { + data_object->Swap( + {GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}}); + } else { + data_object->Swap({GpgGenerateKeyResult{}}); + } + + return CheckGpgError(err); +} + /** * Generate a new key pair * @param params key generation args * @return error information */ -void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params, +void GpgKeyOpera::GenerateKey(const QSharedPointer<GenKeyInfo>& params, const GpgOperationCallback& callback) { RunGpgOperaAsync( - [&ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError { - auto userid = params->GetUserid(); - auto algo = params->GetAlgo() + params->GetKeySizeStr(); - - LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr(); - - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - - GpgError err; - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "key generation args: " << userid << algo << expires - << flags; - - err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), - algo.toUtf8(), 0, expires, nullptr, flags); - assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); - - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{ - gpgme_op_genkey_result(ctx.DefaultContext())}}); - } else { - data_object->Swap({GpgGenerateKeyResult{}}); - } - - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateKeyImpl(ctx_, params, data_object); }, callback, "gpgme_op_createkey", "2.1.0"); } -auto GpgKeyOpera::GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params) +auto GpgKeyOpera::GenerateKeySync(const QSharedPointer<GenKeyInfo>& params) -> std::tuple<GpgError, DataObjectPtr> { return RunGpgOperaSync( - [=, &ctx = ctx_](const DataObjectPtr& data_object) -> GpgError { - auto userid = params->GetUserid(); - auto algo = params->GetAlgo() + params->GetKeySizeStr(); - - LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr(); - - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - - GpgError err; - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "key generation args: " << userid << algo << expires - << flags; - - err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), - algo.toUtf8(), 0, expires, nullptr, flags); - assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); - - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{ - gpgme_op_genkey_result(ctx.DefaultContext())}}); - } else { - data_object->Swap({GpgGenerateKeyResult{}}); - } - - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateKeyImpl(ctx_, params, data_object); }, "gpgme_op_createkey", "2.1.0"); } +auto GenerateSubKeyImpl(GpgContext& ctx, const GpgKey& key, + const QSharedPointer<GenKeyInfo>& 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(); + + auto algo = params->GetAlgo().Id(); + unsigned long expires = + QDateTime::currentDateTime().secsTo(params->GetExpireTime()); + unsigned int flags = 0; + + if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; + if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; + if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; + if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; + if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; + if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; + + LOG_D() << "subkey generation args: " << key.GetId() << algo << expires + << flags; + + auto err = + gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key), + algo.toLatin1(), 0, expires, flags); + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { + data_object->Swap({GpgGenerateKeyResult{}}); + return err; + } + + data_object->Swap( + {GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}}); + return CheckGpgError(err); +} + void GpgKeyOpera::GenerateSubkey(const GpgKey& key, - const std::shared_ptr<GenKeyInfo>& params, + const QSharedPointer<GenKeyInfo>& params, const GpgOperationCallback& callback) { RunGpgOperaAsync( - [key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError { - if (!params->IsSubKey()) return GPG_ERR_CANCELED; - - LOG_D() << "generate subkey algo: " << params->GetAlgo() - << "key size: " << params->GetKeySizeStr(); - - auto algo = params->GetAlgo() + params->GetKeySizeStr(); - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "subkey generation args: " << key.GetId() << algo << expires - << flags; - - auto err = gpgme_op_createsubkey(ctx.DefaultContext(), - static_cast<gpgme_key_t>(key), - algo.toLatin1(), 0, expires, flags); - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{}}); - return err; - } - - data_object->Swap({GpgGenerateKeyResult{ - gpgme_op_genkey_result(ctx.DefaultContext())}}); - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateSubKeyImpl(ctx_, key, params, data_object); }, callback, "gpgme_op_createsubkey", "2.1.13"); } auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key, - const std::shared_ptr<GenKeyInfo>& params) + const QSharedPointer<GenKeyInfo>& params) -> std::tuple<GpgError, DataObjectPtr> { return RunGpgOperaSync( - [key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError { - if (!params->IsSubKey()) return GPG_ERR_CANCELED; - - LOG_D() << "generate subkey algo: " << params->GetAlgo() - << " key size: " << params->GetKeySizeStr(); - - auto algo = params->GetAlgo() + params->GetKeySizeStr(); - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << " args: " << key.GetId() << algo << expires << flags; - - auto err = gpgme_op_createsubkey(ctx.DefaultContext(), - static_cast<gpgme_key_t>(key), - algo.toLatin1(), 0, expires, flags); - - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{}}); - return err; - } - - data_object->Swap({GpgGenerateKeyResult{ - gpgme_op_genkey_result(ctx.DefaultContext())}}); - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateSubKeyImpl(ctx_, key, params, data_object); }, "gpgme_op_createsubkey", "2.1.13"); } +auto GenerateKeyWithSubkeyImpl(GpgContext& ctx, GpgKeyGetter& key_getter, + const QSharedPointer<GenKeyInfo>& p_params, + const QSharedPointer<GenKeyInfo>& s_params, + const DataObjectPtr& data_object) -> GpgError { + auto err = GenerateKeyImpl(ctx, p_params, data_object); + + if (err != GPG_ERR_NO_ERROR) return err; + if (!data_object->Check<GpgGenerateKeyResult>()) return GPG_ERR_CANCELED; + + auto result = ExtractParams<GpgGenerateKeyResult>(data_object, 0); + auto key = key_getter.GetKey(result.GetFingerprint()); + if (!key.IsGood()) { + LOG_W() << "cannot get key which has been generated, fpr: " + << result.GetFingerprint(); + return GPG_ERR_CANCELED; + } + + if (s_params == nullptr) return err; + + data_object->Swap({}); + err = GenerateSubKeyImpl(ctx, key, s_params, data_object); + auto s_result = ExtractParams<GpgGenerateKeyResult>(data_object, 0); + + data_object->Swap({result, s_result}); + return err; +} + void GpgKeyOpera::GenerateKeyWithSubkey( - const std::shared_ptr<GenKeyInfo>& params, - const std::shared_ptr<GenKeyInfo>& subkey_params, + const QSharedPointer<GenKeyInfo>& p_params, + const QSharedPointer<GenKeyInfo>& s_params, const GpgOperationCallback& callback) { RunGpgOperaAsync( - [&ctx = ctx_, params, subkey_params, - channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError { - auto userid = params->GetUserid().toUtf8(); - auto algo = (params->GetAlgo() + params->GetKeySizeStr()).toUtf8(); - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - - GpgError err; - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "key generation args: " << userid << algo << expires - << flags; - - err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires, - nullptr, flags); - assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); - - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{}}); - return err; - } - - auto genkey_result = - GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}; - - if (subkey_params == nullptr || !subkey_params->IsSubKey()) { - data_object->Swap({genkey_result}); - return err; - } - - auto key = GpgKeyGetter::GetInstance(channel).GetKey( - genkey_result.GetFingerprint()); - if (!key.IsGood()) { - LOG_W() << "cannot get key which has been generate, fpr: " - << genkey_result.GetFingerprint(); - return err; - } - - algo = (subkey_params->GetAlgo() + subkey_params->GetKeySizeStr()) - .toUtf8(); - expires = - QDateTime::currentDateTime().secsTo(subkey_params->GetExpireTime()); - - flags = 0; - if (subkey_params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (subkey_params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (subkey_params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "subkey generation args: " << key.GetId() << algo << expires - << flags; - - err = gpgme_op_createsubkey(ctx.DefaultContext(), - static_cast<gpgme_key_t>(key), algo, 0, - expires, flags); - - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - data_object->Swap( - {genkey_result, GpgGenerateKeyResult{gpgme_op_genkey_result( - ctx.DefaultContext())}}); - } else { - data_object->Swap({genkey_result, GpgGenerateKeyResult{}}); - } - - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params, + data_object); }, callback, "gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0"); } auto GpgKeyOpera::GenerateKeyWithSubkeySync( - const std::shared_ptr<GenKeyInfo>& params, - const std::shared_ptr<GenKeyInfo>& subkey_params) + const QSharedPointer<GenKeyInfo>& p_params, + const QSharedPointer<GenKeyInfo>& s_params) -> std::tuple<GpgError, DataObjectPtr> { return RunGpgOperaSync( - [&ctx = ctx_, params, subkey_params, - channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError { - auto userid = params->GetUserid().toUtf8(); - auto algo = (params->GetAlgo() + params->GetKeySizeStr()).toUtf8(); - unsigned long expires = - QDateTime::currentDateTime().secsTo(params->GetExpireTime()); - - GpgError err; - unsigned int flags = 0; - - if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT; - if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "key generation args: " << userid << algo << expires - << flags; - - err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires, - nullptr, flags); - assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); - - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - data_object->Swap({GpgGenerateKeyResult{}}); - return err; - } - - auto genkey_result = - GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}; - - if (subkey_params == nullptr || !subkey_params->IsSubKey()) { - data_object->Swap({genkey_result}); - return err; - } - - auto key = GpgKeyGetter::GetInstance(channel).GetKey( - genkey_result.GetFingerprint()); - if (!key.IsGood()) { - LOG_W() << "cannot get key which has been generate, fpr: " - << genkey_result.GetFingerprint(); - return err; - } - - LOG_D() << "try to generate subkey of key: " << key.GetId() - << ", algo :" << subkey_params->GetAlgo() - << ", key size: " << subkey_params->GetKeySizeStr(); - - algo = (subkey_params->GetAlgo() + subkey_params->GetKeySizeStr()) - .toUtf8(); - expires = - QDateTime::currentDateTime().secsTo(subkey_params->GetExpireTime()); - - flags = 0; - if (subkey_params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; - if (subkey_params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN; - if (subkey_params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH; - if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; - if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - - LOG_D() << "subkey generation args: " << key.GetId() << algo << expires - << flags; - - err = gpgme_op_createsubkey(ctx.DefaultContext(), - static_cast<gpgme_key_t>(key), algo, 0, - expires, flags); - - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - data_object->Swap( - {genkey_result, GpgGenerateKeyResult{gpgme_op_genkey_result( - ctx.DefaultContext())}}); - } else { - data_object->Swap({genkey_result, GpgGenerateKeyResult{}}); - } - - return CheckGpgError(err); + [=](const DataObjectPtr& data_object) -> GpgError { + return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params, + data_object); }, "gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0"); } diff --git a/src/core/function/gpg/GpgKeyOpera.h b/src/core/function/gpg/GpgKeyOpera.h index 0084d473..d724f5f8 100644 --- a/src/core/function/gpg/GpgKeyOpera.h +++ b/src/core/function/gpg/GpgKeyOpera.h @@ -31,6 +31,7 @@ #include <functional> #include "core/function/gpg/GpgContext.h" +#include "core/function/gpg/GpgKeyGetter.h" #include "core/typedef/GpgTypedef.h" namespace GpgFrontend { @@ -114,7 +115,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @param result * @return GpgFrontend::GpgError */ - void GenerateKey(const std::shared_ptr<GenKeyInfo>&, + void GenerateKey(const QSharedPointer<GenKeyInfo>&, const GpgOperationCallback&); /** @@ -122,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * * @param params */ - auto GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params) + auto GenerateKeySync(const QSharedPointer<GenKeyInfo>& params) -> std::tuple<GpgError, DataObjectPtr>; /** @@ -133,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @return GpgFrontend::GpgError */ void GenerateSubkey(const GpgKey& key, - const std::shared_ptr<GenKeyInfo>& params, + const QSharedPointer<GenKeyInfo>& params, const GpgOperationCallback&); /** @@ -143,7 +144,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @param params */ auto GenerateSubkeySync(const GpgKey& key, - const std::shared_ptr<GenKeyInfo>& params) + const QSharedPointer<GenKeyInfo>& params) -> std::tuple<GpgError, DataObjectPtr>; /** @@ -153,8 +154,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @param subkey_params * @param callback */ - void GenerateKeyWithSubkey(const std::shared_ptr<GenKeyInfo>& params, - const std::shared_ptr<GenKeyInfo>& subkey_params, + void GenerateKeyWithSubkey(const QSharedPointer<GenKeyInfo>& p_params, + const QSharedPointer<GenKeyInfo>& s_params, const GpgOperationCallback& callback); /** @@ -164,13 +165,15 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @param subkey_params * @param callback */ - auto GenerateKeyWithSubkeySync( - const std::shared_ptr<GenKeyInfo>& params, - const std::shared_ptr<GenKeyInfo>& subkey_params) + auto GenerateKeyWithSubkeySync(const QSharedPointer<GenKeyInfo>& p_params, + const QSharedPointer<GenKeyInfo>& s_params) -> std::tuple<GpgError, DataObjectPtr>; private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< + + GpgKeyGetter& key_getter_ = + GpgKeyGetter::GetInstance(SingletonFunctionObject::GetChannel()); ///< }; } // namespace GpgFrontend diff --git a/src/core/model/GpgGenKeyInfo.cpp b/src/core/model/GpgGenKeyInfo.cpp index 180a7fab..2b8a3dbc 100644 --- a/src/core/model/GpgGenKeyInfo.cpp +++ b/src/core/model/GpgGenKeyInfo.cpp @@ -35,125 +35,141 @@ namespace GpgFrontend { -void GenKeyInfo::SetAlgo(const QString &t_algo_args) { - auto algo_args = t_algo_args.toLower(); - - // reset all options - reset_options(); - - if (!this->subkey_) { - this->SetAllowCertification(true); - - } else { - this->SetAllowCertification(false); - } - - this->allow_change_certification_ = false; - - if (algo_args == "rsa") { - /** - * RSA is the world’s premier asymmetric cryptographic algorithm, - * and is built on the difficulty of factoring extremely large composites. - * GnuPG supports RSA with key sizes of between 1024 and 4096 bits. - */ - suggest_min_key_size_ = 1024; - suggest_max_key_size_ = 4096; - suggest_size_addition_step_ = 1024; - SetKeyLength(2048); - - } else if (algo_args == "dsa") { +const QContainer<KeyAlgo> GenKeyInfo::kPrimaryKeyAlgos = { /** * Algorithm (DSA) as a government standard for digital signatures. * Originally, it supported key lengths between 512 and 1024 bits. * Recently, NIST has declared 512-bit keys obsolete: * now, DSA is available in 1024, 2048 and 3072-bit lengths. */ - - SetAllowEncryption(false); - allow_change_encryption_ = false; - - suggest_min_key_size_ = 1024; - suggest_max_key_size_ = 3072; - suggest_size_addition_step_ = 1024; - SetKeyLength(2048); - } else if (algo_args == "elg") { + {"rsa1024", "RSA", "RSA", 1024, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"}, + {"rsa2048", "RSA", "RSA", 2048, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"}, + {"rsa3072", "RSA", "RSA", 3072, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"}, + {"rsa4096", "RSA", "RSA", 4096, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"}, + {"dsa1024", "DSA", "DSA", 1024, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"dsa2048", "DSA", "DSA", 2048, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"dsa3072", "DSA", "DSA", 3072, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"ed25519", "ED25519", "EdDSA", 256, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"nistp256", "NIST", "ECDSA", 256, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"nistp384", "NIST", "ECDSA", 384, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"nistp521", "NIST", "ECDSA", 521, kSIGN | kAUTH | kCERT, "2.2.0"}, + {"brainpoolp256r1", "BrainPooL", "ECDSA", 256, kSIGN | kAUTH | kCERT, + "2.3.0"}, + {"brainpoolp384r1", "BrainPooL", "ECDSA", 384, kSIGN | kAUTH | kCERT, + "2.3.0"}, + {"brainpoolp512r1", "BrainPooL", "ECDSA", 512, kSIGN | kAUTH | kCERT, + "2.3.0"}, + {"ed448", "ED448", "EdDSA", 448, kSIGN | kAUTH | kCERT, "2.3.0"}, + {"secp256k1", "ED448", "EdDSA", 256, kSIGN | kAUTH | kCERT, "2.3.0"}, +}; + +const QContainer<KeyAlgo> GenKeyInfo::kSubKeyAlgos = { + {"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"}, + {"rsa4096", "RSA", "RSA", 4096, kENCRYPT | kSIGN | kAUTH, "2.2.0"}, + {"dsa1024", "DSA", "DSA", 1024, kSIGN | kAUTH, "2.2.0"}, + {"dsa2048", "DSA", "DSA", 2048, kSIGN | kAUTH, "2.2.0"}, + {"dsa3072", "DSA", "DSA", 3072, kSIGN | kAUTH, "2.2.0"}, + {"ed25519", "ED25519", "EdDSA", 256, kSIGN | kAUTH, "2.2.0"}, + {"cv25519", "CV25519", "ECDH", 256, kENCRYPT, "2.2.0"}, + {"nistp256", "NIST", "ECDH", 256, kENCRYPT, "2.2.0"}, + {"nistp384", "NIST", "ECDH", 384, kENCRYPT, "2.2.0"}, + {"nistp521", "NIST", "ECDH", 521, kENCRYPT, "2.2.0"}, + {"brainpoolp256r1", "BrainPooL", "ECDH", 256, kENCRYPT, "2.3.0"}, + {"brainpoolp384r1", "BrainPooL", "ECDH", 384, kENCRYPT, "2.3.0"}, + {"brainpoolp512r1", "BrainPooL", "ECDH", 512, kENCRYPT, "2.3.0"}, + {"x448", "X448", "ECDH", 448, kENCRYPT, "2.3.0"}, + {"secp256k1", "SECP256K1", "ECDH", 256, kENCRYPT, "2.3.0"}, /** * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths * ranging from 1024 to 4096 bits. */ + {"elg1024", "ELG-E", "ELG-E", 1024, kENCRYPT, "2.2.0"}, + {"elg2048", "ELG-E", "ELG-E", 2048, kENCRYPT, "2.2.0"}, + {"elg3072", "ELG-E", "ELG-E", 3072, kENCRYPT, "2.2.0"}, + {"elg4096", "ELG-E", "ELG-E", 4096, kENCRYPT, "2.2.0"}, +}; + +auto GenKeyInfo::GetSupportedKeyAlgo() -> QContainer<KeyAlgo> { + const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); - SetAllowEncryption(true); - - SetAllowAuthentication(false); - allow_change_authentication_ = false; - - SetAllowSigning(false); - allow_change_signing_ = false; - - suggest_min_key_size_ = 1024; - suggest_max_key_size_ = 4096; - suggest_size_addition_step_ = 1024; - SetKeyLength(3072); - - } else if (algo_args == "ed25519") { - SetAllowEncryption(false); - allow_change_encryption_ = false; - - suggest_min_key_size_ = -1; - suggest_max_key_size_ = -1; - suggest_size_addition_step_ = -1; - SetKeyLength(-1); - } else if (algo_args == "cv25519" || algo_args == "x448") { - SetAllowAuthentication(false); - allow_change_authentication_ = false; - - SetAllowSigning(false); - allow_change_signing_ = false; - - suggest_min_key_size_ = -1; - suggest_max_key_size_ = -1; - suggest_size_addition_step_ = -1; - SetKeyLength(-1); - } else if (algo_args == "ed448") { - SetAllowEncryption(false); - allow_change_encryption_ = false; - - // it should allow signing or it's bug - SetAllowSigning(true); - allow_change_signing_ = true; - - suggest_min_key_size_ = -1; - suggest_max_key_size_ = -1; - suggest_size_addition_step_ = -1; - SetKeyLength(-1); - } else if (algo_args == "nistp256" || algo_args == "nistp384" || - algo_args == "nistp521" || algo_args == "brainpoolp256r1" || - algo_args == "brainpoolp384r1" || algo_args == "brainpoolp512r1" || - algo_args == "secp256k1") { - if (!subkey_) { // for primary key is always ecdsa - - SetAllowEncryption(false); - allow_change_encryption_ = false; - - } else { // for subkey key is always ecdh - - SetAllowAuthentication(false); - allow_change_authentication_ = false; - - SetAllowSigning(false); - allow_change_signing_ = false; - } - - suggest_min_key_size_ = -1; - suggest_max_key_size_ = -1; - suggest_size_addition_step_ = -1; - SetKeyLength(-1); - } else { - LOG_W() << "unsupported genkey algo arguments: " << algo_args; - return; + QContainer<KeyAlgo> algos; + + for (const auto &algo : kPrimaryKeyAlgos) { + if (!algo.IsSupported(gnupg_version)) continue; + algos.append(algo); } - this->algo_ = algo_args; + std::sort(algos.begin(), algos.end(), [](const KeyAlgo &a, const KeyAlgo &b) { + return a.Name() < b.Name() && a.KeyLength() < b.KeyLength(); + }); + + return algos; +} + +auto GenKeyInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> { + const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); + + QContainer<KeyAlgo> algos; + + for (const auto &algo : kSubKeyAlgos) { + if (!algo.IsSupported(gnupg_version)) continue; + algos.append(algo); + } + + std::sort(algos.begin(), algos.end(), [](const KeyAlgo &a, const KeyAlgo &b) { + return a.Name() < b.Name() && a.KeyLength() < b.KeyLength(); + }); + + return algos; +} + +auto GenKeyInfo::SearchPrimaryKeyAlgo(const QString &algo_id) + -> std::tuple<bool, KeyAlgo> { + auto it = + std::find_if(kPrimaryKeyAlgos.cbegin(), kPrimaryKeyAlgos.cend(), + [=](const KeyAlgo &algo) { return algo.Id() == algo_id; }); + + if (it != kPrimaryKeyAlgos.cend()) { + return {true, *it}; + } + + return {false, KeyAlgo{}}; +} + +auto GenKeyInfo::SearchSubKeyAlgo(const QString &algo_id) + -> std::tuple<bool, KeyAlgo> { + auto it = + std::find_if(kSubKeyAlgos.cbegin(), kSubKeyAlgos.cend(), + [=](const KeyAlgo &algo) { return algo.Id() == algo_id; }); + + if (it != kSubKeyAlgos.cend()) { + return {true, *it}; + } + + return {false, KeyAlgo{}}; +} + +void GenKeyInfo::SetAlgo(const KeyAlgo &algo) { + // reset all options + reset_options(); + + this->SetAllowCertification(algo.CanCert()); + this->allow_change_certification_ = false; + + SetAllowEncryption(algo.CanEncrypt()); + allow_change_encryption_ = algo.CanEncrypt(); + + SetAllowSigning(algo.CanSign()); + allow_change_signing_ = algo.CanSign(); + + SetAllowAuthentication(algo.CanAuth()); + allow_change_authentication_ = algo.CanAuth(); + + this->algo_ = algo; } void GenKeyInfo::reset_options() { @@ -168,29 +184,10 @@ void GenKeyInfo::reset_options() { allow_change_authentication_ = true; SetAllowAuthentication(true); - - passphrase_.clear(); -} - -auto GenKeyInfo::GetKeySizeStr() const -> QString { - if (key_size_ > 0) { - return QString::number(key_size_); - } - return {}; -} - -void GenKeyInfo::SetKeyLength(int m_key_size) { - if (m_key_size < suggest_min_key_size_ || - m_key_size > suggest_max_key_size_) { - return; - } - GenKeyInfo::key_size_ = m_key_size; } void GenKeyInfo::SetExpireTime(const QDateTime &m_expired) { - if (!IsNonExpired()) { - GenKeyInfo::expired_ = m_expired; - } + GenKeyInfo::expired_ = m_expired; } void GenKeyInfo::SetNonExpired(bool m_non_expired) { @@ -210,103 +207,9 @@ void GenKeyInfo::SetAllowCertification(bool m_allow_certification) { } } -GenKeyInfo::GenKeyInfo(bool m_is_sub_key) : subkey_(m_is_sub_key) { +GenKeyInfo::GenKeyInfo(bool is_subkey) : subkey_(is_subkey) { assert(!GetSupportedKeyAlgo().empty()); - SetAlgo(std::get<0>(GetSupportedKeyAlgo()[0])); -} - -auto GenKeyInfo::GetSupportedKeyAlgo() - -> const QContainer<GenKeyInfo::KeyGenAlgo> & { - static QContainer<GenKeyInfo::KeyGenAlgo> k_support_key_algo = { - {"RSA", "RSA", ""}, - {"DSA", "DSA", ""}, - }; - static bool initialized = false; - - if (!initialized) { - const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( - "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); - if (GFCompareSoftwareVersion(gnupg_version, "2.0.0") < 0) { - // do nothing - } else if (GFCompareSoftwareVersion(gnupg_version, "2.3.0") < 0) { - k_support_key_algo = { - {"RSA", "RSA", ""}, - {"DSA", "DSA", ""}, - {"EdDSA (ED25519)", "ED25519", ""}, - {"ECDSA (NIST P-256)", "NISTP256", ""}, - {"ECDSA (NIST P-384)", "NISTP384", ""}, - {"ECDSA (NIST P-521)", "NISTP521", ""}, - }; - } else { - k_support_key_algo = { - {"RSA", "RSA", ""}, - {"DSA", "DSA", ""}, - {"EdDSA (ED448)", "ED448", ""}, - {"EdDSA (ED25519)", "ED25519", ""}, - {"ECDSA (SECP256K1)", "SECP256K1", ""}, - {"ECDSA (NIST P-256)", "NISTP256", ""}, - {"ECDSA (NIST P-384)", "NISTP384", ""}, - {"ECDSA (NIST P-521)", "NISTP521", ""}, - {"ECDSA (BrainPooL P-256)", "BRAINPOOLP256R1", ""}, - {"ECDSA (BrainPooL P-384)", "BRAINPOOLP384R1", ""}, - {"ECDSA (BrainPooL P-512)", "BRAINPOOLP512R1", ""}, - }; - } - - initialized = true; - } - - return k_support_key_algo; -} - -auto GenKeyInfo::GetSupportedSubkeyAlgo() - -> const QContainer<GenKeyInfo::KeyGenAlgo> & { - static QContainer<GenKeyInfo::KeyGenAlgo> k_support_subkey_algo = { - {"RSA", "", "RSA"}, - {"DSA", "", "DSA"}, - {"ELG-E", "", "ELG"}, - }; - static bool initialized = false; - - if (!initialized) { - const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( - "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); - if (GFCompareSoftwareVersion(gnupg_version, "2.0.0") < 0) { - // do nothing - } else if (GFCompareSoftwareVersion(gnupg_version, "2.3.0") < 0) { - k_support_subkey_algo = { - {"RSA", "", "RSA"}, - {"DSA", "", "DSA"}, - {"ELG-E", "", "ELG"}, - {"EdDSA (ED25519)", "", "ED25519"}, - {"ECDH (CV25519)", "", "CV25519"}, - {"ECDH (NIST P-256)", "", "NISTP256"}, - {"ECDH (NIST P-384)", "", "NISTP384"}, - {"ECDH (NIST P-521)", "", "NISTP521"}, - }; - } else { - k_support_subkey_algo = { - {"RSA", "", "RSA"}, - {"DSA", "", "DSA"}, - {"ELG-E", "", "ELG"}, - {"EdDSA (ED25519)", "", "ED25519"}, - {"ECDH (CV25519)", "", "CV25519"}, - {"ECDH (SECP256K1)", "", "SECP256K1"}, - {"EdDSA (ED448)", "", "ED448"}, - {"ECDH (X448)", "", "X448"}, - {"ECDH (NIST P-256)", "", "NISTP256"}, - {"ECDH (NIST P-384)", "", "NISTP384"}, - {"ECDH (NIST P-521)", "", "NISTP521"}, - {"ECDH (BrainPooL P-256)", "", "BRAINPOOLP256R1"}, - {"ECDH (BrainPooL P-384)", "", "BRAINPOOLP384R1"}, - {"ECDH (BrainPooL P-512)", "", "BRAINPOOLP512R1"}, - }; - } - - initialized = true; - } - - return k_support_subkey_algo; + SetAlgo(GetSupportedKeyAlgo().front()); } /** @@ -386,7 +289,7 @@ void GenKeyInfo::SetComment(const QString &m_comment) { * * @return const QString& */ -[[nodiscard]] auto GenKeyInfo::GetAlgo() const -> const QString & { +[[nodiscard]] auto GenKeyInfo::GetAlgo() const -> const KeyAlgo & { return algo_; } @@ -395,7 +298,9 @@ void GenKeyInfo::SetComment(const QString &m_comment) { * * @return int */ -[[nodiscard]] auto GenKeyInfo::GetKeyLength() const -> int { return key_size_; } +[[nodiscard]] auto GenKeyInfo::GetKeyLength() const -> int { + return algo_.KeyLength(); +} /** * @brief Get the Expired object @@ -506,24 +411,6 @@ void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) { } /** - * @brief Get the Pass Phrase object - * - * @return const QString& - */ -[[nodiscard]] auto GenKeyInfo::GetPassPhrase() const -> const QString & { - return passphrase_; -} - -/** - * @brief Set the Pass Phrase object - * - * @param m_pass_phrase - */ -void GenKeyInfo::SetPassPhrase(const QString &m_pass_phrase) { - GenKeyInfo::passphrase_ = m_pass_phrase; -} - -/** * @brief * * @return true @@ -563,31 +450,37 @@ void GenKeyInfo::SetPassPhrase(const QString &m_pass_phrase) { return allow_change_authentication_; } -/** - * @brief Get the Suggest Max Key Size object - * - * @return int - */ -[[nodiscard]] auto GenKeyInfo::GetSuggestMaxKeySize() const -> int { - return suggest_max_key_size_; -} +KeyAlgo::KeyAlgo(QString id, QString name, QString type, int length, int opera, + QString supported_version) + : id_(std::move(id)), + name_(std::move(name)), + type_(std::move(type)), + length_(length), + supported_version_(std::move(supported_version)) { + encrypt_ = ((opera & kENCRYPT) != 0); + sign_ = ((opera & kSIGN) != 0); + auth_ = ((opera & kAUTH) != 0); + cert_ = ((opera & kCERT) != 0); +}; -/** - * @brief Get the Suggest Min Key Size object - * - * @return int - */ -[[nodiscard]] auto GenKeyInfo::GetSuggestMinKeySize() const -> int { - return suggest_min_key_size_; -} +auto KeyAlgo::Id() const -> QString { return id_; } -/** - * @brief Get the Size Change Step object - * - * @return int - */ -[[nodiscard]] auto GenKeyInfo::GetSizeChangeStep() const -> int { - return suggest_size_addition_step_; +auto KeyAlgo::Name() const -> QString { return name_; } + +auto KeyAlgo::KeyLength() const -> int { return length_; } + +auto KeyAlgo::Type() const -> QString { return type_; } + +auto KeyAlgo::CanEncrypt() const -> bool { return encrypt_; } + +auto KeyAlgo::CanSign() const -> bool { return sign_; } + +auto KeyAlgo::CanAuth() const -> bool { return auth_; } + +auto KeyAlgo::CanCert() const -> bool { return cert_; } + +auto KeyAlgo::IsSupported(const QString &version) const -> bool { + return GFCompareSoftwareVersion(version, supported_version_) >= 0; } } // namespace GpgFrontend diff --git a/src/core/model/GpgGenKeyInfo.h b/src/core/model/GpgGenKeyInfo.h index 460dffc6..a6dd03b0 100644 --- a/src/core/model/GpgGenKeyInfo.h +++ b/src/core/model/GpgGenKeyInfo.h @@ -28,14 +28,60 @@ #pragma once +#include <utility> + #include "core/GpgFrontendCoreExport.h" +#include "core/function/gpg/GpgKeyOpera.h" #include "core/typedef/CoreTypedef.h" namespace GpgFrontend { +class GPGFRONTEND_CORE_EXPORT KeyAlgo { + public: + KeyAlgo() = default; + + KeyAlgo(QString id, QString name, QString type, int length, int opera, + QString supported_version); + + KeyAlgo(const KeyAlgo &) = default; + + auto operator=(const KeyAlgo &) -> KeyAlgo & = default; + + [[nodiscard]] auto Id() const -> QString; + + [[nodiscard]] auto Name() const -> QString; + + [[nodiscard]] auto KeyLength() const -> int; + + [[nodiscard]] auto Type() const -> QString; + + [[nodiscard]] auto CanEncrypt() const -> bool; + + [[nodiscard]] auto CanSign() const -> bool; + + [[nodiscard]] auto CanAuth() const -> bool; + + [[nodiscard]] auto CanCert() const -> bool; + + [[nodiscard]] auto IsSupported(const QString &version) const -> bool; + + private: + QString id_; + QString name_; + QString type_; + int length_; + bool encrypt_; + bool sign_; + bool auth_; + bool cert_; + QString supported_version_; +}; + class GPGFRONTEND_CORE_EXPORT GenKeyInfo { public: - using KeyGenAlgo = std::tuple<QString, QString, QString>; + static const QContainer<KeyAlgo> kPrimaryKeyAlgos; + + static const QContainer<KeyAlgo> kSubKeyAlgos; /** * @brief Construct a new Gen Key Info object @@ -43,21 +89,39 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { * @param m_is_sub_key * @param m_standalone */ - explicit GenKeyInfo(bool m_is_sub_key = false); + explicit GenKeyInfo(bool is_subkey = false); /** * @brief Get the Supported Key Algo object * * @return const QContainer<KeyGenAlgo>& */ - static auto GetSupportedKeyAlgo() -> const QContainer<KeyGenAlgo> &; + static auto GetSupportedKeyAlgo() -> QContainer<KeyAlgo>; /** * @brief Get the Supported Subkey Algo object * * @return const QContainer<KeyGenAlgo>& */ - static auto GetSupportedSubkeyAlgo() -> const QContainer<KeyGenAlgo> &; + static auto GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo>; + + /** + * @brief + * + * @param algo_id + * @return std::tuple<bool, KeyAlgo> + */ + static auto SearchPrimaryKeyAlgo(const QString &algo_id) + -> std::tuple<bool, KeyAlgo>; + + /** + * @brief + * + * @param algo_id + * @return std::tuple<bool, KeyAlgo> + */ + static auto SearchSubKeyAlgo(const QString &algo_id) + -> std::tuple<bool, KeyAlgo>; /** * @brief @@ -72,7 +136,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { * * @param m_sub_key */ - void SetIsSubKey(bool m_sub_key); + void SetIsSubKey(bool); /** * @brief Get the Userid object @@ -86,21 +150,21 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { * * @param m_name */ - void SetName(const QString &m_name); + void SetName(const QString &name); /** * @brief Set the Email object * * @param m_email */ - void SetEmail(const QString &m_email); + void SetEmail(const QString &email); /** * @brief Set the Comment object * * @param m_comment */ - void SetComment(const QString &m_comment); + void SetComment(const QString &comment); /** * @brief Get the Name object @@ -128,21 +192,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { * * @return const QString& */ - [[nodiscard]] auto GetAlgo() const -> const QString &; + [[nodiscard]] auto GetAlgo() const -> const KeyAlgo &; /** * @brief Set the Algo object * * @param m_algo */ - void SetAlgo(const QString &); - - /** - * @brief Get the Key Size Str object - * - * @return QString - */ - [[nodiscard]] auto GetKeySizeStr() const -> QString; + void SetAlgo(const KeyAlgo &); /** * @brief Get the Key Size object @@ -152,13 +209,6 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { [[nodiscard]] auto GetKeyLength() const -> int; /** - * @brief Set the Key Size object - * - * @param m_key_size - */ - void SetKeyLength(int m_key_size); - - /** * @brief Get the Expired object * * @return const QDateTime& @@ -271,20 +321,6 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { void SetAllowAuthentication(bool m_allow_authentication); /** - * @brief Get the Pass Phrase object - * - * @return const QString& - */ - [[nodiscard]] auto GetPassPhrase() const -> const QString &; - - /** - * @brief Set the Pass Phrase object - * - * @param m_pass_phrase - */ - void SetPassPhrase(const QString &m_pass_phrase); - - /** * @brief * * @return true @@ -316,47 +352,19 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { */ [[nodiscard]] auto IsAllowChangeAuthentication() const -> bool; - /** - * @brief Get the Suggest Max Key Size object - * - * @return int - */ - [[nodiscard]] auto GetSuggestMaxKeySize() const -> int; - - /** - * @brief Get the Suggest Min Key Size object - * - * @return int - */ - [[nodiscard]] auto GetSuggestMinKeySize() const -> int; - - /** - * @brief Get the Size Change Step object - * - * @return int - */ - [[nodiscard]] auto GetSizeChangeStep() const -> int; - private: bool subkey_ = false; ///< QString name_; ///< QString email_; ///< QString comment_; ///< - QString algo_; ///< - int key_size_ = 2048; + KeyAlgo algo_; ///< QDateTime expired_ = QDateTime::currentDateTime().addYears(2); bool non_expired_ = false; ///< bool no_passphrase_ = false; ///< bool allow_no_pass_phrase_ = true; ///< - int suggest_max_key_size_ = 4096; ///< - int suggest_size_addition_step_ = 1024; ///< - int suggest_min_key_size_ = 1024; ///< - - QString passphrase_; ///< - bool allow_encryption_ = true; ///< bool allow_change_encryption_ = true; ///< bool allow_certification_ = true; ///< diff --git a/src/core/typedef/GpgTypedef.h b/src/core/typedef/GpgTypedef.h index fffc5cf4..8d9fbf5f 100644 --- a/src/core/typedef/GpgTypedef.h +++ b/src/core/typedef/GpgTypedef.h @@ -69,5 +69,7 @@ enum GpgOperation { kVERIFY = 1 << 3, kENCRYPT_SIGN = 1 << 4, kDECRYPT_VERIFY = 1 << 5, + kAUTH = 1 << 6, + kCERT = 1 << 7, }; } // namespace GpgFrontend
\ No newline at end of file |