19#include "ByteArrayUtil.h"
20#include "IllegalStateException.h"
39using namespace keyple::core::util;
42const std::map<const int, const std::shared_ptr<StatusProperties>>
43 CmdCardSvGet::STATUS_TABLE = initStatusTable();
46 const SvOperation svOperation,
47 const bool useExtendedMode)
54 const uint8_t p1 = useExtendedMode ? 0x01 : 0x00;
55 const uint8_t p2 = svOperation == SvOperation::RELOAD ? 0x07 : 0x09;
58 if (useExtendedMode) {
61 if (svOperation == SvOperation::RELOAD) {
71 std::make_shared<ApduRequestAdapter>(
75 ss <<
"OPERATION:" << svOperation;
78 mHeader = std::vector<uint8_t>(4);
94 const std::vector<uint8_t> cardResponse = apduResponse->getDataOut();
96 uint8_t currentKvc = 0;
97 int transactionNumber = 0;
99 std::shared_ptr<SvLoadLogRecord> loadLog =
nullptr;
100 std::shared_ptr<SvDebitLogRecord> debitLog =
nullptr;
102 switch (cardResponse.size()) {
106 std::vector<uint8_t> challengeOut(2);
107 std::vector<uint8_t> previousSignatureLo = std::vector<uint8_t>(3);
108 currentKvc = cardResponse[0];
109 transactionNumber = ByteArrayUtil::extractInt(cardResponse, 1, 2,
false);
110 System::arraycopy(cardResponse, 3, previousSignatureLo, 0, 3);
111 challengeOut[0] = cardResponse[6];
112 challengeOut[1] = cardResponse[7];
113 balance = ByteArrayUtil::extractInt(cardResponse, 8, 3,
true);
115 if (cardResponse.size() == 0x21) {
118 loadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 11);
125 debitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 11);
132 std::vector<uint8_t> challengeOut(8);
133 std::vector<uint8_t> previousSignatureLo(6);
134 System::arraycopy(cardResponse, 0, challengeOut, 0, 8);
135 currentKvc = cardResponse[8];
136 transactionNumber = ByteArrayUtil::extractInt(cardResponse, 9, 2,
false);
137 System::arraycopy(cardResponse, 11, previousSignatureLo, 0, 6);
138 balance = ByteArrayUtil::extractInt(cardResponse, 17, 3,
true);
139 loadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 20);
140 debitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 42);
144 throw IllegalStateException(
"Incorrect data length in response to SVGet");
149 apduResponse->getApdu(),
156const std::map<const int, const std::shared_ptr<StatusProperties>>
157 CmdCardSvGet::initStatusTable()
159 std::map<const int, const std::shared_ptr<StatusProperties>> m =
163 std::make_shared<StatusProperties>(
"Security conditions not fulfilled.",
166 std::make_shared<StatusProperties>(
"Preconditions not satisfied (a store value " \
167 "operation was already done in the current " \
169 typeid(CalypsoSamAccessForbiddenException))});
171 std::make_shared<StatusProperties>(
"Incorrect P1 or P2.",
172 typeid(CardIllegalParameterException))});
174 std::make_shared<StatusProperties>(
"Le inconsistent with P2.",
175 typeid(CardIllegalParameterException))});
177 std::make_shared<StatusProperties>(
"SV function not present.",
178 typeid(CardIllegalParameterException))});
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
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
static const CalypsoCardClass LEGACY
static const CalypsoCardClass ISO
static const CalypsoCardClass LEGACY_STORED_VALUE
static const CalypsoCardCommand SV_GET
uint8_t getInstructionByte() const
CmdCardSvGet(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const SvOperation svOperation, const bool useExtendedMode)
bool isSessionBufferUsed() const override
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override