Skip to content

Commit

Permalink
Remove the ScopedGuard and replace it with the qScopeGuard function.
Browse files Browse the repository at this point in the history
  • Loading branch information
w15dev committed Jan 1, 2025
1 parent be13fcf commit de84278
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions src/keys/drivers/YubiKeyInterfacePCSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#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 @@ -511,30 +513,6 @@ namespace
return rv;
});
}

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()>>,
"F-typed objects are not convertible to std::function<void()>");
static_assert(std::is_invocable_v<F>, "F-typed objects are not invocable");
}

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

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

} // namespace

YubiKeyInterfacePCSC::YubiKeyInterfacePCSC()
Expand Down Expand Up @@ -601,7 +579,7 @@ YubiKey::KeyMap YubiKeyInterfacePCSC::findValidKeys()
continue;
}

ScopeGuard disconnect{[hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); }};
auto finally = qScopeGuard([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); });

// Read the protocol and the ATR record
char pbReader[MAX_READERNAME] = {0};
Expand Down Expand Up @@ -700,7 +678,7 @@ YubiKey::KeyList YubiKeyInterfacePCSC::findKeys()
continue;
}

ScopeGuard disconnect([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); });
auto finally = qScopeGuard([hCard]() { SCardDisconnect(hCard, SCARD_LEAVE_CARD); });

// Read the protocol and the ATR record
char pbReader[MAX_READERNAME] = {0};
Expand Down

0 comments on commit de84278

Please sign in to comment.