GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgConstants.h
1
29#ifndef GPG_CONSTANTS_H
30#define GPG_CONSTANTS_H
31
32#include <GpgFrontend.h>
33#include <gpgme.h>
34
35#include <cassert>
36#include <functional>
37
38// dll export macro
39#include "GpgFrontendCoreExport.h"
40
41const int RESTART_CODE = 1000;
42
43namespace GpgFrontend {
44
45using ByteArray = std::string;
46using ByteArrayPtr = std::unique_ptr<ByteArray>;
47using StdBypeArrayPtr = std::unique_ptr<ByteArray>;
48using BypeArrayRef = ByteArray&;
49using BypeArrayConstRef = const ByteArray&;
50using StringArgsPtr = std::unique_ptr<std::vector<std::string>>;
51using StringArgsRef = std::vector<std::string>&;
52
53using GpgError = gpgme_error_t;
54
60 void operator()(void* _result);
61};
62
63using GpgEncrResult = std::shared_ptr<struct _gpgme_op_encrypt_result>;
64using GpgDecrResult = std::shared_ptr<struct _gpgme_op_decrypt_result>;
65using GpgSignResult = std::shared_ptr<struct _gpgme_op_sign_result>;
66using GpgVerifyResult = std::shared_ptr<struct _gpgme_op_verify_result>;
67using GpgGenKeyResult = std::shared_ptr<struct _gpgme_op_genkey_result>;
68
69// Convert from gpgme_xxx_result to GpgXXXResult
70
77GPGFRONTEND_CORE_EXPORT GpgEncrResult
78_new_result(gpgme_encrypt_result_t&& result);
79
86GPGFRONTEND_CORE_EXPORT GpgDecrResult
87_new_result(gpgme_decrypt_result_t&& result);
88
95GPGFRONTEND_CORE_EXPORT GpgSignResult _new_result(gpgme_sign_result_t&& result);
96
103GPGFRONTEND_CORE_EXPORT GpgVerifyResult
104_new_result(gpgme_verify_result_t&& result);
105
112GPGFRONTEND_CORE_EXPORT GpgGenKeyResult
113_new_result(gpgme_genkey_result_t&& result);
114
115// Error Info Printer
116
123GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err);
124
132GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError gpgmeError,
133 const std::string& comment);
134
142GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code(
143 gpgme_error_t err, gpgme_error_t predict = GPG_ERR_NO_ERROR);
144
145// Fingerprint
146
153GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(
154 BypeArrayConstRef fingerprint);
155
156// File Operation
157
164std::string read_all_data_in_file(const std::string& path);
165
174GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(
175 const std::string& path, const std::string& out_buffer);
176
183std::string get_file_extension(const std::string& path);
184
191std::string get_only_file_name_with_path(const std::string& path);
192
193// Check
194
201int text_is_signed(BypeArrayRef text);
202
203// Channels
204const int GPGFRONTEND_DEFAULT_CHANNEL = 0;
205const int GPGFRONTEND_NON_ASCII_CHANNEL = 2;
206
211class GPGFRONTEND_CORE_EXPORT GpgConstants {
212 public:
213 static const char* PGP_CRYPT_BEGIN;
214 static const char* PGP_CRYPT_END;
215 static const char* PGP_SIGNED_BEGIN;
216 static const char* PGP_SIGNED_END;
217 static const char* PGP_SIGNATURE_BEGIN;
218 static const char* PGP_SIGNATURE_END;
219 static const char* PGP_PUBLIC_KEY_BEGIN;
220 static const char* PGP_PRIVATE_KEY_BEGIN;
221 static const char* GPG_FRONTEND_SHORT_CRYPTO_HEAD;
222};
223
224} // namespace GpgFrontend
225
226#endif // GPG_CONSTANTS_H
Definition: GpgConstants.h:211
static const char * PGP_CRYPT_BEGIN
Definition: GpgConstants.h:213
Definition: CoreCommonUtil.cpp:29
int text_is_signed(BypeArrayRef text)
Definition: GpgConstants.cpp:176
GPGFRONTEND_CORE_EXPORT GpgEncrResult _new_result(gpgme_encrypt_result_t &&result)
Definition: GpgConstants.cpp:191
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:64
GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(const std::string &path, const std::string &out_buffer)
Definition: GpgConstants.cpp:135
std::string get_only_file_name_with_path(const std::string &path)
Get the only file name with path object.
Definition: GpgConstants.cpp:164
std::string read_all_data_in_file(const std::string &path)
Definition: GpgConstants.cpp:117
GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(BypeArrayConstRef fingerprint)
Definition: GpgConstants.cpp:85
std::string get_file_extension(const std::string &path)
Get the file extension object.
Definition: GpgConstants.cpp:151
GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err)
Definition: GpgConstants.cpp:55
Result Deleter.
Definition: GpgConstants.h:59