aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-24 06:55:40 +0000
committersaturneric <[email protected]>2023-12-24 06:55:40 +0000
commit8f1844b23ea137e645800c8ed0ec5a50f33787fe (patch)
tree31ee73588483de365654f638478ccb7a11c0a188 /src
parentfix: test the initialization of gui application (diff)
downloadGpgFrontend-8f1844b23ea137e645800c8ed0ec5a50f33787fe.tar.gz
GpgFrontend-8f1844b23ea137e645800c8ed0ec5a50f33787fe.zip
fix: test the encrypt async api on gui app
Diffstat (limited to 'src')
-rw-r--r--src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp16
-rw-r--r--src/core/function/result_analyse/GpgEncryptResultAnalyse.h7
-rw-r--r--src/core/model/GFBuffer.cpp15
-rw-r--r--src/core/model/GFBuffer.h4
-rw-r--r--src/core/model/GpgEncryptResult.cpp4
-rw-r--r--src/core/model/GpgEncryptResult.h2
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp24
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp84
8 files changed, 93 insertions, 63 deletions
diff --git a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
index 9f523330..80ec6233 100644
--- a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
+++ b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
@@ -28,9 +28,13 @@
#include "GpgEncryptResultAnalyse.h"
+#include "core/model/GpgEncryptResult.h"
+
+namespace GpgFrontend {
+
GpgFrontend::GpgEncryptResultAnalyse::GpgEncryptResultAnalyse(
- GpgError error, GpgEncrResult result)
- : error_(error), result_(std::move(result)) {}
+ GpgError error, GpgEncryptResult result)
+ : error_(error), result_(result) {}
void GpgFrontend::GpgEncryptResultAnalyse::doAnalyse() {
SPDLOG_DEBUG("start encrypt result analyse");
@@ -47,9 +51,11 @@ void GpgFrontend::GpgEncryptResultAnalyse::doAnalyse() {
if ((~status_) == 0) {
stream_ << "------------>" << std::endl;
- if (result_ != nullptr) {
+
+ const auto *result = result_.GetRaw();
+ if (result != nullptr) {
stream_ << _("Invalid Recipients") << ": " << std::endl;
- auto *inv_reci = result_->invalid_recipients;
+ auto *inv_reci = result->invalid_recipients;
while (inv_reci != nullptr) {
stream_ << _("Fingerprint") << ": " << inv_reci->fpr << std::endl;
stream_ << _("Reason") << ": " << gpgme_strerror(inv_reci->reason)
@@ -64,3 +70,5 @@ void GpgFrontend::GpgEncryptResultAnalyse::doAnalyse() {
stream_ << std::endl;
}
+
+} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/function/result_analyse/GpgEncryptResultAnalyse.h b/src/core/function/result_analyse/GpgEncryptResultAnalyse.h
index 13f0a3b6..221a4c22 100644
--- a/src/core/function/result_analyse/GpgEncryptResultAnalyse.h
+++ b/src/core/function/result_analyse/GpgEncryptResultAnalyse.h
@@ -29,6 +29,7 @@
#pragma once
#include "GpgResultAnalyse.h"
+#include "core/model/GpgEncryptResult.h"
namespace GpgFrontend {
/**
@@ -44,7 +45,7 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResultAnalyse
* @param error
* @param result
*/
- explicit GpgEncryptResultAnalyse(GpgError error, GpgEncrResult result);
+ explicit GpgEncryptResultAnalyse(GpgError error, GpgEncryptResult result);
protected:
/**
@@ -54,7 +55,7 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResultAnalyse
void doAnalyse() final;
private:
- GpgError error_; ///<
- GpgEncrResult result_; ///<
+ GpgError error_; ///<
+ GpgEncryptResult result_; ///<
};
} // namespace GpgFrontend
diff --git a/src/core/model/GFBuffer.cpp b/src/core/model/GFBuffer.cpp
index 99154bdd..379873c1 100644
--- a/src/core/model/GFBuffer.cpp
+++ b/src/core/model/GFBuffer.cpp
@@ -35,7 +35,7 @@ GFBuffer::GFBuffer()
GFBuffer::GFBuffer(const std::string& str)
: buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) {
- std::transform(str.begin(), str.end(), buffer_->begin(),
+ std::transform(str.begin(), str.end(), std::back_inserter(*buffer_),
[](const char c) { return static_cast<std::byte>(c); });
}
@@ -53,10 +53,17 @@ GFBuffer::GFBuffer(const char* c_str)
GFBuffer::GFBuffer(QByteArray buffer)
: buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) {
- std::transform(buffer.begin(), buffer.end(), buffer_->begin(),
+ std::transform(buffer.begin(), buffer.end(), std::back_inserter(*buffer_),
[](const char c) { return static_cast<std::byte>(c); });
}
+GFBuffer::GFBuffer(QString str)
+ : buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) {
+ std::transform(
+ str.begin(), str.end(), std::back_inserter(*buffer_),
+ [](const QChar c) { return static_cast<std::byte>(c.unicode()); });
+}
+
auto GFBuffer::operator==(const GFBuffer& o) const -> bool {
return equal(buffer_->begin(), buffer_->end(), o.buffer_->begin());
}
@@ -67,4 +74,8 @@ void GFBuffer::Resize(size_t size) { buffer_->resize(size); }
auto GFBuffer::Size() -> size_t { return buffer_->size(); }
+auto GFBuffer::ConvertToQByteArray() -> QByteArray {
+ return QByteArray::fromRawData(reinterpret_cast<const char*>(Data()),
+ static_cast<qsizetype>(Size()));
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/model/GFBuffer.h b/src/core/model/GFBuffer.h
index 297c5fc7..cc233e86 100644
--- a/src/core/model/GFBuffer.h
+++ b/src/core/model/GFBuffer.h
@@ -43,6 +43,8 @@ class GPGFRONTEND_CORE_EXPORT GFBuffer {
explicit GFBuffer(QByteArray buffer);
+ explicit GFBuffer(QString str);
+
auto operator==(const GFBuffer& o) const -> bool;
auto Data() -> std::byte*;
@@ -51,6 +53,8 @@ class GPGFRONTEND_CORE_EXPORT GFBuffer {
auto Size() -> size_t;
+ auto ConvertToQByteArray() -> QByteArray;
+
private:
std::shared_ptr<std::vector<std::byte>> buffer_;
};
diff --git a/src/core/model/GpgEncryptResult.cpp b/src/core/model/GpgEncryptResult.cpp
index 9228d3e1..821b10d5 100644
--- a/src/core/model/GpgEncryptResult.cpp
+++ b/src/core/model/GpgEncryptResult.cpp
@@ -58,4 +58,8 @@ auto GpgEncryptResult::InvalidRecipients()
}
return result;
}
+
+auto GpgEncryptResult::GetRaw() -> gpgme_encrypt_result_t {
+ return result_ref_.get();
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/model/GpgEncryptResult.h b/src/core/model/GpgEncryptResult.h
index 56484f49..c5c01228 100644
--- a/src/core/model/GpgEncryptResult.h
+++ b/src/core/model/GpgEncryptResult.h
@@ -38,6 +38,8 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResult {
auto InvalidRecipients() -> std::vector<std::tuple<std::string, GpgError>>;
+ auto GetRaw() -> gpgme_encrypt_result_t;
+
explicit GpgEncryptResult(gpgme_encrypt_result_t);
GpgEncryptResult();
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index 444cc224..fc9401c8 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -278,10 +278,10 @@ void MainWindow::SlotFileEncrypt() {
}
if (!if_error) {
- auto resultAnalyse = GpgEncryptResultAnalyse(error, std::move(result));
- resultAnalyse.Analyse();
- process_result_analyse(edit_, info_board_, resultAnalyse);
- fileTreeView->update();
+ // auto resultAnalyse = GpgEncryptResultAnalyse(error, std::move(result));
+ // resultAnalyse.Analyse();
+ // process_result_analyse(edit_, info_board_, resultAnalyse);
+ // fileTreeView->update();
} else {
QMessageBox::critical(this, _("Error"),
_("An error occurred during operation."));
@@ -641,14 +641,14 @@ void MainWindow::SlotFileEncryptSign() {
});
if (!if_error) {
- auto encrypt_result =
- GpgEncryptResultAnalyse(error, std::move(encr_result));
- auto sign_res = GpgSignResultAnalyse(error, std::move(sign_result));
- encrypt_result.Analyse();
- sign_res.Analyse();
- process_result_analyse(edit_, info_board_, encrypt_result, sign_res);
-
- file_tree_view->update();
+ // auto encrypt_result =
+ // GpgEncryptResultAnalyse(error, std::move(encr_result));
+ // auto sign_res = GpgSignResultAnalyse(error, std::move(sign_result));
+ // encrypt_result.Analyse();
+ // sign_res.Analyse();
+ // process_result_analyse(edit_, info_board_, encrypt_result, sign_res);
+
+ // file_tree_view->update();
} else {
QMessageBox::critical(this, _("Error"),
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 0ef8c9e2..1c7633b4 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -41,6 +41,7 @@
#include "core/function/result_analyse/GpgSignResultAnalyse.h"
#include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
#include "core/model/DataObject.h"
+#include "core/model/GpgEncryptResult.h"
#include "core/module/ModuleManager.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/CommonUtils.h"
@@ -65,8 +66,6 @@ void MainWindow::slot_encrypt() {
}
auto key_ids = m_key_list_->GetChecked();
- auto buffer = GFBuffer(
- edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString());
if (key_ids->empty()) {
// Symmetric Encrypt
@@ -99,10 +98,11 @@ void MainWindow::slot_encrypt() {
// return 0;
// };
+ auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
// CommonUtils::WaitForOpera(
// this, _("Symmetrically Encrypting"),
- // [this, keys, buffer](const OperaWaitingHd& hd) {
- // GpgFrontend::GpgBasicOperator::GetInstance().Encrypt(
+ // [this, buffer](const OperaWaitingHd& hd) {
+ // GpgFrontend::GpgBasicOperator::GetInstance().EncryptSymmetric(
// std::move(keys), buffer.toStdString(),
// [this, hd](GpgError err, const DataObjectPtr& data_obj) {
// auto result = ExtractParams<GpgEncrResult>(data_obj, 0);
@@ -123,45 +123,45 @@ void MainWindow::slot_encrypt() {
// });
// });
- } else {
- auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
- for (const auto& key : *keys) {
- if (!key.IsHasActualEncryptionCapability()) {
- QMessageBox::information(
- this, _("Invalid Operation"),
- QString(_(
- "The selected key contains a key that does not actually have a "
+ return;
+ }
+
+ auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
+ for (const auto& key : *keys) {
+ if (!key.IsHasActualEncryptionCapability()) {
+ QMessageBox::information(
+ this, _("Invalid Operation"),
+ QString(
+ _("The selected key contains a key that does not actually have a "
"encrypt usage.")) +
- "<br/><br/>" + _("For example the Following Key:") + " <br/>" +
- QString::fromStdString(key.GetUIDs()->front().GetUID()));
- return;
- }
+ "<br/><br/>" + _("For example the Following Key:") + " <br/>" +
+ QString::fromStdString(key.GetUIDs()->front().GetUID()));
+ return;
}
-
- CommonUtils::WaitForOpera(
- this, _("Encrypting"), [this, keys, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().Encrypt(
- {keys->begin(), keys->end()}, buffer, true,
- [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- auto result = ExtractParams<GpgEncrResult>(data_obj, 0);
- auto buffer = ExtractParams<ByteArrayPtr>(data_obj, 1);
-
- auto result_analyse =
- GpgEncryptResultAnalyse(err, std::move(result));
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(
- QString::fromStdString(*buffer));
- }
- info_board_->ResetOptionActionsMenu();
-
- // stop waiting
- hd();
- });
- });
}
+
+ auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ CommonUtils::WaitForOpera(
+ this, _("Encrypting"), [this, keys, buffer](const OperaWaitingHd& hd) {
+ GpgFrontend::GpgBasicOperator::GetInstance().Encrypt(
+ {keys->begin(), keys->end()}, buffer, true,
+ [this, hd](GpgError err, const DataObjectPtr& data_obj) {
+ // stop waiting
+ hd();
+
+ auto result = ExtractParams<GpgEncryptResult>(data_obj, 0);
+ auto buffer = ExtractParams<GFBuffer>(data_obj, 1);
+
+ auto result_analyse = GpgEncryptResultAnalyse(err, result);
+ result_analyse.Analyse();
+ process_result_analyse(edit_, info_board_, result_analyse);
+
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
+ edit_->SlotFillTextEditWithText(buffer.ConvertToQByteArray());
+ }
+ info_board_->ResetOptionActionsMenu();
+ });
+ });
}
void MainWindow::slot_sign() {
@@ -463,8 +463,8 @@ void MainWindow::slot_encrypt_sign() {
auto sign_result = ExtractParams<GpgSignResult>(data_object, 2);
auto tmp = ExtractParams<ByteArrayPtr>(data_object, 3);
- auto encrypt_result_analyse =
- GpgEncryptResultAnalyse(error, std::move(encrypt_result));
+ auto encrypt_result_analyse = GpgEncryptResultAnalyse(
+ error, GpgEncryptResult(encrypt_result.get()));
auto sign_result_analyse =
GpgSignResultAnalyse(error, std::move(sign_result));
encrypt_result_analyse.Analyse();