14#include "keyple/card/calypso/crypto/legacysam/CommandCardGenerateKey.hpp"
20#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
21#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/DtoAdapters.hpp"
23#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
24#include "keyple/card/calypso/crypto/legacysam/IncorrectInputDataException.hpp"
25#include "keyple/core/util/ApduUtil.hpp"
33using keyple::core::util::ApduUtil;
35const std::map<int, const std::shared_ptr<StatusProperties>>
36 CommandCardGenerateKey::STATUS_TABLE = [] {
37 std::map<int, const std::shared_ptr<StatusProperties>> m(
38 Command::STATUS_TABLE);
42 std::make_shared<StatusProperties>(
43 "Incorrect Lc",
typeid(IllegalParameterException))},
45 std::make_shared<StatusProperties>(
46 "Preconditions not satisfied",
47 typeid(AccessForbiddenException))},
49 std::make_shared<StatusProperties>(
50 "Incorrect P1 or P2",
typeid(IllegalParameterException))},
52 std::make_shared<StatusProperties>(
53 "Incorrect incoming data: unknown or incorrect format",
54 typeid(IncorrectInputDataException))},
56 std::make_shared<StatusProperties>(
57 "Record not found: ciphering key or key to cipher not found",
58 typeid(DataAccessException))}});
62CommandCardGenerateKey::CommandCardGenerateKey(
63 std::shared_ptr<DtoAdapters::CommandContextDto> context,
68: Command(CommandRef::CARD_GENERATE_KEY, 0, context)
70 const uint8_t cla = context->getTargetSam()->getClassByte();
74 std::vector<uint8_t> data;
76 if (cipheringKif == 0 && cipheringKvc == 0) {
91 data[0] = cipheringKif;
92 data[1] = cipheringKvc;
99 std::make_shared<ApduRequestAdapter>(core::util::ApduUtil::build(
100 cla, getCommandRef().getInstructionByte(), p1, p2, data)));
103const std::vector<uint8_t>&
104CommandCardGenerateKey::getCipheredData()
const
106 return mCipheredData;
110CommandCardGenerateKey::finalizeRequest()
116CommandCardGenerateKey::isControlSamRequiredToFinalizeRequest()
const
122CommandCardGenerateKey::parseResponse(
123 std::shared_ptr<ApduResponseApi> apduResponse)
125 setResponseAndCheckStatus(apduResponse);
126 mCipheredData = apduResponse->getDataOut();
129const std::map<int, const std::shared_ptr<StatusProperties>>&
130CommandCardGenerateKey::getStatusTable()
const