Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdSamSvPrepareDebitOrUndebit.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 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
14
15/* Keyple Card Calypso */
16#include "CalypsoCardAdapter.h"
17#include "CalypsoCardClass.h"
24#include "SamUtilAdapter.h"
25
26/* Keyple Core Util */
27#include "ApduUtil.h"
28#include "IllegalArgumentException.h"
29#include "IllegalStateException.h"
30#include "System.h"
31
32namespace keyple {
33namespace card {
34namespace calypso {
35
36using namespace keyple::core::util;
37using namespace keyple::core::util::cpp;
38using namespace keyple::core::util::cpp::exception;
39
40const std::map<const int, const std::shared_ptr<StatusProperties>>
41 CmdSamSvPrepareDebitOrUndebit::STATUS_TABLE = initStatusTable();
42
44 const bool isDebitCommand,
45 const CalypsoSam::ProductType productType,
46 const std::vector<uint8_t>& svGetHeader,
47 const std::vector<uint8_t>& svGetData,
48 const std::vector<uint8_t>& svDebitOrUndebitCmdBuildData)
49: AbstractSamCommand(isDebitCommand ? CalypsoSamCommand::SV_PREPARE_DEBIT :
50 CalypsoSamCommand::SV_PREPARE_UNDEBIT,
51 0)
52{
53 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
54 const uint8_t p1 = 0x01;
55 const uint8_t p2 = 0xFF;
56 std::vector<uint8_t> data(16 + svGetData.size()); /* Header(4) + SvUndebit data (12) = 16 bytes*/
57
58 System::arraycopy(svGetHeader, 0, data, 0, 4);
59 System::arraycopy(svGetData, 0, data, 4, svGetData.size());
60 System::arraycopy(svDebitOrUndebitCmdBuildData,
61 0,
62 data,
63 4 + svGetData.size(),
64 svDebitOrUndebitCmdBuildData.size());
65
67 std::make_shared<ApduRequestAdapter>(
68 ApduUtil::build(cla, getCommandRef().getInstructionByte(), p1, p2, data)));
69}
70
71const std::map<const int, const std::shared_ptr<StatusProperties>>
72 CmdSamSvPrepareDebitOrUndebit::initStatusTable()
73{
74 std::map<const int, const std::shared_ptr<StatusProperties>> m =
76
77 m.insert({0x6700,
78 std::make_shared<StatusProperties>("Incorrect Lc.",
80 m.insert({0x6985,
81 std::make_shared<StatusProperties>("Preconditions not satisfied.",
82 typeid(CalypsoSamAccessForbiddenException))});
83 m.insert({0x6A00,
84 std::make_shared<StatusProperties>("Incorrect P1 or P2",
85 typeid(CalypsoSamIllegalParameterException))});
86 m.insert({0x6A80,
87 std::make_shared<StatusProperties>("Incorrect incoming data.",
88 typeid(CalypsoSamIncorrectInputDataException))});
89 m.insert({0x6A83,
90 std::make_shared<StatusProperties>("Record not found: ciphering key not found",
91 typeid(CalypsoSamDataAccessException))});
92
93 return m;
94}
95
96const std::map<const int, const std::shared_ptr<StatusProperties>>&
98{
99 return STATUS_TABLE;
100}
101
102}
103}
104}
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const CalypsoSamCommand & getCommandRef() const override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamSvPrepareDebitOrUndebit(const bool isDebitCommand, const CalypsoSam::ProductType productType, const std::vector< uint8_t > &svGetHeader, const std::vector< uint8_t > &svGetData, const std::vector< uint8_t > &svDebitOrUndebitCmdBuildData)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType