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