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();
41 buildCommand(calypsoCard->getCardClass());
47 buildCommand(calypsoCardClass);
54 std::make_shared<ApduRequestAdapter>(
55 ApduUtil::build(calypsoCardClass.
getValue(),
76 mLogger->debug(
"The response to the select application command status word indicates that" \
77 " the DF has been invalidated\n");
78 mIsDfInvalidated =
true;
84 const std::vector<uint8_t> responseData =
getApduResponse()->getDataOut();
91 const std::map<const int, const std::vector<uint8_t>> tags =
92 BerTlvUtil::parseSimple(responseData,
true);
94 auto it = tags.find(TAG_DF_NAME);
95 if (it == tags.end()) {
96 mLogger->error(
"DF name tag (84h) not found\n");
100 mDfName = it->second;
102 if (mDfName.size() < 5 || mDfName.size() > 16) {
103 mLogger->error(
"Invalid DF name length: %. Should be between 5 and 16\n",
108 mLogger->debug(
"DF name = %\n", HexUtil::toHex(mDfName));
110 it = tags.find(TAG_APPLICATION_SERIAL_NUMBER);
111 if (it == tags.end()) {
112 mLogger->error(
"Serial Number tag (C7h) not found\n");
116 mApplicationSN = it->second;
119 if (mApplicationSN.size() != 8) {
120 mLogger->error(
"Invalid application serial number length: %. Should be 8\n",
121 mApplicationSN.size());
125 mLogger->debug(
"Application Serial Number = %\n", HexUtil::toHex(mApplicationSN));
127 it = tags.find(TAG_DISCRETIONARY_DATA);
128 if (it == tags.end()) {
129 mLogger->error(
"Discretionary data tag (53h) not found\n");
133 mDiscretionaryData = it->second;
135 if (mDiscretionaryData.size() < 7) {
136 mLogger->error(
"Invalid startup info length: %. Should be >= 7\n",
137 mDiscretionaryData.size());
141 mLogger->debug(
"Discretionary Data = %\n", HexUtil::toHex(mDiscretionaryData));
144 mIsValidCalypsoFCI =
true;
146 }
catch (
const Exception& e) {
149 mLogger->debug(
"Error while parsing the FCI BER-TLV data structure (%)\n", e.getMessage());
157 return mIsValidCalypsoFCI;
167 return mApplicationSN;
172 return mDiscretionaryData;
177 return mIsDfInvalidated;
180const std::map<const int, const std::shared_ptr<StatusProperties>>
181 CmdCardGetDataFci::initStatusTable()
183 std::map<const int, const std::shared_ptr<StatusProperties>> m =
187 std::make_shared<StatusProperties>(
"Data object not found (optional mode not " \
191 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
192 typeid(CardDataAccessException))});
194 std::make_shared<StatusProperties>(
"Successful execution, FCI request and DF is " \
201const 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
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
static const CalypsoCardCommand GET_DATA
uint8_t getInstructionByte() const
CmdCardGetDataFci(const std::shared_ptr< CalypsoCardAdapter > calypsoCard)
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const std::vector< uint8_t > & getDfName() const
bool isDfInvalidated() const
bool isValidCalypsoFCI() const
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