aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--include/gpg/GpgConstants.h45
-rw-r--r--include/gpg/GpgContext.h2
-rw-r--r--include/gpg/function/BasicOperator.h13
-rw-r--r--include/gpg/function/GpgCommandExecutor.h46
-rw-r--r--include/gpg/model/GpgKey.h9
-rw-r--r--include/gpg/result_analyse/DecryptResultAnalyse.h27
-rw-r--r--include/gpg/result_analyse/EncryptResultAnalyse.h25
-rw-r--r--include/gpg/result_analyse/ResultAnalyse.h35
-rw-r--r--include/gpg/result_analyse/SignResultAnalyse.h25
-rw-r--r--include/gpg/result_analyse/VerifyResultAnalyse.h12
-rw-r--r--src/gpg/function/GpgCommandExecutor.cpp45
-rw-r--r--src/gpg/gpg_context/GpgContext.cpp29
-rw-r--r--src/gpg/result_analyse/DecryptResultAnalyse.cpp22
-rw-r--r--src/gpg/result_analyse/EncryptResultAnalyse.cpp4
-rw-r--r--src/gpg/result_analyse/ResultAnalyse.cpp18
-rw-r--r--src/gpg/result_analyse/SignResultAnalyse.cpp15
-rw-r--r--src/gpg/result_analyse/VerifyResultAnalyse.cpp159
-rw-r--r--test/CMakeLists.txt19
-rw-r--r--test/GpgCoreTest.cpp33
20 files changed, 394 insertions, 190 deletions
diff --git a/.gitignore b/.gitignore
index 986db60c..c4857a03 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,7 +10,6 @@ include/GpgFrontendBuildInfo.h
# Clangd
.cache/
-test/
# C++
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;
};
}
diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp
new file mode 100644
index 00000000..98743ed4
--- /dev/null
+++ b/src/gpg/function/GpgCommandExecutor.cpp
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ *
+ */
+#include "gpg/function/GpgCommandExecutor.h"
+
+
+void GpgFrontend::GpgCommandExecutor::execute(const QStringList &arguments,
+ const std::function<void(QProcess *)> &interactFunc) {
+ QEventLoop looper;
+ auto *gpgProcess = new QProcess(&looper);
+ gpgProcess->setProcessChannelMode(QProcess::MergedChannels);
+ connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), &looper, &QEventLoop::quit);
+ connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); });
+ connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit);
+ connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; });
+ connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() {
+ qDebug() << "Function Called";
+ interactFunc(gpgProcess);
+ });
+ gpgProcess->setProgram(ctx.getInfo().appPath);
+ gpgProcess->setArguments(arguments);
+ gpgProcess->start();
+ looper.exec();
+
+}
diff --git a/src/gpg/gpg_context/GpgContext.cpp b/src/gpg/gpg_context/GpgContext.cpp
index eaaac640..a892603c 100644
--- a/src/gpg/gpg_context/GpgContext.cpp
+++ b/src/gpg/gpg_context/GpgContext.cpp
@@ -131,7 +131,7 @@ namespace GpgFrontend {
#endif
if (last_was_bad) {
- passwordDialogMessage += "<i>" + tr("Wrong password") + ".</i><br><br>\n\n";
+ passwordDialogMessage += "<i> Wrong password. </i><br><br>\n\n";
clearPasswordCache();
}
@@ -139,11 +139,11 @@ namespace GpgFrontend {
if (!gpgHint.isEmpty()) {
// remove UID, leave only username & email
gpgHint.remove(0, gpgHint.indexOf(" "));
- passwordDialogMessage += "<b>" + tr("Enter Password for") + "</b><br>" + gpgHint + "<br>";
+ passwordDialogMessage += "<b> Enter Password for </b><br>" + gpgHint + "<br>";
}
if (mPasswordCache.isEmpty()) {
- QString password = QInputDialog::getText(QApplication::activeWindow(), tr("Enter Password"),
+ QString password = QInputDialog::getText(QApplication::activeWindow(), "Enter Password",
passwordDialogMessage, QLineEdit::Password,
"", &result);
@@ -200,30 +200,7 @@ namespace GpgFrontend {
}
/** return type should be gpgme_error_t*/
- void
- GpgContext::executeGpgCommand(const QStringList &arguments, const std::function<void(QProcess *)> &interactFunc) {
- QEventLoop looper;
- auto dialog = new WaitingDialog(tr("Processing"), nullptr);
- dialog->show();
- auto *gpgProcess = new QProcess(&looper);
- gpgProcess->setProcessChannelMode(QProcess::MergedChannels);
- connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), &looper, &QEventLoop::quit);
- connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), dialog,
- &WaitingDialog::deleteLater);
- connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); });
- connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit);
- connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; });
- connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() {
- qDebug() << "Function Called";
- interactFunc(gpgProcess);
- });
- gpgProcess->setProgram(info.appPath);
- gpgProcess->setArguments(arguments);
- gpgProcess->start();
- looper.exec();
- dialog->close();
- }
/*
diff --git a/src/gpg/result_analyse/DecryptResultAnalyse.cpp b/src/gpg/result_analyse/DecryptResultAnalyse.cpp
index 7c91e6b2..351045c9 100644
--- a/src/gpg/result_analyse/DecryptResultAnalyse.cpp
+++ b/src/gpg/result_analyse/DecryptResultAnalyse.cpp
@@ -22,11 +22,12 @@
*
*/
+#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/DecryptResultAnalyse.h"
-DecryptResultAnalyse::DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result)
- : mCtx(ctx) {
+GpgFrontend::DecryptResultAnalyse::DecryptResultAnalyse(GpgError error, GpgDecrResult result) : error(error), result(std::move(result)) {}
+void GpgFrontend::DecryptResultAnalyse::do_analyse() {
stream << tr("[#] Decrypt Operation ");
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
@@ -51,25 +52,24 @@ DecryptResultAnalyse::DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_e
if (reci != nullptr)
stream << tr("Recipient(s): ") << Qt::endl;
while (reci != nullptr) {
- printReci(stream, reci);
+ print_reci(stream, reci);
reci = reci->next;
}
stream << "<------------" << Qt::endl;
}
stream << Qt::endl;
-
}
-bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci) {
+bool GpgFrontend::DecryptResultAnalyse::print_reci(QTextStream &stream, gpgme_recipient_t reci) {
bool keyFound = true;
stream << QApplication::tr(" {>} Recipient: ");
- auto key = mCtx->getKeyRefById(reci->keyid);
- if(key.good) {
- stream << key.name;
- if (!key.email.isEmpty()) {
- stream << "<" << key.email << ">";
+ auto key = GpgFrontend::GpgKeyGetter::getInstance().getKey(reci->keyid);
+ if(key.good()) {
+ stream << key.name().c_str();
+ if (!key.email().empty()) {
+ stream << "<" << key.email().c_str() << ">";
}
} else {
stream << "<Unknown>";
@@ -79,7 +79,7 @@ bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci
stream << Qt::endl;
- stream << tr(" Keu ID: ") << reci->keyid << Qt::endl;
+ stream << tr(" Keu ID: ") << key.id().c_str() << Qt::endl;
stream << tr(" Public Algo: ") << gpgme_pubkey_algo_name(reci->pubkey_algo) << Qt::endl;
return keyFound;
diff --git a/src/gpg/result_analyse/EncryptResultAnalyse.cpp b/src/gpg/result_analyse/EncryptResultAnalyse.cpp
index 1ba685c9..fd7faf59 100644
--- a/src/gpg/result_analyse/EncryptResultAnalyse.cpp
+++ b/src/gpg/result_analyse/EncryptResultAnalyse.cpp
@@ -24,8 +24,9 @@
#include "gpg/result_analyse/EncryptResultAnalyse.h"
-EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_result_t result) {
+GpgFrontend::EncryptResultAnalyse::EncryptResultAnalyse(GpgError error, GpgEncrResult result) : error(error), result(std::move(result)) {}
+void GpgFrontend::EncryptResultAnalyse::do_analyse() {
qDebug() << "Start Encrypt Result Analyse";
stream << "[#] Encrypt Operation ";
@@ -54,5 +55,4 @@ EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_re
}
stream << Qt::endl;
-
}
diff --git a/src/gpg/result_analyse/ResultAnalyse.cpp b/src/gpg/result_analyse/ResultAnalyse.cpp
index 7186d21a..b1f2cef9 100644
--- a/src/gpg/result_analyse/ResultAnalyse.cpp
+++ b/src/gpg/result_analyse/ResultAnalyse.cpp
@@ -24,15 +24,23 @@
#include "gpg/result_analyse/ResultAnalyse.h"
-const QString &ResultAnalyse::getResultReport() const{
+const QString &GpgFrontend::ResultAnalyse::getResultReport() {
+ if(!analysed_) do_analyse();
return resultText;
}
-int ResultAnalyse::getStatus() const {
+int GpgFrontend::ResultAnalyse::getStatus() {
+ if(!analysed_) do_analyse();
return status;
}
-void ResultAnalyse::setStatus(int mStatus) {
- if(mStatus < status)
- status = mStatus;
+void GpgFrontend::ResultAnalyse::setStatus(int mStatus) {
+ if(mStatus < status) status = mStatus;
+}
+
+void GpgFrontend::ResultAnalyse::analyse() {
+ if(!analysed_){
+ do_analyse();
+ analysed_ = true;
+ }
}
diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp
index efbbb4db..ff7cd029 100644
--- a/src/gpg/result_analyse/SignResultAnalyse.cpp
+++ b/src/gpg/result_analyse/SignResultAnalyse.cpp
@@ -22,10 +22,14 @@
*
*/
+#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/SignResultAnalyse.h"
-SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result) {
+GpgFrontend::SignResultAnalyse::SignResultAnalyse(GpgError error, GpgSignResult result) : error(error),
+ result(std::move(result)) {}
+
+void GpgFrontend::SignResultAnalyse::do_analyse() {
qDebug() << "Start Sign Result Analyse";
stream << tr("[#] Sign Operation ");
@@ -58,9 +62,9 @@ SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t
stream << Qt::endl;
- GpgKey singerKey = ctx->getKeyRefByFpr(new_sign->fpr);
- if(singerKey.good) {
- stream << tr(" Signer: ") << singerKey.uids.first().uid << Qt::endl;
+ auto singerKey = GpgFrontend::GpgKeyGetter::getInstance().getKey(new_sign->fpr);
+ if (singerKey.good()) {
+ stream << tr(" Signer: ") << singerKey.uids()->front().uid() << Qt::endl;
} else {
stream << tr(" Signer: ") << tr("<unknown>") << Qt::endl;
}
@@ -92,5 +96,4 @@ SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t
stream << "<------------" << Qt::endl;
}
-
-}
+} \ No newline at end of file
diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp
index e7c3276a..f794b31c 100644
--- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp
+++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp
@@ -26,8 +26,9 @@
#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/VerifyResultAnalyse.h"
-GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme_verify_result_t result) {
+GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(GpgError error, GpgVerifyResult result) : error(errror), result(std::move(result)) {}
+void GpgFrontend::VerifyResultAnalyse::do_analyse() {
qDebug() << "Verify Result Analyse Started";
stream << tr("[#] Verify Operation ");
@@ -64,81 +65,81 @@ GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme
canContinue = false;
setStatus(-1);
break;
- case GPG_ERR_NO_ERROR:
- stream << QApplication::tr("A ");
- if (sign->summary & GPGME_SIGSUM_GREEN) {
- stream << QApplication::tr("Good ");
- }
- if (sign->summary & GPGME_SIGSUM_RED) {
- stream << QApplication::tr("Bad ");
- }
- if (sign->summary & GPGME_SIGSUM_SIG_EXPIRED) {
- stream << QApplication::tr("Expired ");
- }
- if (sign->summary & GPGME_SIGSUM_KEY_MISSING) {
- stream << QApplication::tr("Missing Key's ");
- }
- if (sign->summary & GPGME_SIGSUM_KEY_REVOKED) {
- stream << QApplication::tr("Revoked Key's ");
- }
- if (sign->summary & GPGME_SIGSUM_KEY_EXPIRED) {
- stream << QApplication::tr("Expired Key's ");
- }
- if (sign->summary & GPGME_SIGSUM_CRL_MISSING) {
- stream << QApplication::tr("Missing CRL's ");
- }
-
- if (sign->summary & GPGME_SIGSUM_VALID) {
- stream << QApplication::tr("Signature Fully Valid.") << Qt::endl;
- } else {
- stream << QApplication::tr("Signature Not Fully Valid.") << Qt::endl;
- }
-
- if (!(sign->status & GPGME_SIGSUM_KEY_MISSING)) {
- if (!printSigner(stream, sign)) setStatus(0);
- } else {
- stream << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << Qt::endl;
- }
-
- setStatus(1);
-
- break;
- case GPG_ERR_NO_PUBKEY:
- stream << QApplication::tr("A signature could NOT be verified due to a Missing Key\n");
- setStatus(-1);
- break;
- case GPG_ERR_CERT_REVOKED:
- stream << QApplication::tr(
- "A signature is valid but the key used to verify the signature has been revoked\n");
- if (!printSigner(stream, sign)) {
- setStatus(0);
- }
- setStatus(-1);
- break;
- case GPG_ERR_SIG_EXPIRED:
- stream << QApplication::tr("A signature is valid but expired\n");
- if (!printSigner(stream, sign)) {
- setStatus(0);
- }
- setStatus(-1);
- break;
- case GPG_ERR_KEY_EXPIRED:
- stream << QApplication::tr(
- "A signature is valid but the key used to verify the signature has expired.\n");
- if (!printSigner(stream, sign)) {
- setStatus(0);
- }
- break;
- case GPG_ERR_GENERAL:
- stream << QApplication::tr(
- "There was some other error which prevented the signature verification.\n");
- status = -1;
- canContinue = false;
- break;
- default:
- stream << QApplication::tr("Error for key with fingerprint ") <<
- GpgFrontend::GpgContext::beautifyFingerprint(QString(sign->fpr));
- setStatus(-1);
+ case GPG_ERR_NO_ERROR:
+ stream << QApplication::tr("A ");
+ if (sign->summary & GPGME_SIGSUM_GREEN) {
+ stream << QApplication::tr("Good ");
+ }
+ if (sign->summary & GPGME_SIGSUM_RED) {
+ stream << QApplication::tr("Bad ");
+ }
+ if (sign->summary & GPGME_SIGSUM_SIG_EXPIRED) {
+ stream << QApplication::tr("Expired ");
+ }
+ if (sign->summary & GPGME_SIGSUM_KEY_MISSING) {
+ stream << QApplication::tr("Missing Key's ");
+ }
+ if (sign->summary & GPGME_SIGSUM_KEY_REVOKED) {
+ stream << QApplication::tr("Revoked Key's ");
+ }
+ if (sign->summary & GPGME_SIGSUM_KEY_EXPIRED) {
+ stream << QApplication::tr("Expired Key's ");
+ }
+ if (sign->summary & GPGME_SIGSUM_CRL_MISSING) {
+ stream << QApplication::tr("Missing CRL's ");
+ }
+
+ if (sign->summary & GPGME_SIGSUM_VALID) {
+ stream << QApplication::tr("Signature Fully Valid.") << Qt::endl;
+ } else {
+ stream << QApplication::tr("Signature Not Fully Valid.") << Qt::endl;
+ }
+
+ if (!(sign->status & GPGME_SIGSUM_KEY_MISSING)) {
+ if (!print_signer(stream, sign)) setStatus(0);
+ } else {
+ stream << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << Qt::endl;
+ }
+
+ setStatus(1);
+
+ break;
+ case GPG_ERR_NO_PUBKEY:
+ stream << QApplication::tr("A signature could NOT be verified due to a Missing Key\n");
+ setStatus(-1);
+ break;
+ case GPG_ERR_CERT_REVOKED:
+ stream << QApplication::tr(
+ "A signature is valid but the key used to verify the signature has been revoked\n");
+ if (!print_signer(stream, sign)) {
+ setStatus(0);
+ }
+ setStatus(-1);
+ break;
+ case GPG_ERR_SIG_EXPIRED:
+ stream << QApplication::tr("A signature is valid but expired\n");
+ if (!print_signer(stream, sign)) {
+ setStatus(0);
+ }
+ setStatus(-1);
+ break;
+ case GPG_ERR_KEY_EXPIRED:
+ stream << QApplication::tr(
+ "A signature is valid but the key used to verify the signature has expired.\n");
+ if (!print_signer(stream, sign)) {
+ setStatus(0);
+ }
+ break;
+ case GPG_ERR_GENERAL:
+ stream << QApplication::tr(
+ "There was some other error which prevented the signature verification.\n");
+ status = -1;
+ canContinue = false;
+ break;
+ default:
+ stream << QApplication::tr("Error for key with fingerprint ") <<
+ GpgFrontend::GpgContext::beautifyFingerprint(QString(sign->fpr));
+ setStatus(-1);
}
stream << Qt::endl;
sign = sign->next;
@@ -147,7 +148,8 @@ GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme
}
}
-bool GpgFrontend::VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sign) {
+
+bool GpgFrontend::VerifyResultAnalyse::print_signer(QTextStream &stream, gpgme_signature_t sign) {
bool keyFound = true;
auto key = GpgFrontend::GpgKeyGetter::getInstance().getKey(sign->fpr);
@@ -163,4 +165,5 @@ bool GpgFrontend::VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_si
stream << tr(" Date & Time: ") << QDateTime::fromTime_t(sign->timestamp).toString() << Qt::endl;
stream << Qt::endl;
return keyFound;
-} \ No newline at end of file
+}
+
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 00000000..ac16834d
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,19 @@
+enable_testing()
+
+find_package(GTest REQUIRED)
+
+aux_source_directory(. TEST_SOURCE)
+
+add_executable(
+ ${AppName}
+ ${TEST_SOURCE}
+)
+
+if(GPG_CORE)
+ target_link_libraries(${AppName} gpg_core)
+endif()
+
+target_link_libraries(${AppName} GTest::gtest GTest::gtest_main)
+
+
+add_test(AllTestsInGpgFrontend ${AppName}) \ No newline at end of file
diff --git a/test/GpgCoreTest.cpp b/test/GpgCoreTest.cpp
new file mode 100644
index 00000000..ecdd7279
--- /dev/null
+++ b/test/GpgCoreTest.cpp
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ *
+ */
+
+#include <gtest/gtest.h>
+
+// Demonstrate some basic assertions.
+TEST(HelloTest, GpgCoreTest) {
+ // Expect two strings not to be equal.
+ EXPECT_STRNE("hello", "world");
+ // Expect equality.
+ EXPECT_EQ(7 * 6, 42);
+}