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 std::shared_ptr<CalypsoCard> calypsoCard,
46 const SvOperation svOperation)
54 const uint8_t p1 = calypsoCard->isExtendedModeSupported() ? 0x01 : 0x00;
55 const uint8_t p2 = svOperation == SvOperation::RELOAD ? 0x07 : 0x09;
58 std::make_shared<ApduRequestAdapter>(
62 ss <<
"OPERATION:" << svOperation;
65 mHeader = std::vector<uint8_t>(4);
81 const std::vector<uint8_t> cardResponse = apduResponse->getDataOut();
83 switch (cardResponse.size()) {
86 mChallengeOut = std::vector<uint8_t>(2);
87 mPreviousSignatureLo = std::vector<uint8_t>(3);
88 mCurrentKVC = cardResponse[0];
89 mTransactionNumber = ByteArrayUtil::twoBytesToInt(cardResponse, 1);
90 System::arraycopy(cardResponse, 3, mPreviousSignatureLo, 0, 3);
91 mChallengeOut[0] = cardResponse[6];
92 mChallengeOut[1] = cardResponse[7];
93 mBalance = ByteArrayUtil::threeBytesSignedToInt(cardResponse, 8);
94 if (cardResponse.size() == 0x21) {
96 mLoadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 11);
101 mDebitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 11);
105 mChallengeOut = std::vector<uint8_t>(8);
106 mPreviousSignatureLo = std::vector<uint8_t>(6);
107 System::arraycopy(cardResponse, 0, mChallengeOut, 0, 8);
108 mCurrentKVC = cardResponse[8];
109 mTransactionNumber = ByteArrayUtil::twoBytesToInt(cardResponse, 9);
110 System::arraycopy(cardResponse, 11, mPreviousSignatureLo, 0, 6);
111 mBalance = ByteArrayUtil::threeBytesSignedToInt(cardResponse, 17);
112 mLoadLog = std::make_shared<SvLoadLogRecordAdapter>(cardResponse, 20);
113 mDebitLog = std::make_shared<SvDebitLogRecordAdapter>(cardResponse, 42);
116 throw IllegalStateException(
"Incorrect data length in response to SVGet");
134 return mTransactionNumber;
139 return mPreviousSignatureLo;
144 return mChallengeOut;
162const std::map<const int, const std::shared_ptr<StatusProperties>>
163 CmdCardSvGet::initStatusTable()
165 std::map<const int, const std::shared_ptr<StatusProperties>> m =
169 std::make_shared<StatusProperties>(
"Security conditions not fulfilled.",
172 std::make_shared<StatusProperties>(
"Preconditions not satisfied (a store value " \
173 "operation was already done in the current " \
175 typeid(CalypsoSamAccessForbiddenException))});
177 std::make_shared<StatusProperties>(
"Incorrect P1 or P2.",
178 typeid(CardIllegalParameterException))});
180 std::make_shared<StatusProperties>(
"Le inconsistent with P2.",
181 typeid(CardIllegalParameterException))});
183 std::make_shared<StatusProperties>(
"SV function not present.",
184 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
CmdCardSvGet(const CalypsoCardClass calypsoCardClass, const std::shared_ptr< CalypsoCard > calypsoCard, const SvOperation svOperation)
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
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdCardSvGet & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override