diff options
author | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
commit | bf538056b24a68b8fd235b1c50991ee8eb46a776 (patch) | |
tree | e1bab54095b80df62b321fb5bd69453f9f951b05 /src/core/function/gpg/GpgKeyGetter.cpp | |
parent | feat: improve api and ui of keys import and export (diff) | |
download | GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.tar.gz GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.zip |
refactor: use QString instead of std::string and improve threading system
Diffstat (limited to 'src/core/function/gpg/GpgKeyGetter.cpp')
-rw-r--r-- | src/core/function/gpg/GpgKeyGetter.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 5c5ed039..e22979d7 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -46,7 +46,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { GF_CORE_LOG_DEBUG("called channel: {}", channel); } - auto GetKey(const std::string& fpr, bool use_cache) -> GpgKey { + auto GetKey(const QString& fpr, bool use_cache) -> GpgKey { // find in cache first if (use_cache) { auto key = get_key_in_cache(fpr); @@ -54,7 +54,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { } gpgme_key_t p_key = nullptr; - gpgme_get_key(ctx_.DefaultContext(), fpr.c_str(), &p_key, 1); + gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 1); if (p_key == nullptr) { GF_CORE_LOG_WARN("GpgKeyGetter GetKey Private _p_key Null fpr", fpr); return GetPubkey(fpr, true); @@ -62,7 +62,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { return GpgKey(std::move(p_key)); } - auto GetPubkey(const std::string& fpr, bool use_cache) -> GpgKey { + auto GetPubkey(const QString& fpr, bool use_cache) -> GpgKey { // find in cache first if (use_cache) { auto key = get_key_in_cache(fpr); @@ -70,7 +70,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { } gpgme_key_t p_key = nullptr; - gpgme_get_key(ctx_.DefaultContext(), fpr.c_str(), &p_key, 0); + gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 0); if (p_key == nullptr) GF_CORE_LOG_WARN("GpgKeyGetter GetKey _p_key Null", fpr); return GpgKey(std::move(p_key)); @@ -181,7 +181,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { * @brief cache the keys with key id * */ - std::map<std::string, GpgKey> keys_cache_; + std::map<QString, GpgKey> keys_cache_; /** * @brief shared mutex for the keys cache @@ -195,7 +195,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { * @param id * @return GpgKey */ - auto get_key_in_cache(const std::string& key_id) -> GpgKey { + 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()) { std::lock_guard<std::mutex> lock(ctx_mutex_); @@ -216,12 +216,11 @@ GpgKeyGetter::GpgKeyGetter(int channel) GpgKeyGetter::~GpgKeyGetter() = default; -auto GpgKeyGetter::GetKey(const std::string& key_id, bool use_cache) -> GpgKey { +auto GpgKeyGetter::GetKey(const QString& key_id, bool use_cache) -> GpgKey { return p_->GetKey(key_id, use_cache); } -auto GpgKeyGetter::GetPubkey(const std::string& key_id, bool use_cache) - -> GpgKey { +auto GpgKeyGetter::GetPubkey(const QString& key_id, bool use_cache) -> GpgKey { return p_->GetPubkey(key_id, use_cache); } |