31using namespace keyple::core::util;
32using namespace keyple::core::util::cpp;
35const std::map<const int, const std::shared_ptr<StatusProperties>>
36 CmdCardReadRecords::STATUS_TABLE = initStatusTable();
40 const int firstRecordNumber,
42 const int expectedLength)
44 mRecordSize(expectedLength)
46 buildCommand(calypsoCard->getCardClass(), sfi, firstRecordNumber, readMode, expectedLength);
51 const uint8_t firstRecordNumber,
53 const int expectedLength)
55 mRecordSize(expectedLength)
57 buildCommand(calypsoCardClass, sfi, firstRecordNumber, readMode, expectedLength);
60void CmdCardReadRecords::buildCommand(
const CalypsoCardClass calypsoCardClass,
62 const int firstRecordNumber,
63 const ReadMode readMode,
64 const int expectedLength)
67 mFirstRecordNumber = firstRecordNumber;
70 const uint8_t p1 =
static_cast<uint8_t
>(firstRecordNumber);
71 uint8_t p2 = sfi == 0x00 ? 0x05 :
static_cast<uint8_t
>((sfi * 8) + 5);
78 const uint8_t le = expectedLength < 0 ? 0 : expectedLength;
82 std::make_shared<ApduRequestAdapter>(
87 std::stringstream extraInfo;
88 extraInfo <<
"SFI: " << sfi <<
"h, "
89 <<
"REC: " << firstRecordNumber <<
", "
90 <<
"READMODE: " << readMode <<
", "
91 <<
"EXPECTEDLENGTH: " << expectedLength;
100const std::map<const int, const std::shared_ptr<StatusProperties>>
101 CmdCardReadRecords::initStatusTable()
103 std::map<const int, const std::shared_ptr<StatusProperties>> m =
107 std::make_shared<StatusProperties>(
"Command forbidden on binary files",
110 std::make_shared<StatusProperties>(
"Security conditions not fulfilled (PIN code " \
111 "not presented, encryption required).",
112 typeid(CardSecurityContextException))});
114 std::make_shared<StatusProperties>(
"Access forbidden (Never access mode, stored " \
115 "value log file and a stored value operation was" \
116 " done during the current session).",
117 typeid(CardAccessForbiddenException))});
119 std::make_shared<StatusProperties>(
"Command not allowed (no current EF)",
120 typeid(CardDataAccessException))});
122 std::make_shared<StatusProperties>(
"File not found",
123 typeid(CardDataAccessException))});
125 std::make_shared<StatusProperties>(
"Record not found (record index is 0, or above " \
127 typeid(CardDataAccessException))});
129 std::make_shared<StatusProperties>(
"P2 value not supported",
130 typeid(CardIllegalParameterException))});
135const std::map<const int, const std::shared_ptr<StatusProperties>>&
147 getCalypsoCard()->setContent(mSfi, mFirstRecordNumber, apduResponse->getDataOut());
151 const std::vector<uint8_t> mApdu = apduResponse->getDataOut();
152 uint8_t apduLen =
static_cast<uint8_t
>(mApdu.size());
155 while (apduLen > 0) {
157 const uint8_t recordNb = mApdu[index++];
158 const uint8_t len = mApdu[index++];
162 Arrays::copyOfRange(mApdu, index, index + len));
165 apduLen -= (2 + len);
177 return mFirstRecordNumber;
196 os <<
"MULTIPLE_RECORD";
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual void addSubName(const std::string &subName) 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 READ_RECORDS
uint8_t getInstructionByte() const
ReadMode getReadMode() const
CmdCardReadRecords(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const int sfi, const int firstRecordNumber, const ReadMode readMode, const int expectedLength)
bool isSessionBufferUsed() const override
int getRecordSize() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
uint8_t getFirstRecordNumber() const
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduRequestAdapter > ara)