15#include "keyple/card/calypso/crypto/legacysam/CommandSvPrepareDebitOrUndebit.hpp"
21#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
23#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
24#include "keyple/card/calypso/crypto/legacysam/IncorrectInputDataException.hpp"
25#include "keyple/card/calypso/crypto/legacysam/LegacySamConstants.hpp"
26#include "keyple/card/calypso/crypto/legacysam/SecurityDataException.hpp"
27#include "keyple/core/util/ApduUtil.hpp"
28#include "keyple/core/util/ByteArrayUtil.hpp"
29#include "keyple/core/util/cpp/Arrays.hpp"
30#include "keyple/core/util/cpp/System.hpp"
31#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
32#include "keypop/calypso/crypto/legacysam/transaction/InvalidSignatureException.hpp"
40using keyple::core::util::ApduUtil;
41using keyple::core::util::ByteArrayUtil;
42using keyple::core::util::cpp::Arrays;
43using keyple::core::util::cpp::System;
44using keyple::core::util::cpp::exception::IllegalArgumentException;
45using keypop::calypso::crypto::legacysam::transaction::
46 InvalidSignatureException;
48const std::map<int, const std::shared_ptr<StatusProperties>>
49 CommandSvPrepareDebitOrUndebit::STATUS_TABLE = [] {
50 std::map<int, const std::shared_ptr<StatusProperties>> m(
51 Command::STATUS_TABLE);
55 std::make_shared<StatusProperties>(
56 "Incorrect Lc",
typeid(IllegalParameterException))},
58 std::make_shared<StatusProperties>(
59 "Preconditions not satisfied",
60 typeid(AccessForbiddenException))},
62 std::make_shared<StatusProperties>(
63 "Incorrect P1 or P2",
typeid(IllegalParameterException))},
65 std::make_shared<StatusProperties>(
66 "Incorrect incoming data",
67 typeid(IncorrectInputDataException))},
69 std::make_shared<StatusProperties>(
70 "Record not found: ciphering key not found",
71 typeid(DataAccessException))}});
75CommandSvPrepareDebitOrUndebit::CommandSvPrepareDebitOrUndebit(
76 std::shared_ptr<CommandContextDto> context,
77 std::shared_ptr<SvCommandSecurityDataApi> data)
79 data->getSvCommandPartialRequest()[0] == 0xBA
80 ? CommandRef::SV_PREPARE_DEBIT
81 : CommandRef::SV_PREPARE_UNDEBIT,
86 const std::uint8_t cla = context->getTargetSam()->getClassByte();
87 const std::uint8_t inst = getCommandRef().getInstructionByte();
88 const std::uint8_t p1 = 0x01;
89 const std::uint8_t p2 = 0xFF;
92 std::vector<std::uint8_t> dataIn(16 + data->getSvGetResponse().size());
94 System::arraycopy(data->getSvGetRequest(), 0, dataIn, 0, 4);
96 data->getSvGetResponse(),
100 data->getSvGetResponse().size());
102 data->getSvCommandPartialRequest(),
105 4 + data->getSvGetResponse().size(),
106 data->getSvCommandPartialRequest().size());
109 std::make_shared<ApduRequestAdapter>(
110 ApduUtil::build(cla, inst, p1, p2, dataIn)));
114CommandSvPrepareDebitOrUndebit::finalizeRequest()
120CommandSvPrepareDebitOrUndebit::isControlSamRequiredToFinalizeRequest()
const
126CommandSvPrepareDebitOrUndebit::parseResponse(
127 std::shared_ptr<ApduResponseApi> apduResponse)
129 setResponseAndCheckStatus(apduResponse);
130 const std::vector<std::uint8_t> dataOut = apduResponse->getDataOut();
131 mData->setSerialNumber(getContext()->getTargetSam()->getSerialNumber())
132 .setTerminalChallenge(Arrays::copyOfRange(dataOut, 0, 3))
133 .setTransactionNumber(Arrays::copyOfRange(dataOut, 3, 6))
134 .setTerminalSvMac(Arrays::copyOfRange(dataOut, 6, dataOut.size()));
137const std::map<int, const std::shared_ptr<StatusProperties>>&
138CommandSvPrepareDebitOrUndebit::getStatusTable()
const