21#include "ByteArrayUtil.h"
34using namespace keyple::core::util;
35using namespace keyple::core::util::cpp;
37const std::map<const int, const std::shared_ptr<StatusProperties>>
38 CmdCardIncreaseOrDecreaseMultiple::STATUS_TABLE = initStatusTable();
41 const bool isDecreaseCommand,
42 const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
44 const std::map<const int, const int> counterNumberToIncDecValueMap)
47 counterNumberToIncDecValueMap.size() * 4,
50 mCounterNumberToIncDecValueMap(counterNumberToIncDecValueMap)
53 const uint8_t p2 = sfi * 8;
54 std::vector<uint8_t> dataIn(4 * counterNumberToIncDecValueMap.size());
57 for (
const auto& entry : counterNumberToIncDecValueMap) {
59 dataIn[index] =
static_cast<uint8_t
>(entry.first);
60 const int incDecValue = entry.second;
61 ByteArrayUtil::copyBytes(incDecValue, dataIn, index + 1, 3);
67 std::make_shared<ApduRequestAdapter>(
68 ApduUtil::build(calypsoCard->getCardClass().getValue(),
75 std::stringstream extraInfo;
76 extraInfo <<
"SFI:" << sfi <<
"h";
78 for (
const auto& entry : counterNumberToIncDecValueMap) {
80 extraInfo <<
", " << entry.first <<
":" << entry.second;
91const std::map<const int, const std::shared_ptr<StatusProperties>>
92 CmdCardIncreaseOrDecreaseMultiple::initStatusTable()
94 std::map<const int, const std::shared_ptr<StatusProperties>> m =
98 std::make_shared<StatusProperties>(
"Too many modifications in session.",
101 std::make_shared<StatusProperties>(
"Lc value not supported.",
102 typeid(CardIllegalParameterException))});
104 std::make_shared<StatusProperties>(
"Incorrect EF type: not a Counters EF.",
105 typeid(CardDataAccessException))});
107 std::make_shared<StatusProperties>(
"Security conditions not fulfilled (no secure " \
108 "session, incorrect key, encryption required, " \
109 "PKI mode and not Always access mode).",
110 typeid(CardSecurityContextException))});
112 std::make_shared<StatusProperties>(
"Access forbidden (Never access mode, DF is " \
114 typeid(CardAccessForbiddenException))});
116 std::make_shared<StatusProperties>(
"Incorrect file type: the Current File is not " \
117 "an EF. Supersedes 6981h.",
118 typeid(CardDataAccessException))});
120 std::make_shared<StatusProperties>(
"Incorrect command data (Overflow error, " \
121 "Incorrect counter number, Counter number " \
122 "present more than once).",
123 typeid(CardIllegalParameterException))});
125 std::make_shared<StatusProperties>(
"File not found.",
126 typeid(CardDataAccessException))});
128 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
129 typeid(CardIllegalParameterException))});
134const std::map<const int, const std::shared_ptr<StatusProperties>>&
141 const std::shared_ptr<ApduResponseApi> apduResponse)
145 if (apduResponse->getDataOut().size() > 0) {
147 const std::vector<uint8_t> dataOut = apduResponse->getDataOut();
148 const int nbCounters =
static_cast<int>(dataOut.size() / 4);
150 for (
int i = 0; i < nbCounters; i++) {
153 dataOut[i * 4] & 0xFF,
154 Arrays::copyOfRange(dataOut, (i * 4) + 1, (i * 4) + 4));
164const std::map<const int, const int>&
167 return mCounterNumberToIncDecValueMap;
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
const CalypsoCardCommand & getCommandRef() const override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
bool isSessionBufferUsed() const override
const std::map< const int, const int > & getCounterNumberToIncDecValueMap() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
CmdCardIncreaseOrDecreaseMultiple(const bool isDecreaseCommand, const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t sfi, const std::map< const int, const int > counterNumberToIncDecValueMap)