14#include "keyple/card/calypso/CommandUpdateRecord.hpp"
22#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
23#include "keyple/card/calypso/CalypsoCardClass.hpp"
24#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
25#include "keyple/card/calypso/CardCommandRef.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/CardSessionBufferOverflowException.hpp"
30#include "keyple/core/util/ApduUtil.hpp"
31#include "keyple/core/util/HexUtil.hpp"
32#include "keyple/core/util/cpp/Arrays.hpp"
33#include "keyple/core/util/cpp/System.hpp"
39using keyple::core::util::ApduUtil;
40using keyple::core::util::HexUtil;
41using keyple::core::util::cpp::Arrays;
42using keyple::core::util::cpp::System;
44const std::map<int, const std::shared_ptr<Command::StatusProperties>>
45 CommandUpdateRecord::STATUS_TABLE = [] {
46 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
47 Command::STATUS_TABLE);
51 std::make_shared<Command::StatusProperties>(
52 "Too many modifications in session",
53 typeid(CardSessionBufferOverflowException))},
55 std::make_shared<Command::StatusProperties>(
56 "Lc value not supported",
typeid(CardDataAccessException))},
58 std::make_shared<Command::StatusProperties>(
59 "Command forbidden on cyclic files when the record exists "
61 "is not record 01h and on binary files",
62 typeid(CardDataAccessException))},
64 std::make_shared<Command::StatusProperties>(
65 "Security conditions not fulfilled (no session, wrong key, "
66 "encryption required)",
67 typeid(CardSecurityContextException))},
69 std::make_shared<Command::StatusProperties>(
70 "Access forbidden (Never access mode, DF is invalidated, "
72 typeid(CardSecurityContextException))},
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))},
81 std::make_shared<Command::StatusProperties>(
82 "Record is not found (record index is 0 or above NumRec)",
83 typeid(CardDataAccessException))},
85 std::make_shared<Command::StatusProperties>(
86 "P2 value not supported",
87 typeid(CardIllegalParameterException))}});
91CommandUpdateRecord::CommandUpdateRecord(
92 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
94 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
96 std::uint8_t recordNumber,
97 const std::vector<uint8_t>& newRecordData)
99 CardCommandRef::UPDATE_RECORD,
100 std::unique_ptr<int>(new int(0)),
104, mRecordNumber(recordNumber)
105, mData(newRecordData)
107 const std::uint8_t p2 = (sfi == 0) ? 0x04 : sfi * 8 + 4;
111 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
112 transactionContext->getCard()->getCardClass().getValue(),
113 getCommandRef().getInstructionByte(),
118 std::stringstream extraInfo;
119 extraInfo <<
"SFI:" << sfi <<
"h, "
120 <<
"REC:" << recordNumber;
122 addSubName(extraInfo.str());
126CommandUpdateRecord::finalizeRequest()
128 encryptRequestAndUpdateTerminalSessionMacIfNeeded();
132CommandUpdateRecord::isCryptoServiceRequiredToFinalizeRequest()
const
134 return getCommandContext()->isEncryptionActive();
138CommandUpdateRecord::synchronizeCryptoServiceBeforeCardProcessing()
140 if (getCommandContext()->isEncryptionActive()) {
144 updateTerminalSessionIfNeeded(APDU_RESPONSE_9000);
150CommandUpdateRecord::parseResponse(
151 std::shared_ptr<ApduResponseApi> apduResponse)
153 decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
154 Command::setApduResponseAndCheckStatus(apduResponse);
155 getTransactionContext()->getCard()->setContent(mSfi, mRecordNumber, mData);
156 updateTerminalSessionIfNeeded();
159const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
160CommandUpdateRecord::getStatusTable()
const