15#include "keyple/card/calypso/crypto/legacysam/CommandSvPrepareLoad.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 CommandSvPrepareLoad::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))}});
75CommandSvPrepareLoad::CommandSvPrepareLoad(
76 std::shared_ptr<CommandContextDto> context,
77 std::shared_ptr<SvCommandSecurityDataApi> data)
78: Command(CommandRef::SV_PREPARE_LOAD, 0, context)
81 const std::uint8_t cla = context->getTargetSam()->getClassByte();
82 const std::uint8_t inst = getCommandRef().getInstructionByte();
83 const std::uint8_t p1 = 0x01;
84 const std::uint8_t p2 = 0xFF;
87 std::vector<std::uint8_t> dataIn(19 + data->getSvGetResponse().size());
89 System::arraycopy(data->getSvGetRequest(), 0, dataIn, 0, 4);
91 data->getSvGetResponse(),
95 data->getSvGetResponse().size());
97 data->getSvCommandPartialRequest(),
100 4 + data->getSvGetResponse().size(),
101 data->getSvCommandPartialRequest().size());
104 std::make_shared<ApduRequestAdapter>(
105 ApduUtil::build(cla, inst, p1, p2, dataIn)));
109CommandSvPrepareLoad::finalizeRequest()
115CommandSvPrepareLoad::isControlSamRequiredToFinalizeRequest()
const
121CommandSvPrepareLoad::parseResponse(
122 std::shared_ptr<ApduResponseApi> apduResponse)
124 setResponseAndCheckStatus(apduResponse);
125 const std::vector<std::uint8_t> dataOut = apduResponse->getDataOut();
126 mData->setSerialNumber(getContext()->getTargetSam()->getSerialNumber())
127 .setTerminalChallenge(Arrays::copyOfRange(dataOut, 0, 3))
128 .setTransactionNumber(Arrays::copyOfRange(dataOut, 3, 6))
129 .setTerminalSvMac(Arrays::copyOfRange(dataOut, 6, dataOut.size()));
132const std::map<int, const std::shared_ptr<StatusProperties>>&
133CommandSvPrepareLoad::getStatusTable()
const