VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/SCard.cpp
blob: 9f8d11458a43a31ba59e16e732392afea439e318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "SCard.h"

using namespace std;

namespace VeraCrypt
{
	SCardManager SCard::manager;

	SCard::SCard() : m_reader(NULL)
	{
	}

	SCard::SCard(size_t slotId)
    {
        m_reader = SCard::manager.GetReader(slotId);
    }

	SCard::~SCard()
    {
        if (m_reader)
        {
            m_reader->Disconnect();
        }
    }

	SCard::SCard(const SCard& other) : m_reader(other.m_reader)
	{
	}

	SCard::SCard(SCard&& other) : m_reader(std::move(other.m_reader))
	{
	}
	
	SCard& SCard::operator = (const SCard& other)
	{
		if (this != &other)
		{
			m_reader = other.m_reader;
		}
		return *this;
	}
	
	SCard& SCard::operator = (SCard&& other)
	{
		if (this != &other)
		{
			m_reader = std::move(other.m_reader);
		}
		return *this;
	}

	bool SCard::IsCardHandleValid() const
	{
		bool isValid = false;
		if (m_reader)
        {
			isValid = m_reader->CardHandleStatus() == SCARD_S_SUCCESS;
		}

		return isValid;
	}
}