diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/gpg/GpgConstants.h | 45 | ||||
-rw-r--r-- | include/gpg/GpgContext.h | 2 | ||||
-rw-r--r-- | include/gpg/function/BasicOperator.h | 13 | ||||
-rw-r--r-- | include/gpg/function/GpgCommandExecutor.h | 46 | ||||
-rw-r--r-- | include/gpg/model/GpgKey.h | 9 | ||||
-rw-r--r-- | include/gpg/result_analyse/DecryptResultAnalyse.h | 27 | ||||
-rw-r--r-- | include/gpg/result_analyse/EncryptResultAnalyse.h | 25 | ||||
-rw-r--r-- | include/gpg/result_analyse/ResultAnalyse.h | 35 | ||||
-rw-r--r-- | include/gpg/result_analyse/SignResultAnalyse.h | 25 | ||||
-rw-r--r-- | include/gpg/result_analyse/VerifyResultAnalyse.h | 12 |
10 files changed, 178 insertions, 61 deletions
diff --git a/include/gpg/GpgConstants.h b/include/gpg/GpgConstants.h index 61037170..b4ba0e3c 100644 --- a/include/gpg/GpgConstants.h +++ b/include/gpg/GpgConstants.h @@ -25,19 +25,38 @@ #ifndef GPG_CONSTANTS_H #define GPG_CONSTANTS_H -class QString; +#include "GpgFrontend.h" const int RESTART_CODE = 1000; -class GpgConstants { -public: - static const char *PGP_CRYPT_BEGIN; - static const char *PGP_CRYPT_END; - static const char *PGP_SIGNED_BEGIN; - static const char *PGP_SIGNED_END; - static const char *PGP_SIGNATURE_BEGIN; - static const char *PGP_SIGNATURE_END; - static const char *GPG_FRONTEND_SHORT_CRYPTO_HEAD; -}; - -#endif // CONSTANTS_H +namespace GpgFrontend { + + using BypeArrayPtr = std::unique_ptr<QByteArray>; + using BypeArrayRef = QByteArray &; + + using GpgError = gpgme_error_t; + + using GpgEncrResult = std::unique_ptr<struct _gpgme_op_encrypt_result, std::function<void( + gpgme_encrypt_result_t)>>; + using GpgDecrResult = std::unique_ptr<struct _gpgme_op_decrypt_result, std::function<void( + gpgme_decrypt_result_t)>>; + using GpgSignResult = std::unique_ptr<struct _gpgme_op_sign_result, std::function<void( + gpgme_sign_result_t)>>; + using GpgVerifyResult = std::unique_ptr<struct _gpgme_op_verify_result, std::function<void( + gpgme_verify_result_t)>>; + + class GpgConstants { + public: + static const char *PGP_CRYPT_BEGIN; + static const char *PGP_CRYPT_END; + static const char *PGP_SIGNED_BEGIN; + static const char *PGP_SIGNED_END; + static const char *PGP_SIGNATURE_BEGIN; + static const char *PGP_SIGNATURE_END; + static const char *GPG_FRONTEND_SHORT_CRYPTO_HEAD; + }; +} + + + +#endif // GPG_CONSTANTS_H diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h index 7b335daa..719cd1fe 100644 --- a/include/gpg/GpgContext.h +++ b/include/gpg/GpgContext.h @@ -94,6 +94,8 @@ namespace GpgFrontend { gpgme_error_t generateSubkey(const GpgKey &key, GenKeyInfo *params); + const GpgInfo &getInfo() const { return info; } + void deleteKeys(QStringList *uidList); void clearPasswordCache(); diff --git a/include/gpg/function/BasicOperator.h b/include/gpg/function/BasicOperator.h index 8291b72a..0e9f03bf 100644 --- a/include/gpg/function/BasicOperator.h +++ b/include/gpg/function/BasicOperator.h @@ -26,24 +26,13 @@ #define GPGFRONTEND_ZH_CN_TS_BASICOPERATOR_H #include "GpgFrontend.h" +#include "gpg/GpgConstants.h" #include "gpg/GpgModel.h" #include "gpg/GpgContext.h" #include "gpg/GpgFunctionObject.h" namespace GpgFrontend { - using BypeArrayPtr = std::unique_ptr<QByteArray>; - using BypeArrayRef = QByteArray &; - - using GpgEncrResult = std::unique_ptr<struct _gpgme_op_encrypt_result, std::function<void( - gpgme_encrypt_result_t)>>; - using GpgDecrResult = std::unique_ptr<struct _gpgme_op_decrypt_result, std::function<void( - gpgme_decrypt_result_t)>>; - using GpgSignResult = std::unique_ptr<struct _gpgme_op_sign_result, std::function<void( - gpgme_sign_result_t)>>; - using GpgVerifyResult = std::unique_ptr<struct _gpgme_op_verify_result, std::function<void( - gpgme_verify_result_t)>>; - class BasicOperator : public SingletonFunctionObject<BasicOperator> { public: diff --git a/include/gpg/function/GpgCommandExecutor.h b/include/gpg/function/GpgCommandExecutor.h new file mode 100644 index 00000000..1e64390a --- /dev/null +++ b/include/gpg/function/GpgCommandExecutor.h @@ -0,0 +1,46 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_GPGCOMMANDEXECUTOR_H +#define GPGFRONTEND_ZH_CN_TS_GPGCOMMANDEXECUTOR_H + +#include "GpgFrontend.h" +#include "gpg/GpgContext.h" + +namespace GpgFrontend { + + class GpgCommandExecutor : public QObject { + Q_OBJECT + public: + void execute(const QStringList &arguments, const std::function<void(QProcess *)> &interactFunc); + + private: + + GpgContext &ctx = GpgContext::getInstance(); + }; + +} + + +#endif //GPGFRONTEND_ZH_CN_TS_GPGCOMMANDEXECUTOR_H diff --git a/include/gpg/model/GpgKey.h b/include/gpg/model/GpgKey.h index bc38c6c6..03029f69 100644 --- a/include/gpg/model/GpgKey.h +++ b/include/gpg/model/GpgKey.h @@ -85,6 +85,15 @@ namespace GpgFrontend { [[nodiscard]] bool can_authenticate() const { return _key_ref->can_authenticate; } + bool canAuthActual() { + auto subkeys = subKeys(); + if (std::any_of(subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool { + return subkey.secret() && subkey.can_authenticate() && !subkey.disabled() && !subkey.revoked() && !subkey.expired(); + })) + return true; + else return false; + } + [[nodiscard]] bool is_private_key() const { return _key_ref->secret; } diff --git a/include/gpg/result_analyse/DecryptResultAnalyse.h b/include/gpg/result_analyse/DecryptResultAnalyse.h index e7ddd389..f741ac99 100644 --- a/include/gpg/result_analyse/DecryptResultAnalyse.h +++ b/include/gpg/result_analyse/DecryptResultAnalyse.h @@ -25,20 +25,29 @@ #ifndef GPGFRONTEND_DECRYPTRESULTANALYSE_H #define GPGFRONTEND_DECRYPTRESULTANALYSE_H -#include "gpg/GpgContext.h" +#include "gpg/GpgConstants.h" #include "ResultAnalyse.h" -class DecryptResultAnalyse : public ResultAnalyse { -Q_OBJECT -public: - explicit DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result); +namespace GpgFrontend { -private: + class DecryptResultAnalyse : public ResultAnalyse { + Q_OBJECT + public: + explicit DecryptResultAnalyse(GpgError error, GpgDecrResult result); - GpgFrontend::GpgContext *mCtx; + protected: - bool printReci(QTextStream &stream, gpgme_recipient_t reci); -}; + void do_analyse() final; + + private: + + bool print_reci(QTextStream &stream, gpgme_recipient_t reci); + + GpgError error; + GpgDecrResult result; + }; + +} #endif //GPGFRONTEND_DECRYPTRESULTANALYSE_H diff --git a/include/gpg/result_analyse/EncryptResultAnalyse.h b/include/gpg/result_analyse/EncryptResultAnalyse.h index 447555c5..70e5a5e0 100644 --- a/include/gpg/result_analyse/EncryptResultAnalyse.h +++ b/include/gpg/result_analyse/EncryptResultAnalyse.h @@ -25,14 +25,29 @@ #ifndef GPGFRONTEND_ENCRYPTRESULTANALYSE_H #define GPGFRONTEND_ENCRYPTRESULTANALYSE_H +#include "gpg/GpgConstants.h" #include "ResultAnalyse.h" -class EncryptResultAnalyse : public ResultAnalyse { -Q_OBJECT -public: - explicit EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_result_t result); +namespace GpgFrontend { + class EncryptResultAnalyse : public ResultAnalyse { + Q_OBJECT + public: + + explicit EncryptResultAnalyse(GpgError error, GpgEncrResult result); + + protected: + + void do_analyse() final; + + private: + + GpgError error; + GpgEncrResult result; + + }; +} + -}; #endif //GPGFRONTEND_ENCRYPTRESULTANALYSE_H diff --git a/include/gpg/result_analyse/ResultAnalyse.h b/include/gpg/result_analyse/ResultAnalyse.h index da2e5676..0ee569c6 100644 --- a/include/gpg/result_analyse/ResultAnalyse.h +++ b/include/gpg/result_analyse/ResultAnalyse.h @@ -26,23 +26,34 @@ #include "GpgFrontend.h" -class ResultAnalyse : public QObject { -Q_OBJECT -public: - ResultAnalyse() = default; +namespace GpgFrontend { - [[nodiscard]] const QString &getResultReport() const; + class ResultAnalyse : public QObject { + Q_OBJECT + public: + ResultAnalyse() = default; - [[nodiscard]] int getStatus() const; + [[nodiscard]] const QString &getResultReport(); -protected: - QString resultText; - QTextStream stream{&resultText}; + [[nodiscard]] int getStatus(); - int status = 1; + void analyse(); - void setStatus(int mStatus); -}; + protected: + + virtual void do_analyse() = 0; + + QString resultText; + QTextStream stream{&resultText}; + + int status = 1; + + bool analysed_ = false; + + void setStatus(int mStatus); + }; + +} #endif //GPGFRONTEND_RESULTANALYSE_H diff --git a/include/gpg/result_analyse/SignResultAnalyse.h b/include/gpg/result_analyse/SignResultAnalyse.h index fdff305d..c837e957 100644 --- a/include/gpg/result_analyse/SignResultAnalyse.h +++ b/include/gpg/result_analyse/SignResultAnalyse.h @@ -28,17 +28,28 @@ #include "GpgFrontend.h" #include "ResultAnalyse.h" -#include "gpg/GpgContext.h" +#include "gpg/GpgConstants.h" -class SignResultAnalyse : public ResultAnalyse { -Q_OBJECT -public: +namespace GpgFrontend { - explicit SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result); + class SignResultAnalyse : public ResultAnalyse { + Q_OBJECT + public: + explicit SignResultAnalyse(GpgError error, GpgSignResult result); -private: + protected: -}; + void do_analyse(); + + + private: + GpgError error; + + GpgSignResult result; + + }; + +} #endif //GPGFRONTEND_SIGNRESULTANALYSE_H diff --git a/include/gpg/result_analyse/VerifyResultAnalyse.h b/include/gpg/result_analyse/VerifyResultAnalyse.h index 1774ec2c..8d80a1b6 100644 --- a/include/gpg/result_analyse/VerifyResultAnalyse.h +++ b/include/gpg/result_analyse/VerifyResultAnalyse.h @@ -25,7 +25,7 @@ #ifndef GPGFRONTEND_VERIFYRESULTANALYSE_H #define GPGFRONTEND_VERIFYRESULTANALYSE_H -#include "gpg/GpgContext.h" +#include "gpg/GpgConstants.h" #include "gpg/model/GpgKeySignature.h" #include "ResultAnalyse.h" @@ -35,12 +35,18 @@ namespace GpgFrontend { class VerifyResultAnalyse : public ResultAnalyse{ public: - explicit VerifyResultAnalyse(gpgme_error_t error, gpgme_verify_result_t result); + explicit VerifyResultAnalyse(GpgError error, GpgVerifyResult result); private: - bool printSigner(QTextStream &stream, gpgme_signature_t sign); + void do_analyse(); + private: + + bool print_signer(QTextStream &stream, gpgme_signature_t sign); + + GpgError error; + GpgVerifyResult result; }; } |