15#include "keyple/card/calypso/CommandPutData.hpp"
23#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
24#include "keyple/card/calypso/CalypsoCardConstant.hpp"
25#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
26#include "keyple/card/calypso/CardDataAccessException.hpp"
27#include "keyple/card/calypso/CardIllegalParameterException.hpp"
28#include "keyple/card/calypso/CardSecurityContextException.hpp"
29#include "keyple/card/calypso/CardSecurityDataException.hpp"
30#include "keyple/card/calypso/CardSessionBufferOverflowException.hpp"
31#include "keyple/core/util/ApduUtil.hpp"
32#include "keyple/core/util/cpp/Arrays.hpp"
33#include "keyple/core/util/cpp/System.hpp"
34#include "keyple/core/util/cpp/exception/UnsupportedOperationException.hpp"
40using keyple::core::util::ApduUtil;
41using keyple::core::util::cpp::Arrays;
42using keyple::core::util::cpp::System;
43using keyple::core::util::cpp::exception::UnsupportedOperationException;
45const std::map<int, const std::shared_ptr<Command::StatusProperties>>
46 CommandPutData::STATUS_TABLE = [] {
47 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
48 Command::STATUS_TABLE);
52 std::make_shared<StatusProperties>(
53 "Too many modifications in session",
54 typeid(CardSessionBufferOverflowException))},
56 std::make_shared<StatusProperties>(
57 "Lc value not supported",
typeid(CardDataAccessException))},
59 std::make_shared<StatusProperties>(
60 "Security conditions not fulfilled",
61 typeid(CardSecurityContextException))},
63 std::make_shared<StatusProperties>(
64 "Access forbidden",
typeid(CardAccessForbiddenException))},
66 std::make_shared<StatusProperties>(
67 "Lc not compatible with P1P2",
68 typeid(CardIllegalParameterException))},
70 std::make_shared<StatusProperties>(
71 "Incorrect incoming data",
72 typeid(CardIllegalParameterException))},
74 std::make_shared<StatusProperties>(
75 "Data object not found",
typeid(CardDataAccessException))},
77 std::make_shared<StatusProperties>(
78 "Incorrect AID",
typeid(CardIllegalParameterException))},
80 std::make_shared<StatusProperties>(
81 "Incorrect P1, P2",
typeid(CardIllegalParameterException))},
83 std::make_shared<StatusProperties>(
84 "Command Put Data not supported",
85 typeid(CardIllegalParameterException))}});
89CommandPutData::CommandPutData(
90 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
92 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
95 const std::vector<std::uint8_t>& data)
96: Command(CardCommandRef::PUT_DATA, 0, transactionContext, commandContext)
99, mIsFirstPart(isFirstPart)
103 std::vector<std::uint8_t> dataIn;
106 case PutDataTag::CARD_KEY_PAIR:
107 tagMsb = CalypsoCardConstant::TAG_CARD_KEY_PAIR_MSB;
108 tagLsb = CalypsoCardConstant::TAG_CARD_KEY_PAIR_LSB;
111 case PutDataTag::CARD_CERTIFICATE:
112 tagMsb = CalypsoCardConstant::TAG_CARD_CERTIFICATE_MSB;
114 ? CalypsoCardConstant::TAG_CARD_CERTIFICATE_LSB
115 : CalypsoCardConstant::TAG_CARD_CERTIFICATE_LSB + 1;
117 dataIn = CalypsoCardConstant::TAG_CARD_CERTIFICATE_HEADER;
120 std::make_move_iterator(data.begin()),
121 std::make_move_iterator(data.end()));
126 case PutDataTag::CA_CERTIFICATE:
127 tagMsb = CalypsoCardConstant::TAG_CA_CERTIFICATE_MSB;
128 tagLsb = isFirstPart ? CalypsoCardConstant::TAG_CA_CERTIFICATE_LSB
129 : CalypsoCardConstant::TAG_CA_CERTIFICATE_LSB + 1;
131 dataIn = CalypsoCardConstant::TAG_CA_CERTIFICATE_HEADER;
134 std::make_move_iterator(data.begin()),
135 std::make_move_iterator(data.end()));
141 throw UnsupportedOperationException(
142 "Unsupported PutDataTag: " + std::to_string(
static_cast<int>(tag)));
147 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
148 getTransactionContext()->getCard()->getCardClass().getValue(),
149 getCommandRef().getInstructionByte(),
156CommandPutData::finalizeRequest()
162CommandPutData::isCryptoServiceRequiredToFinalizeRequest()
const
168CommandPutData::synchronizeCryptoServiceBeforeCardProcessing()
174CommandPutData::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
176 Command::setApduResponseAndCheckStatus(apduResponse);
178 if (mTag == PutDataTag::CARD_KEY_PAIR) {
179 getTransactionContext()->getCard()->setCardPublicKey(
180 Arrays::copyOf(mData, CalypsoCardConstant::CARD_PUBLIC_KEY_SIZE));
182 }
else if (mTag == PutDataTag::CARD_CERTIFICATE) {
183 getTransactionContext()->getCard()->addCardCertificateBytes(
184 mData, mIsFirstPart);
186 }
else if (mTag == PutDataTag::CA_CERTIFICATE) {
187 getTransactionContext()->getCard()->addCaCertificateBytes(
188 mData, mIsFirstPart);
192const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
193CommandPutData::getStatusTable()
const