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 "GpgFrontendCore.h"
33 
34 const int RESTART_CODE = 1000;
35 const int DEEP_RESTART_CODE = 1001; // refresh core and ui
36 
37 namespace GpgFrontend {
38 using ByteArray = std::string;
39 using ByteArrayPtr = std::unique_ptr<ByteArray>;
40 using StdBypeArrayPtr = std::unique_ptr<ByteArray>;
41 using BypeArrayRef = ByteArray&;
42 using BypeArrayConstRef = const ByteArray&;
43 using StringArgsPtr = std::unique_ptr<std::vector<std::string>>;
44 using StringArgsRef = std::vector<std::string>&;
45 
46 using GpgError = gpgme_error_t;
47 
53  void operator()(void* _result);
54 };
55 
56 using GpgEncrResult = std::shared_ptr<struct _gpgme_op_encrypt_result>;
57 using GpgDecrResult = std::shared_ptr<struct _gpgme_op_decrypt_result>;
58 using GpgSignResult = std::shared_ptr<struct _gpgme_op_sign_result>;
59 using GpgVerifyResult = std::shared_ptr<struct _gpgme_op_verify_result>;
60 using GpgGenKeyResult = std::shared_ptr<struct _gpgme_op_genkey_result>;
61 
62 // Convert from gpgme_xxx_result to GpgXXXResult
63 
70 GPGFRONTEND_CORE_EXPORT GpgEncrResult
71 _new_result(gpgme_encrypt_result_t&& result);
72 
79 GPGFRONTEND_CORE_EXPORT GpgDecrResult
80 _new_result(gpgme_decrypt_result_t&& result);
81 
88 GPGFRONTEND_CORE_EXPORT GpgSignResult _new_result(gpgme_sign_result_t&& result);
89 
96 GPGFRONTEND_CORE_EXPORT GpgVerifyResult
97 _new_result(gpgme_verify_result_t&& result);
98 
105 GPGFRONTEND_CORE_EXPORT GpgGenKeyResult
106 _new_result(gpgme_genkey_result_t&& result);
107 
108 // Error Info Printer
109 
116 GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err);
117 
125 GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError gpgmeError,
126  const std::string& comment);
127 
135 GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code(
136  gpgme_error_t err, gpgme_error_t predict = GPG_ERR_NO_ERROR);
137 
138 // Fingerprint
139 
146 GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(
147  BypeArrayConstRef fingerprint);
148 
149 // File Operation
150 
157 std::string read_all_data_in_file(const std::string& path);
158 
167 GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(
168  const std::string& path, const std::string& out_buffer);
169 
176 std::string get_file_extension(const std::string& path);
177 
184 std::string get_only_file_name_with_path(const std::string& path);
185 
186 // Check
187 
194 int text_is_signed(BypeArrayRef text);
195 
196 // Channels
197 const int GPGFRONTEND_DEFAULT_CHANNEL = 0;
198 const int GPGFRONTEND_NON_ASCII_CHANNEL = 2;
199 
204 class GPGFRONTEND_CORE_EXPORT GpgConstants {
205  public:
206  static const char* PGP_CRYPT_BEGIN;
207  static const char* PGP_CRYPT_END;
208  static const char* PGP_SIGNED_BEGIN;
209  static const char* PGP_SIGNED_END;
210  static const char* PGP_SIGNATURE_BEGIN;
211  static const char* PGP_SIGNATURE_END;
212  static const char* PGP_PUBLIC_KEY_BEGIN;
213  static const char* PGP_PRIVATE_KEY_BEGIN;
214  static const char* GPG_FRONTEND_SHORT_CRYPTO_HEAD;
215 };
216 
217 } // namespace GpgFrontend
218 
219 #endif // GPG_CONSTANTS_H
Definition: GpgConstants.h:204
static const char * PGP_CRYPT_BEGIN
Definition: GpgConstants.h:206
Definition: CoreCommonUtil.cpp:29
int text_is_signed(BypeArrayRef text)
Definition: GpgConstants.cpp:158
GPGFRONTEND_CORE_EXPORT GpgEncrResult _new_result(gpgme_encrypt_result_t &&result)
Definition: GpgConstants.cpp:173
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:63
GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(const std::string &path, const std::string &out_buffer)
Definition: GpgConstants.cpp:128
std::string get_only_file_name_with_path(const std::string &path)
Get the only file name with path object.
Definition: GpgConstants.cpp:146
std::string read_all_data_in_file(const std::string &path)
Definition: GpgConstants.cpp:122
GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(BypeArrayConstRef fingerprint)
Definition: GpgConstants.cpp:90
std::string get_file_extension(const std::string &path)
Get the file extension object.
Definition: GpgConstants.cpp:133
GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err)
Definition: GpgConstants.cpp:54
Result Deleter.
Definition: GpgConstants.h:52