Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
AbstractSamCommand.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
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: AbstractApduCommand(commandRef, le) {}
36
38{
39 return dynamic_cast<const CalypsoSamCommand&>(AbstractApduCommand::getCommandRef());
40}
41
43 const std::type_info& exceptionClass, const std::string& message) const
44{
45 const auto& command = getCommandRef();
46 const auto statusWord = std::make_shared<int>(getApduResponse()->getStatusWord());
47
48 if (exceptionClass == typeid(CalypsoSamAccessForbiddenException)) {
49 return CalypsoSamAccessForbiddenException(message, command, statusWord);
50 } else if (exceptionClass == typeid(CalypsoSamCounterOverflowException)) {
51 return CalypsoSamCounterOverflowException(message, command, statusWord);
52 } else if (exceptionClass == typeid(CalypsoSamDataAccessException)) {
53 return CalypsoSamDataAccessException(message, command, statusWord);
54 } else if (exceptionClass == typeid(CalypsoSamIllegalArgumentException)) {
55 return CalypsoSamIllegalArgumentException(message, command);
56 } else if (exceptionClass == typeid(CalypsoSamIllegalParameterException)) {
57 return CalypsoSamIllegalParameterException(message, command, statusWord);
58 } else if (exceptionClass == typeid(CalypsoSamIncorrectInputDataException)) {
59 return CalypsoSamIncorrectInputDataException(message, command, statusWord);
60 } else if (exceptionClass == typeid(CalypsoSamSecurityDataException)) {
61 return CalypsoSamSecurityDataException(message, command, statusWord);
62 } else {
63 return CalypsoSamUnknownStatusException(message, command, statusWord);
64 }
65}
66
68 const std::string& message) const
69{
71 message,
73 std::make_shared<int>(getApduResponse()->getStatusWord()));
74}
75
77 const std::shared_ptr<ApduResponseApi> apduResponse)
78{
79 return dynamic_cast<AbstractSamCommand&>(AbstractApduCommand::setApduResponse(apduResponse));
80}
81
83{
84 try {
86 } catch (const CalypsoApduCommandException& e) {
87 throw static_cast<const CalypsoSamCommandException&>(e);
88 }
89}
90
91const std::map<const int, const std::shared_ptr<StatusProperties>>
92 AbstractSamCommand::initStatusTable()
93{
94 std::map<const int, const std::shared_ptr<StatusProperties>> m =
96
97 m.insert({0x6D00,
98 std::make_shared<StatusProperties>("Instruction unknown.",
100 m.insert({0x6E00,
101 std::make_shared<StatusProperties>("Class not supported.",
102 typeid(CalypsoSamIllegalParameterException))});
103
104 return m;
105}
106
107const std::map<const int, const std::shared_ptr<StatusProperties>>&
109{
110 return STATUS_TABLE;
111}
112
113}
114}
115}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual AbstractApduCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse)
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual const CardCommand & getCommandRef() const
const CalypsoApduCommandException buildCommandException(const std::type_info &exceptionClass, const std::string &message) const final
const CalypsoApduCommandException buildUnexpectedResponseLengthException(const std::string &message) const final
AbstractSamCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
AbstractSamCommand(const CalypsoSamCommand &commandRef, const int le)
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 CalypsoSamCommand & getCommandRef() const override