# GpgFrontend Project: src/core/GpgContext.h Source File

GpgContext.h
#ifndef __SGPGMEPP_CONTEXT_H__
#define __SGPGMEPP_CONTEXT_H__
#include <optional>
#include <string>
#include "GpgFunctionObject.h"
#include "GpgInfo.h"
namespace GpgFrontend {
struct GpgContextInitArgs {
// make no sense for gpg2
bool independent_database = false;
std::string db_path = {};
bool gpg_alone = false;
std::string gpg_path = {};
bool test_mode = false;
bool ascii = true;
bool offline_mode = false;
bool auto_import_missing_key = false;
bool custom_gpgconf = false;
std::string custom_gpgconf_path;
bool use_pinentry = false;
GpgContextInitArgs() = default;
};
class GPGFRONTEND_CORE_EXPORT GpgContext
: public QObject,
public SingletonFunctionObject<GpgContext> {
Q_OBJECT
public:
explicit GpgContext(const GpgContextInitArgs& args = {});
explicit GpgContext(int channel);
~GpgContext() override = default;
[[nodiscard]] bool good() const;
[[nodiscard]] const GpgInfo& GetInfo(bool refresh = false);
operator gpgme_ctx_t() const { return _ctx_ref.get(); }
private:
GpgInfo info_{};
GpgContextInitArgs args_{};
bool extend_info_loaded_ = false;
std::shared_mutex preload_lock_{};
void post_init_ctx();
std::string need_user_input_passphrase();
std::optional<std::string> check_binary_chacksum(std::filesystem::path);
struct _ctx_ref_deleter {
void operator()(gpgme_ctx_t _ctx);
};
using CtxRefHandler =
std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
CtxRefHandler _ctx_ref = nullptr;
bool good_ = true;
signals:
void SignalNeedUserInputPassphrase();
public:
static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
const char* passphrase_info,
int last_was_bad, int fd);
static gpgme_error_t custom_passphrase_cb(void* opaque, const char* uid_hint,
const char* passphrase_info,
int last_was_bad, int fd);
static gpgme_error_t test_status_cb(void* hook, const char* keyword,
const char* args);
void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
};
} // namespace GpgFrontend
#endif // __SGPGMEPP_CONTEXT_H__
GpgFrontend::GpgContext
Definition: GpgContext.h:71
GpgFrontend::GpgContext::~GpgContext
~GpgContext() override=default
Destroy the Gpg Context object.
GpgFrontend::GpgInfo
Use to record some info about gnupg.
Definition: GpgInfo.h:40
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:150
GpgFrontend
Definition: CoreCommonUtil.cpp:31
GpgFrontend::GpgContextInitArgs
Definition: GpgContext.h:44
GpgFrontend::GpgContext::_ctx_ref_deleter
Definition: GpgContext.h:145