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)
47 mCounterNumberToIncDecValueMap(counterNumberToIncDecValueMap)
50 const uint8_t p2 = sfi * 8;
51 std::vector<uint8_t> dataIn(4 * counterNumberToIncDecValueMap.size());
54 for (
const auto& entry : counterNumberToIncDecValueMap) {
55 dataIn[index] =
static_cast<uint8_t
>(entry.first);
56 const int incDecValue = entry.second;
57 dataIn[index + 1] = ((incDecValue >> 16) & 0xFF);
58 dataIn[index + 2] = ((incDecValue >> 8) & 0xFF);
59 dataIn[index + 3] = (incDecValue & 0xFF);
64 std::make_shared<ApduRequestAdapter>(
65 ApduUtil::build(calypsoCardClass.
getValue(),
72 std::stringstream extraInfo;
73 extraInfo <<
"SFI:" << sfi <<
"h";
74 for (
const auto& entry : counterNumberToIncDecValueMap) {
75 extraInfo <<
", " << entry.first <<
":" << entry.second;
86const std::map<const int, const std::shared_ptr<StatusProperties>>
87 CmdCardIncreaseOrDecreaseMultiple::initStatusTable()
89 std::map<const int, const std::shared_ptr<StatusProperties>> m =
93 std::make_shared<StatusProperties>(
"Too many modifications in session.",
96 std::make_shared<StatusProperties>(
"Lc value not supported.",
97 typeid(CardIllegalParameterException))});
99 std::make_shared<StatusProperties>(
"Incorrect EF type: not a Counters EF.",
100 typeid(CardDataAccessException))});
102 std::make_shared<StatusProperties>(
"Security conditions not fulfilled (no secure " \
103 "session, incorrect key, encryption required, " \
104 "PKI mode and not Always access mode).",
105 typeid(CardSecurityContextException))});
107 std::make_shared<StatusProperties>(
"Access forbidden (Never access mode, DF is " \
109 typeid(CardAccessForbiddenException))});
111 std::make_shared<StatusProperties>(
"Incorrect file type: the Current File is not " \
112 "an EF. Supersedes 6981h.",
113 typeid(CardDataAccessException))});
115 std::make_shared<StatusProperties>(
"Incorrect command data (Overflow error, " \
116 "Incorrect counter number, Counter number " \
117 "present more than once).",
118 typeid(CardIllegalParameterException))});
120 std::make_shared<StatusProperties>(
"File not found.",
121 typeid(CardDataAccessException))});
123 std::make_shared<StatusProperties>(
"P1 or P2 value not supported.",
124 typeid(CardIllegalParameterException))});
129const std::map<const int, const std::shared_ptr<StatusProperties>>&
136 const std::shared_ptr<ApduResponseApi> apduResponse)
140 if (apduResponse->getDataOut().size() > 0) {
141 const std::vector<uint8_t> dataOut = apduResponse->getDataOut();
142 const int nbCounters =
static_cast<int>(dataOut.size() / 4);
143 for (
int i = 0; i < nbCounters; i++) {
144 mNewCounterValues.insert({dataOut[i * 4],
145 Arrays::copyOfRange(dataOut, (i * 4) + 1, (i * 4) + 4)});
157const std::map<const int, const int>&
160 return mCounterNumberToIncDecValueMap;
163const std::map<const uint8_t, const std::vector<uint8_t>>&
166 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