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 
41 const int RESTART_CODE = 1000;
42 
43 namespace GpgFrontend {
44 
45 using ByteArray = std::string;
46 using ByteArrayPtr = std::unique_ptr<ByteArray>;
47 using StdBypeArrayPtr = std::unique_ptr<ByteArray>;
48 using BypeArrayRef = ByteArray&;
49 using BypeArrayConstRef = const ByteArray&;
50 using StringArgsPtr = std::unique_ptr<std::vector<std::string>>;
51 using StringArgsRef = std::vector<std::string>&;
52 
53 using GpgError = gpgme_error_t;
54 
60  void operator()(void* _result);
61 };
62 
63 using GpgEncrResult = std::shared_ptr<struct _gpgme_op_encrypt_result>;
64 using GpgDecrResult = std::shared_ptr<struct _gpgme_op_decrypt_result>;
65 using GpgSignResult = std::shared_ptr<struct _gpgme_op_sign_result>;
66 using GpgVerifyResult = std::shared_ptr<struct _gpgme_op_verify_result>;
67 using GpgGenKeyResult = std::shared_ptr<struct _gpgme_op_genkey_result>;
68 
69 // Convert from gpgme_xxx_result to GpgXXXResult
70 
77 GPGFRONTEND_CORE_EXPORT GpgEncrResult
78 _new_result(gpgme_encrypt_result_t&& result);
79 
86 GPGFRONTEND_CORE_EXPORT GpgDecrResult
87 _new_result(gpgme_decrypt_result_t&& result);
88 
95 GPGFRONTEND_CORE_EXPORT GpgSignResult _new_result(gpgme_sign_result_t&& result);
96 
103 GPGFRONTEND_CORE_EXPORT GpgVerifyResult
104 _new_result(gpgme_verify_result_t&& result);
105 
112 GPGFRONTEND_CORE_EXPORT GpgGenKeyResult
113 _new_result(gpgme_genkey_result_t&& result);
114 
115 // Error Info Printer
116 
123 GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err);
124 
132 GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError gpgmeError,
133  const std::string& comment);
134 
142 GPGFRONTEND_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 
153 GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(
154  BypeArrayConstRef fingerprint);
155 
156 // File Operation
157 
164 std::string read_all_data_in_file(const std::string& path);
165 
174 GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(
175  const std::string& path, const std::string& out_buffer);
176 
183 std::string get_file_extension(const std::string& path);
184 
191 std::string get_only_file_name_with_path(const std::string& path);
192 
193 // Check
194 
201 int text_is_signed(BypeArrayRef text);
202 
203 // Channels
204 const int GPGFRONTEND_DEFAULT_CHANNEL = 0;
205 const int GPGFRONTEND_NON_ASCII_CHANNEL = 2;
206 
211 class 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
GpgFrontend::beautify_fingerprint
GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint(BypeArrayConstRef fingerprint)
Definition: GpgConstants.cpp:85
GpgFrontend::get_file_extension
std::string get_file_extension(const std::string &path)
Get the file extension object.
Definition: GpgConstants.cpp:151
GpgFrontend::write_buffer_to_file
GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file(const std::string &path, const std::string &out_buffer)
Definition: GpgConstants.cpp:135
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::text_is_signed
int text_is_signed(BypeArrayRef text)
Definition: GpgConstants.cpp:176
GpgFrontend::check_gpg_error
GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err)
Definition: GpgConstants.cpp:55
GpgFrontend::get_only_file_name_with_path
std::string get_only_file_name_with_path(const std::string &path)
Get the only file name with path object.
Definition: GpgConstants.cpp:164
GpgFrontend::_result_ref_deletor
Result Deleter.
Definition: GpgConstants.h:59
GpgFrontend::read_all_data_in_file
std::string read_all_data_in_file(const std::string &path)
Definition: GpgConstants.cpp:117
GpgFrontend::GpgConstants::PGP_CRYPT_BEGIN
static const char * PGP_CRYPT_BEGIN
Definition: GpgConstants.h:213
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:64
GpgFrontend::GpgConstants
Definition: GpgConstants.h:211
GpgFrontend::_new_result
GPGFRONTEND_CORE_EXPORT GpgEncrResult _new_result(gpgme_encrypt_result_t &&result)
Definition: GpgConstants.cpp:191