Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
AbstractSamCommand.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 "AbstractSamCommand.h"
14
15/* Keyple Card calypso */
16#include "CalypsoCardCommand.h"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30
31const std::map<const int, const std::shared_ptr<StatusProperties>>
32 AbstractSamCommand::STATUS_TABLE = initStatusTable();
33
35 const int expectedResponseLength,
36 const std::shared_ptr<CalypsoSamAdapter> calypsoSam)
37: AbstractApduCommand(commandRef, expectedResponseLength), mCalypsoSam(calypsoSam) {}
38
39const std::shared_ptr<CalypsoSamAdapter> AbstractSamCommand::getCalypsoSam() const
40{
41 return mCalypsoSam;
42}
43
45{
46 return dynamic_cast<const CalypsoSamCommand&>(AbstractApduCommand::getCommandRef());
47}
48
50 const std::type_info& exceptionClass, const std::string& message) const
51{
52 const auto& command = getCommandRef();
53 const auto statusWord = std::make_shared<int>(getApduResponse()->getStatusWord());
54
55 if (exceptionClass == typeid(CalypsoSamAccessForbiddenException)) {
56 return CalypsoSamAccessForbiddenException(message, command, statusWord);
57 } else if (exceptionClass == typeid(CalypsoSamCounterOverflowException)) {
58 return CalypsoSamCounterOverflowException(message, command, statusWord);
59 } else if (exceptionClass == typeid(CalypsoSamDataAccessException)) {
60 return CalypsoSamDataAccessException(message, command, statusWord);
61 } else if (exceptionClass == typeid(CalypsoSamIllegalArgumentException)) {
62 return CalypsoSamIllegalArgumentException(message, command);
63 } else if (exceptionClass == typeid(CalypsoSamIllegalParameterException)) {
64 return CalypsoSamIllegalParameterException(message, command, statusWord);
65 } else if (exceptionClass == typeid(CalypsoSamIncorrectInputDataException)) {
66 return CalypsoSamIncorrectInputDataException(message, command, statusWord);
67 } else if (exceptionClass == typeid(CalypsoSamSecurityDataException)) {
68 return CalypsoSamSecurityDataException(message, command, statusWord);
69 } else {
70 return CalypsoSamUnknownStatusException(message, command, statusWord);
71 }
72}
73
75 const std::string& message) const
76{
78 message,
80 std::make_shared<int>(getApduResponse()->getStatusWord()));
81}
82
83void AbstractSamCommand::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse)
84{
85 try {
86
88
89 } catch (const CalypsoApduCommandException& e) {
90
91 throw static_cast<const CalypsoSamCommandException&>(e);
92 }
93}
94
95const std::map<const int, const std::shared_ptr<StatusProperties>>
96 AbstractSamCommand::initStatusTable()
97{
98 std::map<const int, const std::shared_ptr<StatusProperties>> m =
100
101 m.insert({0x6D00,
102 std::make_shared<StatusProperties>("Instruction unknown.",
104 m.insert({0x6E00,
105 std::make_shared<StatusProperties>("Class not supported.",
106 typeid(CalypsoSamIllegalParameterException))});
107
108 return m;
109}
110
111const std::map<const int, const std::shared_ptr<StatusProperties>>&
113{
114 return STATUS_TABLE;
115}
116
117void AbstractSamCommand::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse,
118 const std::shared_ptr<CalypsoSamAdapter> calypsoSam)
119{
120 mCalypsoSam = calypsoSam;
121
122 parseApduResponse(apduResponse);
123}
124
125}
126}
127}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual const CardCommand & getCommandRef() const
virtual void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse)
const CalypsoApduCommandException buildCommandException(const std::type_info &exceptionClass, const std::string &message) const final
const CalypsoApduCommandException buildUnexpectedResponseLengthException(const std::string &message) const final
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const std::shared_ptr< CalypsoSamAdapter > getCalypsoSam() const
AbstractSamCommand(const CalypsoSamCommand &commandRef, const int expectedResponseLength, const std::shared_ptr< CalypsoSamAdapter > calypsoSam)
const CalypsoSamCommand & getCommandRef() const override
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override