Skip to content

Commit

Permalink
refactor(SmartCard): use named constants for smart card models, simpl…
Browse files Browse the repository at this point in the history
…ify vendor-specific PIN pad conditional

WE2-859

Signed-off-by: Mart Somermaa <[email protected]>
  • Loading branch information
mrts committed Mar 5, 2024
1 parent a3b0140 commit 75c4d00
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/libpcsc-cpp/src/SmartCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,23 @@ std::pair<SCARDHANDLE, DWORD> connectToCard(const SCARDCONTEXT ctx, const string
}

template <class K, class V = uint32_t, class D, size_t dsize, typename Func>
constexpr std::map<K, V> parseTLV(const std::array<D, dsize>& data, DWORD size, Func transfrom)
constexpr std::map<K, V> parseTLV(const std::array<D, dsize>& data, DWORD size, Func transform)
{
std::map<K, V> result;
for (auto p = data.cbegin(); DWORD(std::distance(data.cbegin(), p)) < size;) {
auto tag = K(*p++);
V value {};
for (unsigned int i = 0, len = *p++; i < len; ++i)
value |= V(*p++) << 8 * i;
result[tag] = transfrom(value);
result[tag] = transform(value);
}
return result;
}

constexpr uint32_t VENDOR_HID_GLOBAL = 0x076B;
constexpr uint32_t OMNIKEY_3x21 = 0x3031;
constexpr uint32_t OMNIKEY_6121 = 0x6632;

} // namespace

namespace pcsc_cpp
Expand Down Expand Up @@ -134,10 +138,10 @@ class CardImpl

bool readerHasPinPad() const
{
// Some readers claim to have PinPAD support even if they have not
// HID Global OMNIKEY 3x21 Smart Card Reader / HID Global OMNIKEY 6121 Smart Card Reader
if ((id_vendor == 0x076B && id_product == 0x3031)
|| (id_vendor == 0x076B && id_product == 0x6632))
// The HID Global OMNIKEY 3x21 Smart Card Reader and HID Global OMNIKEY 6121 Smart Card Reader
// falsely report that they have PIN pad support even though they don't.
if (id_vendor == VENDOR_HID_GLOBAL &&
(id_product == OMNIKEY_3x21 || id_product == OMNIKEY_6121))
return false;
if (getenv("SMARTCARDPP_NOPINPAD"))
return false;
Expand Down

0 comments on commit 75c4d00

Please sign in to comment.