19#include "ByteArrayUtil.h"
20#include "IllegalStateException.h"
38using namespace keyple::core::util;
41const std::map<const int, const std::shared_ptr<StatusProperties>>
42 CmdCardSvGet::STATUS_TABLE = initStatusTable();
45 const SvOperation svOperation,
46 const bool useExtendedMode)
53 const uint8_t p1 = useExtendedMode ? 0x01 : 0x00;
54 const uint8_t p2 = svOperation == SvOperation::RELOAD ? 0x07 : 0x09;
57 std::make_shared<ApduRequestAdapter>(
61 ss <<
"OPERATION:" << svOperation;
64 mHeader = std::vector<uint8_t>(4);
80 const std::vector<uint8_t> cardResponse = apduResponse->getDataOut();
82 switch (cardResponse.size()) {
85 mChallengeOut = std::vector<uint8_t>(2);
86 mPreviousSignatureLo = std::vector<uint8_t>(3);
87 mCurrentKVC = cardResponse[0];
88 mTransactionNumber = ByteArrayUtil::extractInt(cardResponse, 1, 2,
false);
89 System::arraycopy(cardResponse, 3, mPreviousSignatureLo, 0, 3);
90 mChallengeOut[0] = cardResponse[6];
91 mChallengeOut[1] = cardResponse[7];
92 mBalance = ByteArrayUtil::extractInt(cardResponse, 8, 3,
true);
93 if (cardResponse.size() == 0x21) {
95 mLoadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 11);
100 mDebitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 11);
104 mChallengeOut = std::vector<uint8_t>(8);
105 mPreviousSignatureLo = std::vector<uint8_t>(6);
106 System::arraycopy(cardResponse, 0, mChallengeOut, 0, 8);
107 mCurrentKVC = cardResponse[8];
108 mTransactionNumber = ByteArrayUtil::extractInt(cardResponse, 9, 2,
false);
109 System::arraycopy(cardResponse, 11, mPreviousSignatureLo, 0, 6);
110 mBalance = ByteArrayUtil::extractInt(cardResponse, 17, 3,
true);
111 mLoadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 20);
112 mDebitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 42);
115 throw IllegalStateException(
"Incorrect data length in response to SVGet");
133 return mTransactionNumber;
138 return mPreviousSignatureLo;
143 return mChallengeOut;
161const std::map<const int, const std::shared_ptr<StatusProperties>>
162 CmdCardSvGet::initStatusTable()
164 std::map<const int, const std::shared_ptr<StatusProperties>> m =
168 std::make_shared<StatusProperties>(
"Security conditions not fulfilled.",
171 std::make_shared<StatusProperties>(
"Preconditions not satisfied (a store value " \
172 "operation was already done in the current " \
174 typeid(CalypsoSamAccessForbiddenException))});
176 std::make_shared<StatusProperties>(
"Incorrect P1 or P2.",
177 typeid(CardIllegalParameterException))});
179 std::make_shared<StatusProperties>(
"Le inconsistent with P2.",
180 typeid(CardIllegalParameterException))});
182 std::make_shared<StatusProperties>(
"SV function not present.",
183 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
AbstractCardCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
static const CalypsoCardClass LEGACY
static const CalypsoCardClass ISO
static const CalypsoCardClass LEGACY_STORED_VALUE
static const CalypsoCardCommand SV_GET
uint8_t getInstructionByte() const
const std::shared_ptr< SvLoadLogRecord > getLoadLog() const
bool isSessionBufferUsed() const override
const std::shared_ptr< SvDebitLogRecord > getDebitLog() const
int getTransactionNumber() const
uint8_t getCurrentKVC() const
const std::vector< uint8_t > & getChallengeOut() const
const std::vector< uint8_t > & getSvGetCommandHeader() const
const std::vector< uint8_t > & getPreviousSignatureLo() const
CmdCardSvGet(const CalypsoCardClass calypsoCardClass, const SvOperation svOperation, const bool useExtendedMode)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdCardSvGet & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override