diff options
author | saturneric <[email protected]> | 2024-01-19 13:54:26 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-19 13:54:26 +0000 |
commit | 5baef3c4a3b947d3275e9ce44cfb7a68984f6cca (patch) | |
tree | 78ea7c8caeb4336d99596ae665061bb7f25611f1 /src/core/function/gpg | |
parent | fix: slove discovered faults and bugs (diff) | |
download | GpgFrontend-5baef3c4a3b947d3275e9ce44cfb7a68984f6cca.tar.gz GpgFrontend-5baef3c4a3b947d3275e9ce44cfb7a68984f6cca.zip |
fix: solve discovered bugs and improve ui operations
Diffstat (limited to 'src/core/function/gpg')
-rw-r--r-- | src/core/function/gpg/GpgFileOpera.cpp | 3 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyGetter.cpp | 26 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyImportExporter.cpp | 3 |
3 files changed, 17 insertions, 15 deletions
diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index 5abf3159..94a08c76 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -452,7 +452,6 @@ void GpgFileOpera::DecryptVerifyArchive(const QString& in_path, ArchiveFileOperator::ExtractArchiveFromDataExchanger( ex, out_path, [](GFError err, const DataObjectPtr&) { GF_CORE_LOG_DEBUG("extract archive from ex operation, err: {}", err); - GF_CORE_LOG_INFO("//////////////"); }); RunGpgOperaAsync( @@ -462,10 +461,8 @@ void GpgFileOpera::DecryptVerifyArchive(const QString& in_path, GpgData data_in(in_path, true); GpgData data_out(ex); - GF_CORE_LOG_INFO("-----------------------"); err = CheckGpgError( gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out)); - GF_CORE_LOG_INFO("++++++++++++++++++++++++"); data_object->Swap({ GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())), diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index e22979d7..4a35d3cd 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -77,17 +77,16 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { } auto FetchKey() -> KeyLinkListPtr { - if (keys_cache_.empty()) { + if (keys_search_cache_.empty()) { FlushKeyCache(); } auto keys_list = std::make_unique<GpgKeyLinkList>(); - { // get the lock std::lock_guard<std::mutex> lock(keys_cache_mutex_); - for (const auto& [key, value] : keys_cache_) { - keys_list->push_back(value); + for (const auto& key : keys_cache_) { + keys_list->push_back(key); } } return keys_list; @@ -98,6 +97,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { // clear the keys cache keys_cache_.clear(); + keys_search_cache_.clear(); // init GpgError err = gpgme_op_keylist_start(ctx_.DefaultContext(), nullptr, 0); @@ -123,12 +123,14 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { gpg_key = GetKey(gpg_key.GetId(), false); } - keys_cache_.insert({gpg_key.GetId(), std::move(gpg_key)}); + keys_cache_.push_back(gpg_key); + keys_search_cache_.insert(gpg_key.GetId(), gpg_key); + keys_search_cache_.insert(gpg_key.GetFingerprint(), gpg_key); } } GF_CORE_LOG_DEBUG("flush key channel cache address: {} object address: {}", - static_cast<void*>(&keys_cache_), + static_cast<void*>(&keys_search_cache_), static_cast<void*>(this)); // for debug @@ -181,7 +183,13 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { * @brief cache the keys with key id * */ - std::map<QString, GpgKey> keys_cache_; + QMap<QString, GpgKey> keys_search_cache_; + + /** + * @brief + * + */ + QList<GpgKey> keys_cache_; /** * @brief shared mutex for the keys cache @@ -197,10 +205,10 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { */ auto get_key_in_cache(const QString& key_id) -> GpgKey { std::lock_guard<std::mutex> lock(keys_cache_mutex_); - if (keys_cache_.find(key_id) != keys_cache_.end()) { + if (keys_search_cache_.find(key_id) != keys_search_cache_.end()) { std::lock_guard<std::mutex> lock(ctx_mutex_); // return a copy of the key in cache - return keys_cache_[key_id]; + return keys_search_cache_[key_id]; } // return a bad key diff --git a/src/core/function/gpg/GpgKeyImportExporter.cpp b/src/core/function/gpg/GpgKeyImportExporter.cpp index d2c313dd..ef8cb112 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.cpp +++ b/src/core/function/gpg/GpgKeyImportExporter.cpp @@ -63,7 +63,6 @@ auto GpgKeyImportExporter::ImportKey(const GFBuffer& in_buffer) import_info->imported_keys.emplace_back(key); status = status->next; } - return import_info; } @@ -152,8 +151,6 @@ void GpgKeyImportExporter::ExportAllKeys(const KeyArgsList& keys, bool secret, if (keys.empty()) return GPG_ERR_CANCELED; int mode = 0; - if (secret) mode |= GPGME_EXPORT_MODE_SECRET; - std::vector<gpgme_key_t> keys_array(keys.begin(), keys.end()); // Last entry data_in array has to be nullptr |