LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
iso7816response.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_ISO7816RESPONSE_HPP
8#define LOGICALACCESS_ISO7816RESPONSE_HPP
9
10#include <logicalaccess/plugins/cards/iso7816/lla_cards_iso7816_api.hpp>
13#include <iomanip>
14
15namespace logicalaccess
16{
20class LLA_CARDS_ISO7816_API ISO7816Response
21{
22 public:
23 ISO7816Response(): sw1_(0), sw2_(0), data_()
24 {
25
26 }
27
28 ISO7816Response(const ByteVector &data, unsigned char sw1, unsigned char sw2)
29 {
30 sw1_ = sw1;
31 sw2_ = sw2;
32 data_ = data;
33 }
34
35 explicit ISO7816Response(const ByteVector &data)
36 {
37 if (data.size() < 2)
38 {
40 "Missing SW1 SW2 Status Code.");
41 }
42
43 sw1_ = data.at(data.size() - 2);
44 sw2_ = data.at(data.size() - 1);
45 data_ = ByteVector(data.begin(), data.end() - 2);
46 }
47
48 unsigned char getSW1() const
49 {
50 return sw1_;
51 }
52
53 unsigned char getSW2() const
54 {
55 return sw2_;
56 }
57
58 const ByteVector &getData() const
59 {
60 return data_;
61 }
62
64 auto resp = getData();
65 resp.push_back(sw1_);
66 resp.push_back(sw2_);
67 return resp;
68 }
69
70 private:
74 unsigned char sw1_;
78 unsigned char sw2_;
83};
84
85inline LLA_CARDS_ISO7816_API std::ostream &operator<<(std::ostream &ss,
86 const ISO7816Response &response)
87{
88 std::stringstream tmp;
89 tmp << std::hex;
90 tmp << "ISO7816Response [";
91 tmp << std::setfill('0') << std::setw(2) << +response.getSW1();
92 tmp << std::setfill('0') << std::setw(2) << +response.getSW2() << "]:";
93 tmp << std::resetiosflags(std::ios_base::basefield);
94 tmp << response.getData();
95 ss << tmp.str();
96 return ss;
97}
98}
99
100#endif /* LOGICALACCESS_ISO7816RESPONSE_HPP */
A ISO7816 response message.
Definition: iso7816response.hpp:21
ByteVector getCompleteResponse()
Definition: iso7816response.hpp:63
ByteVector data_
Data Response.
Definition: iso7816response.hpp:82
unsigned char getSW1() const
Definition: iso7816response.hpp:48
ISO7816Response(const ByteVector &data, unsigned char sw1, unsigned char sw2)
Definition: iso7816response.hpp:28
ISO7816Response(const ByteVector &data)
Definition: iso7816response.hpp:35
unsigned char sw2_
SW2 Response Status Code.
Definition: iso7816response.hpp:78
const ByteVector & getData() const
Definition: iso7816response.hpp:58
ISO7816Response()
Definition: iso7816response.hpp:23
unsigned char sw1_
SW1 Response Status Code.
Definition: iso7816response.hpp:74
unsigned char getSW2() const
Definition: iso7816response.hpp:53
A liblogicalaccess exception class.
Definition: myexception.hpp:22
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Logging header.
#define THROW_EXCEPTION_WITH_LOG(type, msg,...)
Definition: logs.hpp:237
Definition: asn1.hpp:9
LLA_CORE_API std::ostream & operator<<(std::ostream &os, const Key &key)
Output to stream operator.
Definition: key.cpp:298