14#include "keyple/card/calypso/CommandAppendRecord.hpp"
21#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
22#include "keyple/card/calypso/CalypsoCardClass.hpp"
23#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
24#include "keyple/card/calypso/CardCommandRef.hpp"
25#include "keyple/card/calypso/CardDataAccessException.hpp"
26#include "keyple/card/calypso/CardIllegalParameterException.hpp"
27#include "keyple/card/calypso/CardSecurityContextException.hpp"
28#include "keyple/card/calypso/CardSessionBufferOverflowException.hpp"
29#include "keyple/core/util/ApduUtil.hpp"
30#include "keyple/core/util/HexUtil.hpp"
31#include "keyple/core/util/cpp/Arrays.hpp"
32#include "keyple/core/util/cpp/System.hpp"
38using keyple::core::util::ApduUtil;
39using keyple::core::util::HexUtil;
40using keyple::core::util::cpp::Arrays;
41using keyple::core::util::cpp::System;
43const std::map<int, const std::shared_ptr<Command::StatusProperties>>
44 CommandAppendRecord::STATUS_TABLE = [] {
45 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
46 Command::STATUS_TABLE);
50 std::make_shared<Command::StatusProperties>(
51 "P1 or P2 value not supported",
52 typeid(CardIllegalParameterException))},
54 std::make_shared<Command::StatusProperties>(
55 "Lc value not supported",
typeid(CardDataAccessException))},
57 std::make_shared<Command::StatusProperties>(
58 "Too many modifications in session",
59 typeid(CardSessionBufferOverflowException))},
61 std::make_shared<Command::StatusProperties>(
62 "The current EF is not a Cyclic EF",
63 typeid(CardDataAccessException))},
65 std::make_shared<Command::StatusProperties>(
66 "Security conditions not fulfilled (no session, wrong key)",
67 typeid(CardSecurityContextException))},
69 std::make_shared<Command::StatusProperties>(
70 "Access forbidden (Never access mode, DF is invalidated, "
72 typeid(CardAccessForbiddenException))},
74 std::make_shared<Command::StatusProperties>(
75 "Command not allowed (no current EF)",
76 typeid(CardDataAccessException))},
78 std::make_shared<Command::StatusProperties>(
79 "File not found",
typeid(CardDataAccessException))}});
83CommandAppendRecord::CommandAppendRecord(
84 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
86 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
88 const std::vector<std::uint8_t>& data)
90 CardCommandRef::APPEND_RECORD,
91 std::unique_ptr<int>(new int(0)),
97 const std::uint8_t p1 = 0x00;
99 =
static_cast<std::uint8_t
>((sfi == 0) ? 0x00 : (sfi * 8));
103 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
104 transactionContext->getCard()->getCardClass().getValue(),
105 getCommandRef().getInstructionByte(),
111 std::string(
"SFI: ") + HexUtil::toHex(
static_cast<std::uint8_t
>(sfi))
116CommandAppendRecord::finalizeRequest()
118 encryptRequestAndUpdateTerminalSessionMacIfNeeded();
122CommandAppendRecord::isCryptoServiceRequiredToFinalizeRequest()
const
124 return getCommandContext()->isEncryptionActive();
128CommandAppendRecord::synchronizeCryptoServiceBeforeCardProcessing()
130 if (getCommandContext()->isEncryptionActive()) {
134 updateTerminalSessionIfNeeded(APDU_RESPONSE_9000);
140CommandAppendRecord::parseResponse(
141 std::shared_ptr<ApduResponseApi> apduResponse)
143 decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
144 Command::setApduResponseAndCheckStatus(apduResponse);
145 getTransactionContext()->getCard()->addCyclicContent(
146 static_cast<std::uint8_t
>(mSfi), mData);
147 updateTerminalSessionIfNeeded();
150const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
151CommandAppendRecord::getStatusTable()
const