aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-01-02 03:40:22 +0000
committerSaturneric <[email protected]>2022-01-02 03:40:22 +0000
commita056f2186de2470d4328bd1cd682e5e484af4587 (patch)
tree27775ca169ad93fc812e94a4da99ebd3fa1c53f9
parent<refactor, test>(core, test): test decryption when key not found (diff)
downloadGpgFrontend-a056f2186de2470d4328bd1cd682e5e484af4587.tar.gz
GpgFrontend-a056f2186de2470d4328bd1cd682e5e484af4587.zip
<refactor, fixed, test>(core, ui): add & modify core and ui
1. add init functions for core. 2. add non ascii settings. 3. fit ui with this version of core.
-rw-r--r--src/gpg/GpgConstants.h5
-rw-r--r--src/gpg/GpgContext.cpp11
-rw-r--r--src/gpg/GpgContext.h1
-rw-r--r--src/gpg/GpgCoreInit.cpp52
-rw-r--r--src/gpg/GpgCoreInit.h40
-rw-r--r--src/gpg/GpgFunctionObject.h8
-rw-r--r--src/gpg/GpgInfo.h2
-rwxr-xr-xsrc/ui/KeyMgmt.cpp6
-rw-r--r--src/ui/KeyServerImportDialog.cpp2
-rw-r--r--src/ui/KeyUploadDialog.cpp2
-rw-r--r--src/ui/UserInterfaceUtils.cpp4
-rw-r--r--src/ui/function/CtxCheckThread.cpp4
-rw-r--r--src/ui/help/AboutDialog.cpp4
-rw-r--r--src/ui/keygen/KeygenDialog.cpp18
-rw-r--r--src/ui/keygen/SubkeyGenerateDialog.cpp4
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp6
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp2
-rw-r--r--src/ui/widgets/KeyList.cpp5
18 files changed, 145 insertions, 31 deletions
diff --git a/src/gpg/GpgConstants.h b/src/gpg/GpgConstants.h
index 3c0240d2..e8b64694 100644
--- a/src/gpg/GpgConstants.h
+++ b/src/gpg/GpgConstants.h
@@ -87,6 +87,10 @@ std::string get_only_file_name_with_path(const std::string& path);
// Check
int text_is_signed(BypeArrayRef text);
+// Channels
+const int GPGFRONTEND_DEFAULT_CHANNEL = 0;
+const int GPGFRONTEND_NON_ASCII_CHANNEL = 2;
+
class GpgConstants {
public:
static const char* PGP_CRYPT_BEGIN;
@@ -97,6 +101,7 @@ class GpgConstants {
static const char* PGP_SIGNATURE_END;
static const char* GPG_FRONTEND_SHORT_CRYPTO_HEAD;
};
+
} // namespace GpgFrontend
#endif // GPG_CONSTANTS_H
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index ff483637..8ecb7b87 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -49,7 +49,7 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) {
if (_first) {
/* Initialize the locale environment. */
LOG(INFO) << "locale" << setlocale(LC_CTYPE, nullptr);
- gpgme_check_version(nullptr);
+ info_.GpgMEVersion = gpgme_check_version(nullptr);
gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr));
#ifdef LC_MESSAGES
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
@@ -148,9 +148,12 @@ void GpgContext::init_ctx() {
info_.DatabasePath = "default";
}
- /** Setting the output type must be done at the beginning */
- /** think this means ascii-armor --> ? */
- gpgme_set_armor(*this, 1);
+ if (args_.ascii) {
+ /** Setting the output type must be done at the beginning */
+ /** think this means ascii-armor --> ? */
+ gpgme_set_armor(*this, 1);
+ }
+
// Speed up loading process
gpgme_set_offline(*this, 1);
diff --git a/src/gpg/GpgContext.h b/src/gpg/GpgContext.h
index 753e1090..146f0794 100644
--- a/src/gpg/GpgContext.h
+++ b/src/gpg/GpgContext.h
@@ -39,6 +39,7 @@ struct GpgContextInitArgs {
bool gpg_alone = false;
std::string gpg_path = {};
bool test_mode = false;
+ bool ascii = true;
GpgContextInitArgs() = default;
};
diff --git a/src/gpg/GpgCoreInit.cpp b/src/gpg/GpgCoreInit.cpp
new file mode 100644
index 00000000..3f07d2b1
--- /dev/null
+++ b/src/gpg/GpgCoreInit.cpp
@@ -0,0 +1,52 @@
+/**
+ * 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 "GpgCoreInit.h"
+
+#include "GpgContext.h"
+
+void GpgFrontend::init_gpgfrontend_core() {
+ GpgFrontend::GpgContext::CreateInstance(
+ GPGFRONTEND_DEFAULT_CHANNEL,
+ [&]() -> std::unique_ptr<GpgFrontend::GpgContext> {
+ GpgFrontend::GpgContextInitArgs args;
+ return std::make_unique<GpgFrontend::GpgContext>(args);
+ });
+
+ GpgFrontend::GpgContext::CreateInstance(
+ GPGFRONTEND_NON_ASCII_CHANNEL,
+ [&]() -> std::unique_ptr<GpgFrontend::GpgContext> {
+ GpgFrontend::GpgContextInitArgs args;
+ args.ascii = false;
+ return std::make_unique<GpgFrontend::GpgContext>(args);
+ });
+}
+
+void GpgFrontend::new_default_settings_channel(int channel) {
+ GpgFrontend::GpgContext::CreateInstance(
+ channel, [&]() -> std::unique_ptr<GpgFrontend::GpgContext> {
+ GpgFrontend::GpgContextInitArgs args;
+ return std::make_unique<GpgFrontend::GpgContext>(args);
+ });
+} \ No newline at end of file
diff --git a/src/gpg/GpgCoreInit.h b/src/gpg/GpgCoreInit.h
new file mode 100644
index 00000000..577f46a3
--- /dev/null
+++ b/src/gpg/GpgCoreInit.h
@@ -0,0 +1,40 @@
+/**
+ * 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_GPGCOREINIT_H
+#define GPGFRONTEND_GPGCOREINIT_H
+
+#include "GpgConstants.h"
+
+namespace GpgFrontend {
+
+// Init
+void init_gpgfrontend_core();
+
+void new_default_settings_channel(
+ int channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL);
+
+} // namespace GpgFrontend
+
+#endif // GPGFRONTEND_GPGCOREINIT_H
diff --git a/src/gpg/GpgFunctionObject.h b/src/gpg/GpgFunctionObject.h
index d81371d9..404b2f84 100644
--- a/src/gpg/GpgFunctionObject.h
+++ b/src/gpg/GpgFunctionObject.h
@@ -34,12 +34,15 @@
#include <stdexcept>
#include <string>
+#include "GpgConstants.h"
+
namespace GpgFrontend {
template <typename T>
class SingletonFunctionObject {
public:
- static T& GetInstance(int channel = 0) {
+ static T& GetInstance(
+ int channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {
static_assert(std::is_base_of<SingletonFunctionObject<T>, T>::value,
"T not derived from SingletonFunctionObject<T>");
@@ -138,7 +141,8 @@ class SingletonFunctionObject {
};
template <typename T>
-int SingletonFunctionObject<T>::_default_channel = 0;
+int SingletonFunctionObject<T>::_default_channel =
+ GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL;
template <typename T>
std::mutex SingletonFunctionObject<T>::_instance_mutex;
diff --git a/src/gpg/GpgInfo.h b/src/gpg/GpgInfo.h
index d651b2f6..67ac55d6 100644
--- a/src/gpg/GpgInfo.h
+++ b/src/gpg/GpgInfo.h
@@ -44,6 +44,8 @@ class GpgInfo {
std::string GpgConfPath;
std::string CMSPath;
+
+ std::string GpgMEVersion;
};
#endif // GPGFRONTEND_ZH_CN_TS_GPGINFO_H
diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp
index 9f599461..8036b120 100755
--- a/src/ui/KeyMgmt.cpp
+++ b/src/ui/KeyMgmt.cpp
@@ -352,7 +352,7 @@ void KeyMgmt::slotShowKeyDetails() {
void KeyMgmt::slotExportKeyToFile() {
ByteArrayPtr key_export_data = nullptr;
auto keys_checked = mKeyList->getChecked();
- if (!GpgKeyImportExportor::GetInstance().ExportKeys(keys_checked,
+ if (!GpgKeyImportExporter::GetInstance().ExportKeys(keys_checked,
key_export_data)) {
return;
}
@@ -377,7 +377,7 @@ void KeyMgmt::slotExportKeyToFile() {
void KeyMgmt::slotExportKeyToClipboard() {
ByteArrayPtr key_export_data = nullptr;
auto keys_checked = mKeyList->getChecked();
- if (!GpgKeyImportExportor::GetInstance().ExportKeys(keys_checked,
+ if (!GpgKeyImportExporter::GetInstance().ExportKeys(keys_checked,
key_export_data)) {
return;
}
@@ -474,7 +474,7 @@ void KeyMgmt::slotExportAsOpenSSHFormat() {
}
auto key = GpgKeyGetter::GetInstance().GetKey(keys_checked->front());
- if (!GpgKeyImportExportor::GetInstance().ExportKeyOpenSSH(key,
+ if (!GpgKeyImportExporter::GetInstance().ExportKeyOpenSSH(key,
key_export_data)) {
QMessageBox::critical(nullptr, _("Error"),
_("An error occur in exporting."));
diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp
index 518b1b94..5bad29f1 100644
--- a/src/ui/KeyServerImportDialog.cpp
+++ b/src/ui/KeyServerImportDialog.cpp
@@ -503,7 +503,7 @@ void KeyServerImportDialog::slotImportFinished(QString keyid) {
void KeyServerImportDialog::importKeys(ByteArrayPtr in_data) {
GpgImportInformation result =
- GpgKeyImportExportor::GetInstance().ImportKey(std::move(in_data));
+ GpgKeyImportExporter::GetInstance().ImportKey(std::move(in_data));
emit signalKeyImported();
QWidget* _parent = qobject_cast<QWidget*>(parent());
if (mAutomatic) {
diff --git a/src/ui/KeyUploadDialog.cpp b/src/ui/KeyUploadDialog.cpp
index ab4e139e..d2b8c0bf 100644
--- a/src/ui/KeyUploadDialog.cpp
+++ b/src/ui/KeyUploadDialog.cpp
@@ -53,7 +53,7 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids,
void KeyUploadDialog::slotUpload() {
auto out_data = std::make_unique<ByteArray>();
- GpgKeyImportExportor::GetInstance().ExportKeys(*mKeys, out_data);
+ GpgKeyImportExporter::GetInstance().ExportKeys(*mKeys, out_data);
uploadKeyToServer(*out_data);
}
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 581eabda..f7f5cb82 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -164,7 +164,7 @@ CommonUtils::CommonUtils() : QWidget(nullptr) {
void CommonUtils::slotImportKeys(QWidget* parent,
const std::string& in_buffer) {
- GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey(
+ GpgImportInformation result = GpgKeyImportExporter::GetInstance().ImportKey(
std::make_unique<ByteArray>(in_buffer));
emit signalKeyStatusUpdated();
new KeyImportDetailDialog(result, false, parent);
@@ -309,7 +309,7 @@ void CommonUtils::slotImportKeyFromKeyServer(
// Try importing
GpgImportInformation result =
- GpgKeyImportExportor::GetInstance(ctx_channel)
+ GpgKeyImportExporter::GetInstance(ctx_channel)
.ImportKey(std::move(key_data_ptr));
if (result.imported == 1) {
diff --git a/src/ui/function/CtxCheckThread.cpp b/src/ui/function/CtxCheckThread.cpp
index cd184910..b51954e1 100644
--- a/src/ui/function/CtxCheckThread.cpp
+++ b/src/ui/function/CtxCheckThread.cpp
@@ -25,6 +25,7 @@
#include "CtxCheckThread.h"
#include "gpg/GpgContext.h"
+#include "gpg/GpgCoreInit.h"
#include "gpg/function/GpgKeyGetter.h"
#include "ui/UserInterfaceUtils.h"
@@ -34,6 +35,9 @@ GpgFrontend::UI::CtxCheckThread::CtxCheckThread() : QThread(nullptr) {
}
void GpgFrontend::UI::CtxCheckThread::run() {
+ // Init GpgFrontend Core
+ init_gpgfrontend_core();
+
// Create & Check Gnupg Context Status
if (!GpgContext::GetInstance().good()) {
emit signalGnupgNotInstall();
diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/help/AboutDialog.cpp
index 93e7ccb3..5ee90e23 100644
--- a/src/ui/help/AboutDialog.cpp
+++ b/src/ui/help/AboutDialog.cpp
@@ -86,8 +86,8 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) {
_("or send a mail to my mailing list at") + " <a " +
"href=\"mailto:[email protected]\">[email protected]</a>." + "<br><br> " +
_("Built with Qt") + " " + qVersion() + " " + _("and GPGME") + " " +
- GpgFrontend::GpgContext::getGpgmeVersion().c_str() + "<br>" +
- _("Built at") + " " + BUILD_TIMESTAMP + "</center>");
+ GpgFrontend::GpgContext::GetInstance().GetInfo().GpgMEVersion.c_str() +
+ "<br>" + _("Built at") + " " + BUILD_TIMESTAMP + "</center>");
auto* layout = new QGridLayout();
auto* pixmapLabel = new QLabel();
diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/keygen/KeygenDialog.cpp
index 98ea1d5c..af9aa4e4 100644
--- a/src/ui/keygen/KeygenDialog.cpp
+++ b/src/ui/keygen/KeygenDialog.cpp
@@ -94,11 +94,9 @@ void KeyGenDialog::slotKeyGenAccept() {
/**
* create the string for key generation
*/
-
- genKeyInfo->setUserid(
- QString("%1(%3)<%2>")
- .arg(nameEdit->text(), emailEdit->text(), commentEdit->text())
- .toStdString());
+ genKeyInfo->setName(nameEdit->text().toStdString());
+ genKeyInfo->setEmail(emailEdit->text().toStdString());
+ genKeyInfo->setComment(commentEdit->text().toStdString());
genKeyInfo->setKeySize(keySizeSpinBox->value());
@@ -109,9 +107,11 @@ void KeyGenDialog::slotKeyGenAccept() {
boost::posix_time::from_time_t(dateEdit->dateTime().toTime_t()));
}
+ GpgGenKeyResult result;
gpgme_error_t error = false;
- auto thread = QThread::create(
- [&]() { error = GpgKeyOpera::GetInstance().GenerateKey(genKeyInfo); });
+ auto thread = QThread::create([&]() {
+ error = GpgKeyOpera::GetInstance().GenerateKey(genKeyInfo, result);
+ });
thread->start();
auto* dialog = new WaitingDialog(_("Generating"), this);
@@ -327,10 +327,10 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
keySizeSpinBox = new QSpinBox(this);
keyTypeComboBox = new QComboBox(this);
- for (auto& algo : GenKeyInfo::SupportedKeyAlgo) {
+ for (auto& algo : GenKeyInfo::getSupportedKeyAlgo()) {
keyTypeComboBox->addItem(QString::fromStdString(algo));
}
- if (!GenKeyInfo::SupportedKeyAlgo.empty()) {
+ if (!GenKeyInfo::getSupportedKeyAlgo().empty()) {
keyTypeComboBox->setCurrentIndex(0);
}
diff --git a/src/ui/keygen/SubkeyGenerateDialog.cpp b/src/ui/keygen/SubkeyGenerateDialog.cpp
index 9bac076e..337b545f 100644
--- a/src/ui/keygen/SubkeyGenerateDialog.cpp
+++ b/src/ui/keygen/SubkeyGenerateDialog.cpp
@@ -99,10 +99,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
keySizeSpinBox = new QSpinBox(this);
keyTypeComboBox = new QComboBox(this);
- for (auto& algo : GenKeyInfo::SupportedSubkeyAlgo) {
+ for (auto& algo : GenKeyInfo::getSupportedKeyAlgo()) {
keyTypeComboBox->addItem(QString::fromStdString(algo));
}
- if (!GenKeyInfo::SupportedKeyAlgo.empty()) {
+ if (!GenKeyInfo::getSupportedKeyAlgo().empty()) {
keyTypeComboBox->setCurrentIndex(0);
}
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index 8b5be042..7f48b3f8 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -220,7 +220,7 @@ KeyPairDetailTab::KeyPairDetailTab(const std::string& key_id, QWidget* parent)
void KeyPairDetailTab::slotExportPublicKey() {
ByteArrayPtr keyArray = nullptr;
- if (!GpgKeyImportExportor::GetInstance().ExportKey(mKey, keyArray)) {
+ if (!GpgKeyImportExporter::GetInstance().ExportKey(mKey, keyArray)) {
QMessageBox::critical(this, _("Error"),
_("An error occurred during the export operation."));
return;
@@ -261,7 +261,7 @@ void KeyPairDetailTab::slotExportShortPrivateKey() {
if (ret == QMessageBox::Ok) {
ByteArrayPtr keyArray = nullptr;
- if (!GpgKeyImportExportor::GetInstance().ExportSecretKeyShortest(
+ if (!GpgKeyImportExporter::GetInstance().ExportSecretKeyShortest(
mKey, keyArray)) {
QMessageBox::critical(
this, _("Error"),
@@ -301,7 +301,7 @@ void KeyPairDetailTab::slotExportPrivateKey() {
if (ret == QMessageBox::Ok) {
ByteArrayPtr keyArray = nullptr;
- if (!GpgKeyImportExportor::GetInstance().ExportSecretKey(mKey, keyArray)) {
+ if (!GpgKeyImportExporter::GetInstance().ExportSecretKey(mKey, keyArray)) {
QMessageBox::critical(
this, _("Error"),
_("An error occurred during the export operation."));
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 5671d943..9dd3e5cf 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -448,7 +448,7 @@ void MainWindow::slotAppendSelectedKeys() {
auto exported = std::make_unique<ByteArray>();
auto key_ids = mKeyList->getSelected();
- GpgKeyImportExportor::GetInstance().ExportKeys(key_ids, exported);
+ GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported);
edit->curTextPage()->append(QString::fromStdString(*exported));
}
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index 464727dc..3b13196f 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -27,6 +27,7 @@
#include <boost/format.hpp>
#include <utility>
+#include "gpg/GpgCoreInit.h"
#include "gpg/function/GpgKeyGetter.h"
#include "ui/SignalStation.h"
#include "ui/UserInterfaceUtils.h"
@@ -55,6 +56,8 @@ void KeyList::init() {
GpgContext::CreateInstance(
_m_key_list_id, std::make_unique<GpgContext>(true, db_path.string(), true,
gpg_path.string()));
+#else
+ new_default_settings_channel(_m_key_list_id);
#endif
ui->setupUi(this);
@@ -375,7 +378,7 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) {
void KeyList::importKeys(const QByteArray& inBuffer) {
auto std_buffer = std::make_unique<ByteArray>(inBuffer.toStdString());
GpgImportInformation result =
- GpgKeyImportExportor::GetInstance(_m_key_list_id)
+ GpgKeyImportExporter::GetInstance(_m_key_list_id)
.ImportKey(std::move(std_buffer));
new KeyImportDetailDialog(result, false, this);
}