diff options
author | saturneric <[email protected]> | 2023-11-07 07:18:06 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-11-07 07:18:06 +0000 |
commit | 3ad7fecdb6458fdd6f146bed19fe643c7f93e905 (patch) | |
tree | 522f7a5dd0389ad0771d01a50ea49ef646940894 /src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp | |
parent | refactor: improve the code structure of core (diff) | |
download | GpgFrontend-3ad7fecdb6458fdd6f146bed19fe643c7f93e905.tar.gz GpgFrontend-3ad7fecdb6458fdd6f146bed19fe643c7f93e905.zip |
refactor: remove CommonUtils at core
Diffstat (limited to 'src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp')
-rw-r--r-- | src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp index b9947cd7..fd80c6bb 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp @@ -39,22 +39,22 @@ GpgFrontend::GpgVerifyResultAnalyse::GpgVerifyResultAnalyse( GpgError error, GpgVerifyResult result) : error_(error), result_(std::move(result)) {} -void GpgFrontend::GpgVerifyResultAnalyse::do_analyse() { +void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { SPDLOG_DEBUG("started"); stream_ << "[#] " << _("Verify Operation") << " "; - if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) + if (gpgme_err_code(error_) == GPG_ERR_NO_ERROR) { stream_ << "[" << _("Success") << "]" << std::endl; - else { + } else { stream_ << "[" << _("Failed") << "] " << gpgme_strerror(error_) << std::endl; - set_status(-1); + setStatus(-1); } if (result_ != nullptr && result_->signatures != nullptr) { stream_ << "------------>" << std::endl; - auto sign = result_->signatures; + auto *sign = result_->signatures; stream_ << "[>] " << _("Signed On") << "(" << _("UTC") << ")" << " " @@ -64,87 +64,87 @@ void GpgFrontend::GpgVerifyResultAnalyse::do_analyse() { stream_ << std::endl << "[>] " << _("Signatures List") << ":" << std::endl; - bool canContinue = true; + bool can_continue = true; int count = 1; - while (sign && canContinue) { + while ((sign != nullptr) && can_continue) { stream_ << boost::format(_("Signature [%1%]:")) % count++ << std::endl; switch (gpg_err_code(sign->status)) { case GPG_ERR_BAD_SIGNATURE: stream_ << _("A Bad Signature.") << std::endl; print_signer(stream_, sign); stream_ << _("This Signature is invalid.") << std::endl; - canContinue = false; - set_status(-1); + can_continue = false; + setStatus(-1); break; case GPG_ERR_NO_ERROR: stream_ << _("A") << " "; - if (sign->summary & GPGME_SIGSUM_GREEN) { + if ((sign->summary & GPGME_SIGSUM_GREEN) != 0) { stream_ << _("Good") << " "; } - if (sign->summary & GPGME_SIGSUM_RED) { + if ((sign->summary & GPGME_SIGSUM_RED) != 0) { stream_ << _("Bad") << " "; } - if (sign->summary & GPGME_SIGSUM_SIG_EXPIRED) { + if ((sign->summary & GPGME_SIGSUM_SIG_EXPIRED) != 0) { stream_ << _("Expired") << " "; } - if (sign->summary & GPGME_SIGSUM_KEY_MISSING) { + if ((sign->summary & GPGME_SIGSUM_KEY_MISSING) != 0) { stream_ << _("Missing Key's") << " "; } - if (sign->summary & GPGME_SIGSUM_KEY_REVOKED) { + if ((sign->summary & GPGME_SIGSUM_KEY_REVOKED) != 0) { stream_ << _("Revoked Key's") << " "; } - if (sign->summary & GPGME_SIGSUM_KEY_EXPIRED) { + if ((sign->summary & GPGME_SIGSUM_KEY_EXPIRED) != 0) { stream_ << _("Expired Key's") << " "; } - if (sign->summary & GPGME_SIGSUM_CRL_MISSING) { + if ((sign->summary & GPGME_SIGSUM_CRL_MISSING) != 0) { stream_ << _("Missing CRL's") << " "; } - if (sign->summary & GPGME_SIGSUM_VALID) { + if ((sign->summary & GPGME_SIGSUM_VALID) != 0) { stream_ << _("Signature Fully Valid.") << std::endl; } else { stream_ << _("Signature Not Fully Valid.") << std::endl; stream_ << _("(May used a subkey to sign)") << std::endl; } - if (!(sign->status & GPGME_SIGSUM_KEY_MISSING)) { - if (!print_signer(stream_, sign)) set_status(0); + if ((sign->status & GPGME_SIGSUM_KEY_MISSING) == 0U) { + if (!print_signer(stream_, sign)) setStatus(0); } else { stream_ << _("Key is NOT present with ID 0x") << sign->fpr << std::endl; } - set_status(1); + setStatus(1); break; case GPG_ERR_NO_PUBKEY: stream_ << _("A signature could NOT be verified due to a Missing Key") << std::endl; - set_status(-2); + setStatus(-2); break; case GPG_ERR_CERT_REVOKED: stream_ << _("A signature is valid but the key used to verify the " "signature has been revoked") << std::endl; if (!print_signer(stream_, sign)) { - set_status(0); + setStatus(0); } - set_status(-1); + setStatus(-1); break; case GPG_ERR_SIG_EXPIRED: stream_ << _("A signature is valid but expired") << std::endl; if (!print_signer(stream_, sign)) { - set_status(0); + setStatus(0); } - set_status(-1); + setStatus(-1); break; case GPG_ERR_KEY_EXPIRED: stream_ << _("A signature is valid but the key used to " "verify the signature has expired.") << std::endl; if (!print_signer(stream_, sign)) { - set_status(0); + setStatus(0); } break; case GPG_ERR_GENERAL: @@ -152,13 +152,13 @@ void GpgFrontend::GpgVerifyResultAnalyse::do_analyse() { "the signature verification.") << std::endl; status_ = -1; - canContinue = false; + can_continue = false; break; default: auto fpr = std::string(sign->fpr); stream_ << _("Error for key with fingerprint") << " " << GpgFrontend::BeautifyFingerprint(fpr); - set_status(-1); + setStatus(-1); } stream_ << std::endl; sign = sign->next; @@ -169,48 +169,53 @@ void GpgFrontend::GpgVerifyResultAnalyse::do_analyse() { << "[>] " << _("Could not find information that can be used for verification.") << std::endl; - set_status(0); + setStatus(0); return; } } -bool GpgFrontend::GpgVerifyResultAnalyse::print_signer( - std::stringstream &stream, gpgme_signature_t sign) { - bool keyFound = true; +auto GpgFrontend::GpgVerifyResultAnalyse::print_signer( + std::stringstream &stream, gpgme_signature_t sign) -> bool { + bool key_found = true; auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(sign->fpr); if (!key.IsGood()) { stream << " " << _("Signed By") << ": " << "<" << _("Unknown") << ">" << std::endl; - set_status(0); - keyFound = false; + setStatus(0); + key_found = false; } else { stream << " " << _("Signed By") << ": " << key.GetUIDs()->front().GetUID() << std::endl; } - if (sign->pubkey_algo) + if (sign->pubkey_algo != 0U) { stream << " " << _("Public Key Algo") << ": " << gpgme_pubkey_algo_name(sign->pubkey_algo) << std::endl; - if (sign->hash_algo) + } + if (sign->hash_algo != 0U) { stream << " " << _("Hash Algo") << ": " << gpgme_hash_algo_name(sign->hash_algo) << std::endl; - if (sign->timestamp) + } + if (sign->timestamp != 0U) { stream << " " << _("Date") << "(" << _("UTC") << ")" << ": " << boost::posix_time::to_iso_extended_string( boost::posix_time::from_time_t(sign->timestamp)) << std::endl; + } stream << std::endl; - return keyFound; + return key_found; } -gpgme_signature_t GpgFrontend::GpgVerifyResultAnalyse::GetSignatures() const { - if (result_) +auto GpgFrontend::GpgVerifyResultAnalyse::GetSignatures() const + -> gpgme_signature_t { + if (result_) { return result_->signatures; - else - return nullptr; + } + return nullptr; } -GpgFrontend::GpgVerifyResult -GpgFrontend::GpgVerifyResultAnalyse::TakeChargeOfResult() { + +auto GpgFrontend::GpgVerifyResultAnalyse::TakeChargeOfResult() + -> GpgFrontend::GpgVerifyResult { return std::move(result_); } |