20#include "ByteArrayUtil.h"
35using namespace keyple::core::util;
36using namespace keyple::core::util::cpp;
38const int CmdCardIncreaseOrDecrease::SW_POSTPONED_DATA = 0x6200;
40const std::map<const int, const std::shared_ptr<StatusProperties>>
41 CmdCardIncreaseOrDecrease::STATUS_TABLE = initStatusTable();
44 const bool isDecreaseCommand,
45 const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
47 const uint8_t counterNumber,
48 const int incDecValue)
54 mCounterNumber(counterNumber),
55 mIncDecValue(incDecValue)
57 const uint8_t cla = calypsoCard->getCardClass().getValue();
63 std::vector<uint8_t> valueBuffer = ByteArrayUtil::extractBytes(incDecValue, 3);
65 const uint8_t p2 = sfi * 8;
67 std::shared_ptr<ApduRequestAdapter> apduRequest;
69 if (!calypsoCard->isCounterValuePostponed()) {
71 apduRequest = std::make_shared<ApduRequestAdapter>(
80 apduRequest = std::make_shared<ApduRequestAdapter>(
87 apduRequest->addSuccessfulStatusWord(SW_POSTPONED_DATA);
92 std::stringstream extraInfo;
93 extraInfo <<
"SFI:" << sfi <<
"h, "
94 <<
"COUNTER:" << mCounterNumber <<
", ";
95 if (isDecreaseCommand) {
96 extraInfo <<
"DECREMENT";
98 extraInfo <<
"INCREMENT";
100 extraInfo <<
":" << incDecValue;
106 const std::shared_ptr<ApduResponseApi> apduResponse)
110 if (apduResponse->getStatusWord() == SW_POSTPONED_DATA) {
116 std::make_shared<int>(SW_POSTPONED_DATA));
120 getCalypsoCard()->setCounter(mSfi, mCounterNumber, mComputedData);
125 getCalypsoCard()->setCounter(mSfi, mCounterNumber, apduResponse->getDataOut());
131 mComputedData = data;
146 return mCounterNumber;
154const std::map<const int, const std::shared_ptr<StatusProperties>>
155 CmdCardIncreaseOrDecrease::initStatusTable()
157 std::map<const int, const std::shared_ptr<StatusProperties>> m =
161 std::make_shared<StatusProperties>(
"Too many modifications in session.",
164 std::make_shared<StatusProperties>(
"Lc value not supported.",
165 typeid(CardIllegalParameterException))});
167 std::make_shared<StatusProperties>(
"The current EF is not a Counters or Simulated " \
169 typeid(CardDataAccessException))});
171 std::make_shared<StatusProperties>(
"Security conditions not fulfilled (no session, " \
172 "wrong key, encryption required).",
173 typeid(CardSecurityContextException))});
175 std::make_shared<StatusProperties>(
"Access forbidden (Never access mode, DF is " \
176 "invalidated, etc.)",
177 typeid(CardAccessForbiddenException))});
179 std::make_shared<StatusProperties>(
"Command not allowed (no current EF).",
180 typeid(CardDataAccessException))});
182 std::make_shared<StatusProperties>(
"Overflow error.",
183 typeid(CardDataOutOfBoundsException))});
185 std::make_shared<StatusProperties>(
"File not found.",
186 typeid(CardDataAccessException))});
188 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
189 typeid(CardDataAccessException))});
191 std::make_shared<StatusProperties>(
"Successful execution (possible only in ISO7816 " \
194 m.insert({SW_POSTPONED_DATA,
195 std::make_shared<StatusProperties>(
"Successful execution, response data postponed " \
196 "until session closing.",
202const std::map<const int, const std::shared_ptr<StatusProperties>>&
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
virtual void setExpectedResponseLength(const int expectedResponseLength) final
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const CalypsoCardCommand & getCommandRef() const override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
void setComputedData(const std::vector< uint8_t > &data)
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
bool isSessionBufferUsed() const override
CmdCardIncreaseOrDecrease(const bool isDecreaseCommand, const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t sfi, const uint8_t counterValue, const int incDecValue)
uint8_t getCounterNumber() const
int getIncDecValue() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override