AusweisApp2
Lade ...
Suche ...
Keine Treffer
CommandApdu.h
gehe zur Dokumentation dieser Datei
1
5#pragma once
6
7#include "EnumHelper.h"
8
9#include <QByteArray>
10#include <QDebug>
11
12#include <cstddef>
13
14
15namespace governikus
16{
18 UNKNOWN = 0x00,
19 DEACTIVATE = 0x04,
20 MSE_SET = 0x22,
21 ACTIVATE = 0x44,
22 EXTERNAL_AUTHENTICATE = 0x82,
23 GET_CHALLENGE = 0x84,
24 GENERAL_AUTHENTICATE = 0x86,
25 PSO_VERIFY = 0x2A,
26 PSO_COMPUTE = 0x2B,
27 RESET_RETRY_COUNTER = 0x2C,
28 SELECT = 0xA4,
29 READ_BINARY = 0xB0,
30 GET_RESPONSE = 0xC0,
31 UPDATE_BINARY = 0xD6
32 )
33
34class CommandApdu
35{
36 private:
37 std::byte mCla;
38 uchar mIns;
39 uchar mP1;
40 uchar mP2;
41 QByteArray mData;
42 int mLe;
43
44 public:
45 enum Param : uchar
46 {
47 IMPLICIT = 0x00,
48 CHANGE = 0x02,
49 UNBLOCK = 0x03,
50 PIN = 0x03,
51 CHIP_AUTHENTICATION = 0x41,
52 VERIFICATION = 0x81,
53 AUTHENTICATION_TEMPLATE = 0xA4,
54 DIGITAL_SIGNATURE_TEMPLATE = 0xB6,
55 SELF_DESCRIPTIVE = 0xBE,
56 PACE = 0xC1
57 };
58
59 static const int NO_LE = 0;
60 static const int SHORT_MAX_LC = 0xFF;
61 static const int SHORT_MAX_LE = 0x0100;
62 static const int EXTENDED_MAX_LC = 0x00FFFF;
63 static const int EXTENDED_MAX_LE = 0x010000;
64
65 [[nodiscard]] static bool isExtendedLength(const QByteArray& pData, int pLe);
66
67 explicit CommandApdu(const QByteArray& pBuffer = QByteArray());
68 explicit CommandApdu(const QByteArray& pHeader, const QByteArray& pData, int pLe = NO_LE);
69 explicit CommandApdu(Ins pIns, uchar pP1, uchar pP2, const QByteArray& pData = QByteArray(), int pLe = NO_LE);
70 virtual ~CommandApdu();
71
72 void enableCommandChaining();
73 [[nodiscard]] bool isCommandChaining() const;
74
75 void setSecureMessaging(bool pEnabled);
76 [[nodiscard]] bool isSecureMessaging() const;
77
78 [[nodiscard]] bool isEmpty() const;
79 [[nodiscard]] Ins getINS() const;
80 [[nodiscard]] uchar getP1() const;
81 [[nodiscard]] uchar getP2() const;
82 [[nodiscard]] QByteArray getHeaderBytes() const;
83 [[nodiscard]] const QByteArray& getData() const;
84 [[nodiscard]] int getLe() const;
85 [[nodiscard]] bool isExtendedLength() const;
86
87 operator QByteArray() const;
88};
89
90
91inline QDebug operator<<(QDebug pDbg, const CommandApdu& pCommandApdu)
92{
93 QDebugStateSaver saver(pDbg);
94 pDbg << QByteArray(pCommandApdu).toHex();
95 return pDbg;
96}
97
98
99char* toString(const CommandApdu& pCommandApdu);
100
101#ifndef QT_NO_DEBUG
102inline bool operator==(const CommandApdu& pLeft, const CommandApdu& pRight)
103{
104 return QByteArray(pLeft) == QByteArray(pRight);
105}
106
107
108#endif
109
110
111} // namespace governikus
#define defineTypedEnumType(enumName, enumType,...)
Definition: EnumHelper.h:65
struct Data mData
A simple template renderer.
Definition: ActivationContext.h:15
UNKNOWN
Definition: ResponseApdu.h:63
char * toString(const CommandApdu &pCommandApdu)
QDebug operator<<(QDebug pDbg, const CommandApdu &pCommandApdu)
Definition: CommandApdu.h:91
bool operator==(const CommandApdu &pLeft, const CommandApdu &pRight)
Definition: CommandApdu.h:102