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