33using namespace keyple::core::util;
34using namespace keyple::core::util::cpp;
36const std::map<const int, const std::shared_ptr<StatusProperties>>
37 CmdCardIncreaseOrDecreaseMultiple::STATUS_TABLE = initStatusTable();
40 const bool isDecreaseCommand,
43 const std::map<const int, const int> counterNumberToIncDecValueMap)
48 mCounterNumberToIncDecValueMap(counterNumberToIncDecValueMap)
51 const uint8_t p2 = sfi * 8;
52 std::vector<uint8_t> dataIn(4 * counterNumberToIncDecValueMap.size());
55 for (
const auto& entry : counterNumberToIncDecValueMap) {
56 dataIn[index] =
static_cast<uint8_t
>(entry.first);
57 const int incDecValue = entry.second;
58 dataIn[index + 1] = ((incDecValue >> 16) & 0xFF);
59 dataIn[index + 2] = ((incDecValue >> 8) & 0xFF);
60 dataIn[index + 3] = (incDecValue & 0xFF);
65 std::make_shared<ApduRequestAdapter>(
66 ApduUtil::build(calypsoCardClass.
getValue(),
73 std::stringstream extraInfo;
74 extraInfo <<
"SFI:" << sfi <<
"h";
75 for (
const auto& entry : counterNumberToIncDecValueMap) {
76 extraInfo <<
", " << entry.first <<
":" << entry.second;
87const std::map<const int, const std::shared_ptr<StatusProperties>>
88 CmdCardIncreaseOrDecreaseMultiple::initStatusTable()
90 std::map<const int, const std::shared_ptr<StatusProperties>> m =
94 std::make_shared<StatusProperties>(
"Too many modifications in session.",
97 std::make_shared<StatusProperties>(
"Lc value not supported.",
98 typeid(CardIllegalParameterException))});
100 std::make_shared<StatusProperties>(
"Incorrect EF type: not a Counters EF.",
101 typeid(CardDataAccessException))});
103 std::make_shared<StatusProperties>(
"Security conditions not fulfilled (no secure " \
104 "session, incorrect key, encryption required, " \
105 "PKI mode and not Always access mode).",
106 typeid(CardSecurityContextException))});
108 std::make_shared<StatusProperties>(
"Access forbidden (Never access mode, DF is " \
110 typeid(CardAccessForbiddenException))});
112 std::make_shared<StatusProperties>(
"Incorrect file type: the Current File is not " \
113 "an EF. Supersedes 6981h.",
114 typeid(CardDataAccessException))});
116 std::make_shared<StatusProperties>(
"Incorrect command data (Overflow error, " \
117 "Incorrect counter number, Counter number " \
118 "present more than once).",
119 typeid(CardIllegalParameterException))});
121 std::make_shared<StatusProperties>(
"File not found.",
122 typeid(CardDataAccessException))});
124 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
125 typeid(CardIllegalParameterException))});
130const std::map<const int, const std::shared_ptr<StatusProperties>>&
137 const std::shared_ptr<ApduResponseApi> apduResponse)
141 if (apduResponse->getDataOut().size() > 0) {
142 const std::vector<uint8_t> dataOut = apduResponse->getDataOut();
143 const int nbCounters =
static_cast<int>(dataOut.size() / 4);
144 for (
int i = 0; i < nbCounters; i++) {
145 mNewCounterValues.insert({dataOut[i * 4],
146 Arrays::copyOfRange(dataOut, (i * 4) + 1, (i * 4) + 4)});
158const std::map<const int, const int>&
161 return mCounterNumberToIncDecValueMap;
164const std::map<const uint8_t, const std::vector<uint8_t>>&
167 return mNewCounterValues;
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
const CalypsoCardCommand & getCommandRef() const override
AbstractCardCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
CmdCardIncreaseOrDecreaseMultiple & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
CmdCardIncreaseOrDecreaseMultiple(const bool isDecreaseCommand, const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const std::map< const int, const int > counterNumberToIncDecValueMap)
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
const std::map< const uint8_t, const std::vector< uint8_t > > & getNewCounterValues() const