diff options
Diffstat (limited to 'src/core/function/result_analyse')
3 files changed, 62 insertions, 68 deletions
diff --git a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp index f84e9b85..1fcda489 100644 --- a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp @@ -28,8 +28,7 @@ #include "GpgDecryptResultAnalyse.h" -#include "core/GpgModel.h" -#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgAbstractKeyGetter.h" GpgFrontend::GpgDecryptResultAnalyse::GpgDecryptResultAnalyse( int channel, GpgError m_error, GpgDecryptResult m_result) @@ -107,12 +106,13 @@ void GpgFrontend::GpgDecryptResultAnalyse::doAnalyse() { void GpgFrontend::GpgDecryptResultAnalyse::print_recipient( QTextStream &stream, gpgme_recipient_t recipient) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(GetChannel()) - .GetKey(recipient->keyid); - if (key.IsGood()) { - stream << key.Name(); - if (!key.Comment().isEmpty()) stream << "(" << key.Comment() << ")"; - if (!key.Email().isEmpty()) stream << "<" << key.Email() << ">"; + auto key = + GpgAbstractKeyGetter::GetInstance(GetChannel()).GetKey(recipient->keyid); + + if (key != nullptr) { + stream << key->Name(); + if (!key->Comment().isEmpty()) stream << "(" << key->Comment() << ")"; + if (!key->Email().isEmpty()) stream << "<" << key->Email() << ">"; } else { stream << "<" << tr("unknown") << ">"; setStatus(0); @@ -120,7 +120,17 @@ void GpgFrontend::GpgDecryptResultAnalyse::print_recipient( stream << Qt::endl; - stream << "- " << tr("Key ID") << ": " << recipient->keyid << Qt::endl; + stream << "- " << tr("Key ID") << ": " << recipient->keyid; + if (key != nullptr) { + stream << " (" + << (key->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY + ? tr("Subkey") + : tr("Primary Key")) + << ")"; + } + + stream << Qt::endl; + stream << "- " << tr("Public Key Algo") << ": " << gpgme_pubkey_algo_name(recipient->pubkey_algo) << Qt::endl; stream << "- " << tr("Status") << ": " << gpgme_strerror(recipient->status) diff --git a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp index 262d0692..0cecc96b 100644 --- a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp @@ -28,8 +28,7 @@ #include "GpgSignResultAnalyse.h" -#include "core/GpgModel.h" -#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgAbstractKeyGetter.h" #include "core/utils/LocalizedUtils.h" namespace GpgFrontend { @@ -54,66 +53,61 @@ void GpgSignResultAnalyse::doAnalyse() { if (result != nullptr && (result->signatures != nullptr || result->invalid_signers != nullptr)) { stream_ << Qt::endl; - auto *new_sign = result->signatures; + auto *sign = result->signatures; auto index = 0; - while (new_sign != nullptr) { + while (sign != nullptr) { stream_ << "## " << tr("New Signature") << " [" << ++index << "]: " << Qt::endl; stream_ << "- " << tr("Sign Mode") << ": "; - if (new_sign->type == GPGME_SIG_MODE_NORMAL) { + if (sign->type == GPGME_SIG_MODE_NORMAL) { stream_ << tr("Normal"); - } else if (new_sign->type == GPGME_SIG_MODE_CLEAR) { + } else if (sign->type == GPGME_SIG_MODE_CLEAR) { stream_ << tr("Clear"); - } else if (new_sign->type == GPGME_SIG_MODE_DETACH) { + } else if (sign->type == GPGME_SIG_MODE_DETACH) { stream_ << tr("Detach"); } stream_ << Qt::endl; - QString fpr = new_sign->fpr == nullptr ? "" : new_sign->fpr; - auto singer_key = GpgKeyGetter::GetInstance(GetChannel()).GetKey(fpr); - if (singer_key.IsGood()) { - stream_ << "- " << tr("Signed By") << ": " - << singer_key.UIDs().front().GetUID() << Qt::endl; - - auto s_keys = singer_key.SubKeys(); - auto it = std::find_if( - s_keys.begin(), s_keys.end(), - [fpr](const GpgSubKey &k) { return k.Fingerprint() == fpr; }); - - if (it != s_keys.end()) { - auto &subkey = *it; - if (subkey.Fingerprint() != singer_key.Fingerprint()) { - stream_ << "- " << tr("Key ID") << ": " << singer_key.ID() << " (" - << tr("Subkey") << ")" << Qt::endl; - } else { - stream_ << "- " << tr("Key ID") << ": " << singer_key.ID() << " (" - << tr("Primary Key") << ")" << Qt::endl; - } - stream_ << "- " << tr("Key Create Date") << ": " - << QLocale().toString(subkey.CreationTime()) << Qt::endl; + QString fpr = sign->fpr == nullptr ? "" : sign->fpr; + auto sign_key = + GpgAbstractKeyGetter::GetInstance(GetChannel()).GetKey(fpr); + if (sign_key != nullptr) { + stream_ << "- " << tr("Signed By") << ": " << sign_key->UID() + << Qt::endl; + + if (sign_key->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY) { + stream_ << "- " << tr("Key ID") << ": " << sign_key->ID() << " (" + << tr("Subkey") << ")" << Qt::endl; + } else { + stream_ << "- " << tr("Key ID") << ": " << sign_key->ID() << " (" + << tr("Primary Key") << ")" << Qt::endl; } + stream_ << "- " << tr("Key Create Date") << ": " + << QLocale().toString(sign_key->CreationTime()) << Qt::endl; + } else { stream_ << "- " << tr("Signed By") << "(" << tr("Fingerprint") << ")" << ": " << (fpr.isEmpty() ? tr("<unknown>") : fpr) << Qt::endl; } + stream_ << "- " << tr("Public Key Algo") << ": " - << gpgme_pubkey_algo_name(new_sign->pubkey_algo) << Qt::endl; + << gpgme_pubkey_algo_name(sign->pubkey_algo) << Qt::endl; stream_ << "- " << tr("Hash Algo") << ": " - << gpgme_hash_algo_name(new_sign->hash_algo) << Qt::endl; + << gpgme_hash_algo_name(sign->hash_algo) << Qt::endl; stream_ << "- " << tr("Sign Date") << "(" << tr("UTC") << ")" << ": " - << GetUTCDateByTimestamp(new_sign->timestamp) << Qt::endl; + << GetUTCDateByTimestamp(sign->timestamp) << Qt::endl; stream_ << "- " << tr("Sign Date") << "(" << tr("Localized") << ")" - << ": " << GetLocalizedDateByTimestamp(new_sign->timestamp) + << ": " << GetLocalizedDateByTimestamp(sign->timestamp) << Qt::endl; stream_ << Qt::endl << "---------------------------------------" << Qt::endl << Qt::endl; - new_sign = new_sign->next; + sign = sign->next; } auto *invalid_signer = result->invalid_signers; diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp index 09b7da7e..66a607b8 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp @@ -28,8 +28,7 @@ #include "GpgVerifyResultAnalyse.h" -#include "core/GpgModel.h" -#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgAbstractKeyGetter.h" #include "core/utils/CommonUtils.h" #include "core/utils/LocalizedUtils.h" @@ -200,29 +199,19 @@ auto GpgFrontend::GpgVerifyResultAnalyse::print_signer( QTextStream &stream, GpgSignature sign) -> bool { auto fingerprint = sign.GetFingerprint(); auto key = - GpgFrontend::GpgKeyGetter::GetInstance(GetChannel()).GetKey(fingerprint); - if (key.IsGood()) { - stream << "- " << tr("Signed By") << ": " << key.UIDs().front().GetUID() - << Qt::endl; - - auto s_keys = key.SubKeys(); - auto it = std::find_if(s_keys.begin(), s_keys.end(), - [fingerprint](const GpgSubKey &k) { - return k.Fingerprint() == fingerprint; - }); - - if (it != s_keys.end()) { - auto &s_key = *it; - if (s_key.Fingerprint() != key.Fingerprint()) { - stream << "- " << tr("Key ID") << ": " << key.ID() << " (" - << tr("Subkey") << ")" << Qt::endl; - } else { - stream << "- " << tr("Key ID") << ": " << key.ID() << " (" - << tr("Primary Key") << ")" << Qt::endl; - } - stream << "- " << tr("Key Create Date") << ": " - << QLocale().toString(s_key.CreationTime()) << Qt::endl; + GpgAbstractKeyGetter::GetInstance(GetChannel()).GetKey(fingerprint); + if (key != nullptr) { + stream << "- " << tr("Signed By") << ": " << key->UID() << Qt::endl; + + if (key->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY) { + stream << "- " << tr("Key ID") << ": " << key->ID() << " (" + << tr("Subkey") << ")" << Qt::endl; + } else { + stream << "- " << tr("Key ID") << ": " << key->ID() << " (" + << tr("Primary Key") << ")" << Qt::endl; } + stream << "- " << tr("Key Create Date") << ": " + << QLocale().toString(key->CreationTime()) << Qt::endl; } else { stream_ << "- " << tr("Signed By") << "(" << tr("Fingerprint") << ")" @@ -239,7 +228,8 @@ auto GpgFrontend::GpgVerifyResultAnalyse::print_signer( stream << "- " << tr("Sign Date") << "(" << tr("Localized") << ")" << ": " << QLocale().toString(sign.GetCreateTime()) << Qt::endl; stream << Qt::endl; - return key.IsGood(); + + return key != nullptr; } auto GpgFrontend::GpgVerifyResultAnalyse::GetSignatures() const |