Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdCardAppendRecord.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2023 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#include "CmdCardAppendRecord.h"
14
15#include <sstream>
16
17/* Keyple Card Calypso */
23
24/* Keyple Core Util */
25#include "ApduUtil.h"
26#include "Arrays.h"
27
28namespace keyple {
29namespace card {
30namespace calypso {
31
32using namespace keyple::core::util;
33using namespace keyple::core::util::cpp;
34
35const CalypsoCardCommand CmdCardAppendRecord::mCommand = CalypsoCardCommand::APPEND_RECORD;
36const std::map<const int, const std::shared_ptr<StatusProperties>>
37 CmdCardAppendRecord::STATUS_TABLE = initStatusTable();
38
39CmdCardAppendRecord::CmdCardAppendRecord(const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
40 const uint8_t sfi,
41 const std::vector<uint8_t>& newRecordData)
42: AbstractCardCommand(mCommand, 0, calypsoCard), mSfi(sfi), mData(newRecordData)
43
44{
45
46 const uint8_t cla = calypsoCard->getCardClass().getValue();
47 const uint8_t p1 = 0x00;
48 const uint8_t p2 = (sfi == 0) ? 0x00 : sfi * 8;
49
50 // APDU Case 3
52 std::make_shared<ApduRequestAdapter>(
53 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, newRecordData)));
54
55 std::stringstream extraInfo;
56 extraInfo << "SFI:" << sfi << "h";
57
58 addSubName(extraInfo.str());
59}
60
61void CmdCardAppendRecord::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse)
62{
64
65 getCalypsoCard()->addCyclicContent(mSfi, mData);
66}
67
69{
70 return true;
71}
72
73const std::map<const int, const std::shared_ptr<StatusProperties>>
74 CmdCardAppendRecord::initStatusTable()
75{
76 std::map<const int, const std::shared_ptr<StatusProperties>> m =
78
79 m.insert({0x6B00,
80 std::make_shared<StatusProperties>("P1 or P2 value not supported.",
82 m.insert({0x6700,
83 std::make_shared<StatusProperties>("Lc value not supported.",
84 typeid(CardDataAccessException))});
85 m.insert({0x6400,
86 std::make_shared<StatusProperties>("Too many modifications in session.",
87 typeid(CardSessionBufferOverflowException))});
88 m.insert({0x6981,
89 std::make_shared<StatusProperties>("The current EF is not a Cyclic EF.",
90 typeid(CardDataAccessException))});
91 m.insert({0x6982,
92 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
93 "wrong key).",
94 typeid(CardSecurityContextException))});
95 m.insert({0x6985,
96 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
97 "invalidated, etc..).",
98 typeid(CardAccessForbiddenException))});
99 m.insert({0x6986,
100 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
101 typeid(CardDataAccessException))});
102 m.insert({0x6A82,
103 std::make_shared<StatusProperties>("File not found.",
104 typeid(CardDataAccessException))});
105
106 return m;
107}
108
109const std::map<const int, const std::shared_ptr<StatusProperties>>&
111{
112 return STATUS_TABLE;
113}
114
115}
116}
117}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual void addSubName(const std::string &subName) final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
static const CalypsoCardCommand APPEND_RECORD
CmdCardAppendRecord(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t sfi, const std::vector< uint8_t > &newRecordData)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override