GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgKeyGetter.h
1 
29 #ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H
30 #define GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H
31 
32 #include <mutex>
33 #include <vector>
34 
35 #include "core/GpgContext.h"
36 #include "core/GpgFunctionObject.h"
37 #include "core/GpgModel.h"
38 
39 namespace GpgFrontend {
40 
45 class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
46  : public SingletonFunctionObject<GpgKeyGetter> {
47  public:
53  explicit GpgKeyGetter(
55 
62  GpgKey GetKey(const std::string& id, bool use_cache = true);
63 
70  KeyListPtr GetKeys(const KeyIdArgsListPtr& ids);
71 
78  GpgKey GetPubkey(const std::string& id, bool use_cache = true);
79 
85  KeyLinkListPtr FetchKey();
86 
91  void FlushKeyCache();
92 
99  KeyListPtr GetKeysCopy(const KeyListPtr& keys);
100 
107  KeyLinkListPtr GetKeysCopy(const KeyLinkListPtr& keys);
108 
109  private:
114  GpgContext& ctx_ =
116 
121  mutable std::mutex ctx_mutex_;
122 
127  std::map<std::string, GpgKey> keys_cache_;
128 
133  mutable std::mutex keys_cache_mutex_;
134 
141  GpgKey get_key_in_cache(const std::string& id);
142 };
143 } // namespace GpgFrontend
144 
145 #endif // GPGFRONTEND_ZH_CN_TS_GPGKEYGETTER_H
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:159
GpgFrontend::GpgKeyGetter::GpgKeyGetter
GpgKeyGetter(int channel=SingletonFunctionObject::GetDefaultChannel())
Construct a new Gpg Key Getter object.
Definition: GpgKeyGetter.cpp:41
GpgFrontend::GpgKeyGetter::GetKeysCopy
KeyListPtr GetKeysCopy(const KeyListPtr &keys)
Get the Keys Copy object.
Definition: GpgKeyGetter.cpp:163
GpgFrontend::GpgKeyGetter::keys_cache_mutex_
std::mutex keys_cache_mutex_
shared mutex for the keys cache
Definition: GpgKeyGetter.h:133
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::SingletonFunctionObject< GpgContext >::GetInstance
static GpgContext & GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)
Get the Instance object.
Definition: GpgFunctionObject.h:181
GpgFrontend::GpgKeyGetter::get_key_in_cache
GpgKey get_key_in_cache(const std::string &id)
Get the Key object.
Definition: GpgKeyGetter.cpp:172
GpgFrontend::GpgKeyGetter
Definition: GpgKeyGetter.h:45
GpgFrontend::SingletonFunctionObject::GetChannel
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.h:252
GpgFrontend::GpgKeyGetter::FetchKey
KeyLinkListPtr FetchKey()
Get all the keys by receiving a linked list.
Definition: GpgKeyGetter.cpp:82
GpgFrontend::GpgContext
Definition: GpgContext.h:59
GpgFrontend::GpgKeyGetter::FlushKeyCache
void FlushKeyCache()
flush the keys in the cache
Definition: GpgKeyGetter.cpp:101
GpgFrontend::GpgKeyGetter::GetKey
GpgKey GetKey(const std::string &id, bool use_cache=true)
Get the Key object.
Definition: GpgKeyGetter.cpp:47
GpgFrontend::GpgKeyGetter::GetPubkey
GpgKey GetPubkey(const std::string &id, bool use_cache=true)
Get the Pubkey object.
Definition: GpgKeyGetter.cpp:67
GpgFrontend::SingletonFunctionObject::GetDefaultChannel
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:245
GpgFrontend::check_gpg_error_2_err_code
GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t predict=GPG_ERR_NO_ERROR)
Definition: GpgConstants.cpp:66
GpgFrontend::GpgKeyGetter::keys_cache_
std::map< std::string, GpgKey > keys_cache_
cache the keys with key id
Definition: GpgKeyGetter.h:127
GpgFrontend::GpgKeyGetter::GetKeys
KeyListPtr GetKeys(const KeyIdArgsListPtr &ids)
Get the Keys object.
Definition: GpgKeyGetter.cpp:147
GpgFrontend::GpgKeyGetter::ctx_mutex_
std::mutex ctx_mutex_
shared mutex for the keys cache
Definition: GpgKeyGetter.h:121
GpgFrontend::GpgKey
Definition: GpgKey.h:44