diff options
Diffstat (limited to 'src/core/function')
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.cpp | 34 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.h | 10 | ||||
-rw-r--r-- | src/core/function/gpg/GpgSmartCardManager.cpp | 12 | ||||
-rw-r--r-- | src/core/function/gpg/GpgSmartCardManager.h | 8 |
4 files changed, 64 insertions, 0 deletions
diff --git a/src/core/function/gpg/GpgAssuanHelper.cpp b/src/core/function/gpg/GpgAssuanHelper.cpp index 2fa836e5..0d1b9cdc 100644 --- a/src/core/function/gpg/GpgAssuanHelper.cpp +++ b/src/core/function/gpg/GpgAssuanHelper.cpp @@ -161,6 +161,40 @@ auto GpgAssuanHelper::SendStatusCommand(GpgComponentType type, return {ret, status_lines}; } +auto GpgAssuanHelper::SendDataCommand(GpgComponentType type, + const QString& command) + -> std::tuple<bool, QStringList> { + QStringList data_lines; + GpgAssuanHelper::DataCallback d_cb = + [&](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "data callback of command " << command << ": " << ctx->buffer; + data_lines.push_back(QString::fromUtf8(ctx->buffer)); + return 0; + }; + + GpgAssuanHelper::InqueryCallback i_cb = + [=](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "inquery callback of command: " << command << ": " + << ctx->inquery; + + return 0; + }; + + GpgAssuanHelper::StatusCallback s_cb = + [&](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "status callback of command: " << command << ": " + << ctx->status; + + return 0; + }; + + auto ret = SendCommand(type, command, d_cb, i_cb, s_cb); + return {ret, data_lines}; +} + auto GpgAssuanHelper::default_data_callback(void* opaque, const void* buffer, size_t length) -> gpgme_error_t { auto ctx = *static_cast<QSharedPointer<AssuanCallbackContext>*>(opaque); diff --git a/src/core/function/gpg/GpgAssuanHelper.h b/src/core/function/gpg/GpgAssuanHelper.h index a0c45d7a..294d33e0 100644 --- a/src/core/function/gpg/GpgAssuanHelper.h +++ b/src/core/function/gpg/GpgAssuanHelper.h @@ -108,6 +108,16 @@ class GPGFRONTEND_CORE_EXPORT GpgAssuanHelper auto SendStatusCommand(GpgComponentType type, const QString& command) -> std::tuple<bool, QStringList>; + /** + * @brief + * + * @param type + * @param command + * @return auto + */ + auto SendDataCommand(GpgComponentType type, + const QString& command) -> std::tuple<bool, QStringList>; + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); diff --git a/src/core/function/gpg/GpgSmartCardManager.cpp b/src/core/function/gpg/GpgSmartCardManager.cpp index 422f0b20..cc7f8ab3 100644 --- a/src/core/function/gpg/GpgSmartCardManager.cpp +++ b/src/core/function/gpg/GpgSmartCardManager.cpp @@ -29,6 +29,7 @@ #include "GpgSmartCardManager.h" #include "core/function/gpg/GpgAutomatonHandler.h" +#include "core/utils/CommonUtils.h" namespace GpgFrontend { @@ -81,6 +82,17 @@ auto GpgSmartCardManager::Fetch(const QString& serial_number) -> bool { .DoCardInteract(serial_number, next_state_handler, action_handler); } +auto GpgSmartCardManager::IsSCDVersionSupported() -> bool { + auto [r, s] = assuan_.SendDataCommand(GpgComponentType::kGPG_AGENT, + "SCD GETINFO version"); + if (s.isEmpty()) { + LOG_D() << "invalid response of SCD GETINFO version: " << s; + return false; + } + + return GFCompareSoftwareVersion(s.front(), "2.3.0") > 0; +} + auto GpgSmartCardManager::GetSerialNumbers() -> QStringList { auto [r, s] = assuan_.SendStatusCommand(GpgComponentType::kGPG_AGENT, "SCD SERIALNO --all"); diff --git a/src/core/function/gpg/GpgSmartCardManager.h b/src/core/function/gpg/GpgSmartCardManager.h index 78c21bc0..2fe194f3 100644 --- a/src/core/function/gpg/GpgSmartCardManager.h +++ b/src/core/function/gpg/GpgSmartCardManager.h @@ -109,6 +109,14 @@ class GPGFRONTEND_CORE_EXPORT GpgSmartCardManager const QDateTime& expire, bool non_expire) -> std::tuple<bool, QString>; + /** + * @brief + * + * @return true + * @return false + */ + auto IsSCDVersionSupported() -> bool; + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< |