14#include "keyple/card/calypso/CommandReadRecordMultiple.hpp"
20#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
21#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
22#include "keyple/card/calypso/CardDataAccessException.hpp"
23#include "keyple/card/calypso/CardIllegalParameterException.hpp"
24#include "keyple/card/calypso/CardSecurityContextException.hpp"
25#include "keyple/core/util/ApduUtil.hpp"
26#include "keyple/core/util/HexUtil.hpp"
27#include "keyple/core/util/cpp/Arrays.hpp"
28#include "keyple/core/util/cpp/System.hpp"
34using keyple::core::util::ApduUtil;
35using keyple::core::util::HexUtil;
36using keyple::core::util::cpp::Arrays;
37using keyple::core::util::cpp::System;
39const std::map<int, const std::shared_ptr<Command::StatusProperties>>
40 CommandReadRecordMultiple::STATUS_TABLE = [] {
41 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
42 Command::STATUS_TABLE);
46 std::make_shared<Command::StatusProperties>(
47 "Lc value not supported",
48 typeid(CardIllegalParameterException))},
50 std::make_shared<Command::StatusProperties>(
51 "Incorrect EF type: Binary EF",
52 typeid(CardDataAccessException))},
54 std::make_shared<Command::StatusProperties>(
55 "Security conditions not fulfilled (PIN code not presented,"
56 " encryption required)",
57 typeid(CardSecurityContextException))},
59 std::make_shared<Command::StatusProperties>(
60 "Access forbidden (Never access mode, Stored value log file"
61 " and a Stored value operation was done during the current "
63 typeid(CardAccessForbiddenException))},
65 std::make_shared<Command::StatusProperties>(
66 "Incorrect file type: the Current File is not an EF. "
68 typeid(CardDataAccessException))},
70 std::make_shared<Command::StatusProperties>(
71 "Incorrect command data (incorrect Tag, incorrect Length, "
72 "R. Length > RecSize, R. Offset + R. Length > RecSize, R. "
74 typeid(CardIllegalParameterException))},
76 std::make_shared<Command::StatusProperties>(
77 "File not found",
typeid(CardDataAccessException))},
79 std::make_shared<Command::StatusProperties>(
80 "Record not found (record index is 0, or above NumRec)",
81 typeid(CardDataAccessException))},
83 std::make_shared<Command::StatusProperties>(
84 "P1 or P2 value not supported",
85 typeid(CardIllegalParameterException))},
87 std::make_shared<Command::StatusProperties>(
88 "Successful execution, partial read only: issue another "
89 "Read Record Multiple from record (P1 + (Size of returned "
90 "data) / (R. Length)) to continue reading")}});
94CommandReadRecordMultiple::CommandReadRecordMultiple(
95 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
97 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
99 std::uint8_t recordNumber,
103 CardCommandRef::READ_RECORD_MULTIPLE,
108, mRecordNumber(recordNumber)
112 const uint8_t p2 = (sfi * 8 + 5);
113 const std::vector<uint8_t> dataIn = {0x54, 0x02, offset, length};
117 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
118 transactionContext->getCard()->getCardClass().getValue(),
119 getCommandRef().getInstructionByte(),
124 std::stringstream extraInfo;
125 extraInfo <<
"SFI:" << sfi <<
"h, "
126 <<
"RECORD_NUMBER:" << recordNumber <<
", "
127 <<
"OFFSET:" << offset <<
", "
128 <<
"LENGTH:" << length;
130 addSubName(extraInfo.str());
134CommandReadRecordMultiple::finalizeRequest()
140CommandReadRecordMultiple::isCryptoServiceRequiredToFinalizeRequest()
const
146CommandReadRecordMultiple::synchronizeCryptoServiceBeforeCardProcessing()
152CommandReadRecordMultiple::parseResponse(
153 std::shared_ptr<ApduResponseApi> apduResponse)
155 if (!setApduResponseAndCheckStatusInBestEffortMode(apduResponse)) {
159 const std::vector<std::uint8_t> dataOut = apduResponse->getDataOut();
160 const int nbRecords =
static_cast<int>(dataOut.size()) / mLength;
162 for (
int i = 0; i < nbRecords; i++) {
163 getTransactionContext()->getCard()->setContent(
165 static_cast<uint8_t
>(mRecordNumber + i),
166 Arrays::copyOfRange(dataOut, i * mLength, (i + 1) * mLength),
171const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
172CommandReadRecordMultiple::getStatusTable()
const