aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-09 12:01:12 +0000
committersaturneric <[email protected]>2024-01-09 12:01:12 +0000
commit8d301459e56df7ca276bb902018b11758ed46fb6 (patch)
treeffe66da3b1a3560e2f6484644535626f09002c43
parentfix: slove an issue that adjusting information board's front size makes no sense (diff)
downloadGpgFrontend-8d301459e56df7ca276bb902018b11758ed46fb6.tar.gz
GpgFrontend-8d301459e56df7ca276bb902018b11758ed46fb6.zip
feat: improve basical opera-result-text structures and add more informations
-rw-r--r--src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp78
-rw-r--r--src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp28
-rw-r--r--src/core/function/result_analyse/GpgSignResultAnalyse.cpp54
-rw-r--r--src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp43
4 files changed, 125 insertions, 78 deletions
diff --git a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp
index a97e9871..6f79d442 100644
--- a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp
+++ b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp
@@ -38,38 +38,71 @@ GpgFrontend::GpgDecryptResultAnalyse::GpgDecryptResultAnalyse(
void GpgFrontend::GpgDecryptResultAnalyse::doAnalyse() {
auto *result = result_.GetRaw();
- stream_ << "[#] " << _("Decrypt Operation");
+ stream_ << "# " << _("Decrypt Operation") << " ";
if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) {
- stream_ << "[" << _("Success") << "]" << std::endl;
+ stream_ << "- " << _("Success") << " " << std::endl;
} else {
- stream_ << "[" << _("Failed") << "] " << gpgme_strerror(error_)
+ stream_ << "- " << _("Failed") << ": " << gpgme_strerror(error_)
<< std::endl;
setStatus(-1);
if (result != nullptr && result->unsupported_algorithm != nullptr) {
- stream_ << "------------>" << std::endl;
- stream_ << _("Unsupported Algo") << ": " << result->unsupported_algorithm
- << std::endl;
+ stream_ << std::endl;
+ stream_ << "## " << _("Unsupported Algo") << ": "
+ << result->unsupported_algorithm << std::endl;
}
}
if (result != nullptr && result->recipients != nullptr) {
- stream_ << "------------>" << std::endl;
+ stream_ << std::endl;
+
+ stream_ << "## " << _("Gernal State") << ": " << std::endl;
+
if (result->file_name != nullptr) {
- stream_ << _("File Name") << ": " << result->file_name << std::endl;
- stream_ << std::endl;
+ stream_ << "- " << _("File Name") << ": " << result->file_name
+ << std::endl;
+ }
+ stream_ << "- " << _("MIME") << ": "
+ << (result->is_mime == 0 ? _("false") : _("true")) << std::endl;
+
+ stream_ << "- " << _("Message Integrity Protection") << ": "
+ << (result->legacy_cipher_nomdc == 0 ? _("true") : _("false"))
+ << std::endl;
+ if (result->legacy_cipher_nomdc == 1) setStatus(0); /// < unsafe situation
+
+ if (result->symkey_algo != nullptr) {
+ stream_ << "- " << _("Symmetric Encryption Algorithm") << ": "
+ << result->symkey_algo << std::endl;
}
- if (result->is_mime) {
- stream_ << _("MIME") << ": " << _("true") << std::endl;
+
+ if (result->session_key != nullptr) {
+ stream_ << "- " << _("Session Key") << ": " << result->session_key
+ << std::endl;
}
+ stream_ << "- " << _("German Encryption Standards") << ": "
+ << (result->is_de_vs == 0 ? _("false") : _("true")) << std::endl;
+
+ stream_ << std::endl << std::endl;
+
auto *recipient = result->recipients;
- if (recipient != nullptr) stream_ << _("Recipient(s)") << ": " << std::endl;
+ auto index = 0;
+ if (recipient != nullptr) {
+ stream_ << "## " << _("Recipient(s)") << ": " << std::endl << std::endl;
+ }
+
while (recipient != nullptr) {
+ // check
+ if (recipient->keyid == nullptr) return;
+ stream_ << "### " << _("Recipient") << " [" << ++index << "]: ";
print_recipient(stream_, recipient);
+ stream_ << std::endl
+ << "---------------------------------------" << std::endl
+ << std::endl;
recipient = recipient->next;
}
- stream_ << "<------------" << std::endl;
+
+ stream_ << std::endl;
}
stream_ << std::endl;
@@ -77,24 +110,21 @@ void GpgFrontend::GpgDecryptResultAnalyse::doAnalyse() {
void GpgFrontend::GpgDecryptResultAnalyse::print_recipient(
std::stringstream &stream, gpgme_recipient_t recipient) {
- // check
- if (recipient->keyid == nullptr) return;
-
- stream << " {>} " << _("Recipient") << ": ";
auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(recipient->keyid);
if (key.IsGood()) {
- stream << key.GetName().c_str();
- if (!key.GetEmail().empty()) {
- stream << "<" << key.GetEmail().c_str() << ">";
- }
+ stream << key.GetName();
+ if (!key.GetComment().empty()) stream << "(" << key.GetComment() << ")";
+ if (!key.GetEmail().empty()) stream << "<" << key.GetEmail() << ">";
} else {
- stream << "<" << _("Unknown") << ">";
+ stream << "<" << _("unknown") << ">";
setStatus(0);
}
stream << std::endl;
- stream << " " << _("Key ID") << ": " << recipient->keyid << std::endl;
- stream << " " << _("Public Key Algo") << ": "
+ stream << "- " << _("Key ID") << ": " << recipient->keyid << std::endl;
+ stream << "- " << _("Public Key Algo") << ": "
<< gpgme_pubkey_algo_name(recipient->pubkey_algo) << std::endl;
+ stream << "- " << _("Status") << ": " << gpgme_strerror(recipient->status)
+ << std::endl;
}
diff --git a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
index 4bb0a5a9..201dfddb 100644
--- a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
+++ b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp
@@ -37,35 +37,41 @@ GpgFrontend::GpgEncryptResultAnalyse::GpgEncryptResultAnalyse(
: error_(error), result_(result) {}
void GpgFrontend::GpgEncryptResultAnalyse::doAnalyse() {
- GF_CORE_LOG_DEBUG("start encrypt result analyse");
-
- stream_ << "[#] " << _("Encrypt Operation") << " ";
+ stream_ << "# " << _("Encrypt Operation") << " ";
if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) {
- stream_ << "[" << _("Success") << "]" << std::endl;
+ stream_ << "- " << _("Success") << " " << std::endl;
} else {
- stream_ << "[" << _("Failed") << "] " << gpgme_strerror(error_)
+ stream_ << "- " << _("Failed") << ": " << gpgme_strerror(error_)
<< std::endl;
setStatus(-1);
}
if ((~status_) == 0) {
- stream_ << "------------>" << std::endl;
+ stream_ << std::endl;
const auto *result = result_.GetRaw();
+
if (result != nullptr) {
- stream_ << _("Invalid Recipients") << ": " << std::endl;
+ stream_ << "## " << _("Invalid Recipients") << ": " << std::endl
+ << std::endl;
+
auto *inv_reci = result->invalid_recipients;
+ auto index = 0;
+
while (inv_reci != nullptr) {
- stream_ << _("Fingerprint") << ": " << inv_reci->fpr << std::endl;
- stream_ << _("Reason") << ": " << gpgme_strerror(inv_reci->reason)
+ stream_ << "### " << _("Recipients") << " " << ++index << ": "
+ << std::endl;
+ stream_ << "- " << _("Fingerprint") << ": " << inv_reci->fpr
<< std::endl;
- stream_ << std::endl;
+ stream_ << "- " << _("Reason") << ": "
+ << gpgme_strerror(inv_reci->reason) << std::endl;
+ stream_ << std::endl << std::endl;
inv_reci = inv_reci->next;
}
}
- stream_ << "<------------" << std::endl;
+ stream_ << std::endl;
}
stream_ << std::endl;
diff --git a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp
index 2c53d329..efaceb1d 100644
--- a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp
+++ b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp
@@ -30,6 +30,7 @@
#include "core/GpgModel.h"
#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/utils/LocalizedUtils.h"
namespace GpgFrontend {
@@ -39,30 +40,27 @@ GpgSignResultAnalyse::GpgSignResultAnalyse(GpgError error, GpgSignResult result)
void GpgSignResultAnalyse::doAnalyse() {
auto *result = this->result_.GetRaw();
- GF_CORE_LOG_DEBUG("start sign result analyse");
-
- stream_ << "[#] " << _("Sign Operation") << " ";
+ stream_ << "# " << _("Sign Operation") << " ";
if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) {
- stream_ << "[" << _("Success") << "]" << std::endl;
+ stream_ << "- " << _("Success") << " " << std::endl;
} else {
- stream_ << "[" << _("Failed") << "] " << gpgme_strerror(error_)
+ stream_ << "- " << _("Failed") << " " << gpgme_strerror(error_)
<< std::endl;
setStatus(-1);
}
if (result != nullptr &&
(result->signatures != nullptr || result->invalid_signers != nullptr)) {
- GF_CORE_LOG_DEBUG("sign result analyse getting result");
- stream_ << "------------>" << std::endl;
+ stream_ << std::endl;
auto *new_sign = result->signatures;
+ auto index = 0;
while (new_sign != nullptr) {
- stream_ << "[>]" << _("New Signature") << ": " << std::endl;
-
- GF_CORE_LOG_DEBUG("signers fingerprint: ", new_sign->fpr);
+ stream_ << "## " << _("New Signature") << " [" << ++index
+ << "]: " << std::endl;
- stream_ << " " << _("Sign Mode") << ": ";
+ stream_ << "- " << _("Sign Mode") << ": ";
if (new_sign->type == GPGME_SIG_MODE_NORMAL) {
stream_ << _("Normal");
} else if (new_sign->type == GPGME_SIG_MODE_CLEAR) {
@@ -75,47 +73,53 @@ void GpgSignResultAnalyse::doAnalyse() {
auto singer_key = GpgKeyGetter::GetInstance().GetKey(new_sign->fpr);
if (singer_key.IsGood()) {
- stream_ << " " << _("Signer") << ": "
+ stream_ << "- " << _("Signer") << ": "
<< singer_key.GetUIDs()->front().GetUID() << std::endl;
} else {
- stream_ << " " << _("Signer") << ": "
+ stream_ << "- " << _("Signer") << ": "
<< "<unknown>" << std::endl;
}
- stream_ << " " << _("Public Key Algo") << ": "
+ stream_ << "- " << _("Public Key Algo") << ": "
<< gpgme_pubkey_algo_name(new_sign->pubkey_algo) << std::endl;
- stream_ << " " << _("Hash Algo") << ": "
+ stream_ << "- " << _("Hash Algo") << ": "
<< gpgme_hash_algo_name(new_sign->hash_algo) << std::endl;
- stream_ << " " << _("Date") << "(" << _("UTC") << ")"
+ stream_ << "- " << _("Date") << "(" << _("UTC") << ")"
<< ": "
<< boost::posix_time::to_iso_extended_string(
boost::posix_time::from_time_t(new_sign->timestamp))
<< std::endl;
+ stream_ << "- " << _("Date") << "(" << _("Localized") << ")"
+ << ": " << GetFormatedDateByTimestamp(new_sign->timestamp)
+ << std::endl;
- stream_ << std::endl;
+ stream_ << std::endl
+ << "---------------------------------------" << std::endl
+ << std::endl;
new_sign = new_sign->next;
}
- GF_CORE_LOG_DEBUG("sign result analyse getting invalid signer");
-
auto *invalid_signer = result->invalid_signers;
+ stream_ << std::endl;
if (invalid_signer != nullptr) {
- stream_ << _("Invalid Signers") << ": " << std::endl;
+ stream_ << "## " << _("Invalid Signers") << ": " << std::endl;
}
+ index = 0;
while (invalid_signer != nullptr) {
setStatus(0);
- stream_ << "[>] " << _("Signer") << ": " << std::endl;
- stream_ << " " << _("Fingerprint") << ": " << invalid_signer->fpr
+ stream_ << "### " << _("Signer") << " [" << ++index << "]: " << std::endl
<< std::endl;
- stream_ << " " << _("Reason") << ": "
+ stream_ << "- " << _("Fingerprint") << ": " << invalid_signer->fpr
+ << std::endl;
+ stream_ << "- " << _("Reason") << ": "
<< gpgme_strerror(invalid_signer->reason) << std::endl;
- stream_ << std::endl;
+ stream_ << "---------------------------------------" << std::endl;
invalid_signer = invalid_signer->next;
}
- stream_ << "<------------" << std::endl;
+ stream_ << std::endl;
}
}
diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp
index d497c094..cfd7f3f1 100644
--- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp
+++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp
@@ -31,10 +31,10 @@
#include <boost/format.hpp>
#include "GpgFrontend.h"
-#include "core/GpgConstants.h"
#include "core/GpgModel.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/utils/CommonUtils.h"
+#include "core/utils/LocalizedUtils.h"
GpgFrontend::GpgVerifyResultAnalyse::GpgVerifyResultAnalyse(
GpgError error, GpgVerifyResult result)
@@ -43,35 +43,39 @@ GpgFrontend::GpgVerifyResultAnalyse::GpgVerifyResultAnalyse(
void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() {
auto *result = this->result_.GetRaw();
- GF_CORE_LOG_DEBUG("started");
-
- stream_ << "[#] " << _("Verify Operation") << " ";
+ stream_ << "# " << _("Verify Operation") << " ";
if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) {
- stream_ << "[" << _("Success") << "]" << std::endl;
+ stream_ << " - " << _("Success") << " " << std::endl;
} else {
- stream_ << "[" << _("Failed") << "] " << gpgme_strerror(error_)
+ stream_ << " - " << _("Failed") << ": " << gpgme_strerror(error_)
<< std::endl;
setStatus(-1);
}
if (result != nullptr && result->signatures != nullptr) {
- stream_ << "------------>" << std::endl;
+ stream_ << std::endl;
auto *sign = result->signatures;
- stream_ << "[>] " << _("Signed On") << "(" << _("UTC") << ")"
+ stream_ << "-> " << _("Signed On") << "(" << _("UTC") << ")"
<< " "
<< boost::posix_time::to_iso_extended_string(
boost::posix_time::from_time_t(sign->timestamp))
<< std::endl;
- stream_ << std::endl << "[>] " << _("Signatures List") << ":" << std::endl;
+ stream_ << "-> " << _("Signed On") << "(" << _("Localized") << ")"
+ << " " << GetFormatedDateByTimestamp(sign->timestamp) << std::endl;
+
+ stream_ << std::endl << "## " << _("Signatures List") << ":" << std::endl;
+ stream_ << std::endl;
bool can_continue = true;
int count = 1;
while ((sign != nullptr) && can_continue) {
- stream_ << boost::format(_("Signature [%1%]:")) % count++ << std::endl;
+ stream_ << "### " << boost::format(_("Signature [%1%]:")) % count++
+ << std::endl;
+ stream_ << "- " << _("Status") << ": ";
switch (gpg_err_code(sign->status)) {
case GPG_ERR_BAD_SIGNATURE:
stream_ << _("A Bad Signature.") << std::endl;
@@ -167,10 +171,10 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() {
stream_ << std::endl;
sign = sign->next;
}
- stream_ << "<------------" << std::endl;
+ stream_ << std::endl;
} else {
stream_
- << "[>] "
+ << "-> "
<< _("Could not find information that can be used for verification.")
<< std::endl;
setStatus(0);
@@ -184,28 +188,31 @@ auto GpgFrontend::GpgVerifyResultAnalyse::print_signer(
auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(sign->fpr);
if (!key.IsGood()) {
- stream << " " << _("Signed By") << ": "
+ stream << "- " << _("Signed By") << ": "
<< "<" << _("Unknown") << ">" << std::endl;
setStatus(0);
key_found = false;
} else {
- stream << " " << _("Signed By") << ": "
- << key.GetUIDs()->front().GetUID() << std::endl;
+ stream << "- " << _("Signed By") << ": " << key.GetUIDs()->front().GetUID()
+ << std::endl;
}
if (sign->pubkey_algo != 0U) {
- stream << " " << _("Public Key Algo") << ": "
+ stream << "- " << _("Public Key Algo") << ": "
<< gpgme_pubkey_algo_name(sign->pubkey_algo) << std::endl;
}
if (sign->hash_algo != 0U) {
- stream << " " << _("Hash Algo") << ": "
+ stream << "- " << _("Hash Algo") << ": "
<< gpgme_hash_algo_name(sign->hash_algo) << std::endl;
}
if (sign->timestamp != 0U) {
- stream << " " << _("Date") << "(" << _("UTC") << ")"
+ stream << "- " << _("Date") << "(" << _("UTC") << ")"
<< ": "
<< boost::posix_time::to_iso_extended_string(
boost::posix_time::from_time_t(sign->timestamp))
<< std::endl;
+
+ stream << "- " << _("Date") << "(" << _("Localized") << ")"
+ << ": " << GetFormatedDateByTimestamp(sign->timestamp) << std::endl;
}
stream << std::endl;
return key_found;