From d15b2628ac63754388c583c03efab552edd40f92 Mon Sep 17 00:00:00 2001 From: w15dev Date: Mon, 30 Dec 2024 00:17:30 +0300 Subject: [PATCH] Fix build in ubuntu --- src/keys/drivers/YubiKey.cpp | 6 ++--- src/keys/drivers/YubiKeyInterfacePCSC.cpp | 29 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/keys/drivers/YubiKey.cpp b/src/keys/drivers/YubiKey.cpp index 61bc8a012b..921a7ab178 100644 --- a/src/keys/drivers/YubiKey.cpp +++ b/src/keys/drivers/YubiKey.cpp @@ -99,10 +99,8 @@ void YubiKey::findValidKeysAsync() YubiKey::KeyMap YubiKey::foundKeys() { QMutexLocker lock(&s_interfaceMutex); - KeyMap foundKeys; - - foundKeys.insert(m_usbKeys); - foundKeys.insert(m_pcscKeys); + KeyMap foundKeys = m_usbKeys; + foundKeys.unite(m_pcscKeys); return foundKeys; } diff --git a/src/keys/drivers/YubiKeyInterfacePCSC.cpp b/src/keys/drivers/YubiKeyInterfacePCSC.cpp index 1981b7e13b..6dc2a622c3 100644 --- a/src/keys/drivers/YubiKeyInterfacePCSC.cpp +++ b/src/keys/drivers/YubiKeyInterfacePCSC.cpp @@ -20,8 +20,6 @@ #include "core/Tools.h" #include "crypto/Random.h" -#include - // MSYS2 does not define these macros // So set them to the value used by pcsc-lite #ifndef MAX_ATR_SIZE @@ -514,6 +512,29 @@ namespace }); } + class ScopeGuard + { + public: + template + explicit ScopeGuard(F&& fn) + : m_function(std::forward(fn)) + { + static_assert(std::is_convertible_v>, + "the functor F isn't convertible to std::function"); + static_assert(std::is_invocable_v, "The functor F isn't invocable"); + } + + ~ScopeGuard() + { + if (m_function) { + m_function(); + } + } + + private: + std::function m_function{}; + }; + } // namespace YubiKeyInterfacePCSC::YubiKeyInterfacePCSC() @@ -580,7 +601,7 @@ YubiKey::KeyMap YubiKeyInterfacePCSC::findValidKeys() continue; } - QScopeGuard disconnect([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); }); + ScopeGuard disconnect{[hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); }}; // Read the protocol and the ATR record char pbReader[MAX_READERNAME] = {0}; @@ -679,7 +700,7 @@ YubiKey::KeyList YubiKeyInterfacePCSC::findKeys() continue; } - QScopeGuard disconnect([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); }); + ScopeGuard disconnect([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); }); // Read the protocol and the ATR record char pbReader[MAX_READERNAME] = {0};