Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardAppendRecord.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 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
40 const uint8_t sfi,
41 const std::vector<uint8_t>& newRecordData)
42: AbstractCardCommand(mCommand), mSfi(sfi), mData(newRecordData)
43
44{
45
46 const uint8_t cla = calypsoCardClass.getValue();
47 const uint8_t p1 = 0x00;
48 const uint8_t p2 = (sfi == 0) ? 0x00 : sfi * 8;
49
51 std::make_shared<ApduRequestAdapter>(
52 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, newRecordData)));
53
54 std::stringstream extraInfo;
55 extraInfo << "SFI:" << sfi << "h";
56
57 addSubName(extraInfo.str());
58}
59
61{
62 return true;
63}
64
66{
67 return mSfi;
68}
69
70const std::vector<uint8_t>& CmdCardAppendRecord::getData() const
71{
72 return mData;
73}
74
75const std::map<const int, const std::shared_ptr<StatusProperties>>
76 CmdCardAppendRecord::initStatusTable()
77{
78 std::map<const int, const std::shared_ptr<StatusProperties>> m =
80
81 m.insert({0x6B00,
82 std::make_shared<StatusProperties>("P1 or P2 value not supported.",
84 m.insert({0x6700,
85 std::make_shared<StatusProperties>("Lc value not supported.",
86 typeid(CardDataAccessException))});
87 m.insert({0x6400,
88 std::make_shared<StatusProperties>("Too many modifications in session.",
89 typeid(CardSessionBufferOverflowException))});
90 m.insert({0x6981,
91 std::make_shared<StatusProperties>("The current EF is not a Cyclic EF.",
92 typeid(CardDataAccessException))});
93 m.insert({0x6982,
94 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
95 "wrong key).",
96 typeid(CardSecurityContextException))});
97 m.insert({0x6985,
98 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
99 "invalidated, etc..).",
100 typeid(CardAccessForbiddenException))});
101 m.insert({0x6986,
102 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
103 typeid(CardDataAccessException))});
104 m.insert({0x6A82,
105 std::make_shared<StatusProperties>("File not found.",
106 typeid(CardDataAccessException))});
107
108 return m;
109}
110
111const std::map<const int, const std::shared_ptr<StatusProperties>>&
113{
114 return STATUS_TABLE;
115}
116
117}
118}
119}
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
static const CalypsoCardCommand APPEND_RECORD
CmdCardAppendRecord(const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const std::vector< uint8_t > &newRecordData)
const std::vector< uint8_t > & getData() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override