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