Skip to content

Commit

Permalink
Fix build in ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
w15dev committed Dec 29, 2024
1 parent 322f318 commit d15b262
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/keys/drivers/YubiKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 25 additions & 4 deletions src/keys/drivers/YubiKeyInterfacePCSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "core/Tools.h"
#include "crypto/Random.h"

#include <QScopeGuard>

// MSYS2 does not define these macros
// So set them to the value used by pcsc-lite
#ifndef MAX_ATR_SIZE
Expand Down Expand Up @@ -514,6 +512,29 @@ namespace
});
}

class ScopeGuard
{
public:
template <typename F>
explicit ScopeGuard(F&& fn)
: m_function(std::forward<F>(fn))
{
static_assert(std::is_convertible_v<F, std::function<void()>>,
"the functor F isn't convertible to std::function<void()>");
static_assert(std::is_invocable_v<F>, "The functor F isn't invocable");
}

~ScopeGuard()
{
if (m_function) {
m_function();
}
}

private:
std::function<void()> m_function{};
};

} // namespace

YubiKeyInterfacePCSC::YubiKeyInterfacePCSC()
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit d15b262

Please sign in to comment.