21#include "BerTlvUtil.h"
28using namespace keyple::core::util;
29using namespace keyple::core::util::cpp;
31const int CmdCardGetDataFci::TAG_DF_NAME = 0x84;
32const int CmdCardGetDataFci::TAG_APPLICATION_SERIAL_NUMBER = 0xC7;
33const int CmdCardGetDataFci::TAG_DISCRETIONARY_DATA = 0x53;
35const std::map<const int, const std::shared_ptr<StatusProperties>>
36 CmdCardGetDataFci::STATUS_TABLE = initStatusTable();
42 std::make_shared<ApduRequestAdapter>(
43 ApduUtil::build(calypsoCardClass.
getValue(),
59 const std::shared_ptr<ApduResponseApi> apduResponse)
68 mLogger->debug(
"The response to the select application command status word indicates that" \
69 " the DF has been invalidated\n");
70 mIsDfInvalidated =
true;
76 const std::vector<uint8_t> responseData =
getApduResponse()->getDataOut();
83 const std::map<const int, const std::vector<uint8_t>> tags =
84 BerTlvUtil::parseSimple(responseData,
true);
86 auto it = tags.find(TAG_DF_NAME);
87 if (it == tags.end()) {
88 mLogger->error(
"DF name tag (84h) not found\n");
94 if (mDfName.size() < 5 || mDfName.size() > 16) {
95 mLogger->error(
"Invalid DF name length: %. Should be between 5 and 16\n",
100 mLogger->debug(
"DF name = %\n", HexUtil::toHex(mDfName));
102 it = tags.find(TAG_APPLICATION_SERIAL_NUMBER);
103 if (it == tags.end()) {
104 mLogger->error(
"Serial Number tag (C7h) not found\n");
108 mApplicationSN = it->second;
111 if (mApplicationSN.size() != 8) {
112 mLogger->error(
"Invalid application serial number length: %. Should be 8\n",
113 mApplicationSN.size());
117 mLogger->debug(
"Application Serial Number = %\n", HexUtil::toHex(mApplicationSN));
119 it = tags.find(TAG_DISCRETIONARY_DATA);
120 if (it == tags.end()) {
121 mLogger->error(
"Discretionary data tag (53h) not found\n");
125 mDiscretionaryData = it->second;
127 if (mDiscretionaryData.size() < 7) {
128 mLogger->error(
"Invalid startup info length: %. Should be >= 7\n",
129 mDiscretionaryData.size());
133 mLogger->debug(
"Discretionary Data = %\n", HexUtil::toHex(mDiscretionaryData));
136 mIsValidCalypsoFCI =
true;
138 }
catch (
const Exception& e) {
140 mLogger->debug(
"Error while parsing the FCI BER-TLV data structure (%)\n", e.getMessage());
148 return mIsValidCalypsoFCI;
158 return mApplicationSN;
163 return mDiscretionaryData;
168 return mIsDfInvalidated;
171const std::map<const int, const std::shared_ptr<StatusProperties>>
172 CmdCardGetDataFci::initStatusTable()
174 std::map<const int, const std::shared_ptr<StatusProperties>> m =
178 std::make_shared<StatusProperties>(
"Data object not found (optional mode not " \
182 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
183 typeid(CardDataAccessException))});
185 std::make_shared<StatusProperties>(
"Successful execution, FCI request and DF is " \
192const std::map<const int, const std::shared_ptr<StatusProperties>>&
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
AbstractCardCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
static const CalypsoCardCommand GET_DATA
uint8_t getInstructionByte() const
const std::vector< uint8_t > & getDfName() const
bool isDfInvalidated() const
bool isValidCalypsoFCI() const
CmdCardGetDataFci & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const std::vector< uint8_t > & getDiscretionaryData() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::vector< uint8_t > & getApplicationSerialNumber() const
bool isSessionBufferUsed() const override