Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
AbstractCardCommand.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 "AbstractCardCommand.h"
14
15/* Keyple Card Calypso */
22#include "CardPinException.h"
29
30namespace keyple {
31namespace card {
32namespace calypso {
33
35: AbstractApduCommand(commandRef, le) {}
36
38{
39 return dynamic_cast<const CalypsoCardCommand&>(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(CardAccessForbiddenException)) {
49 return CardAccessForbiddenException(message, command, statusWord);
50 } else if (exceptionClass == typeid(CardDataAccessException)) {
51 return CardDataAccessException(message, command, statusWord);
52 } else if (exceptionClass == typeid(CardDataOutOfBoundsException)) {
53 return CardDataOutOfBoundsException(message, command, statusWord);
54 } else if (exceptionClass == typeid(CardIllegalArgumentException)) {
55 return CardIllegalArgumentException(message, command);
56 } else if (exceptionClass == typeid(CardIllegalParameterException)) {
57 return CardIllegalParameterException(message, command, statusWord);
58 } else if (exceptionClass == typeid(CardPinException)) {
59 return CardPinException(message, command, statusWord);
60 } else if (exceptionClass == typeid(CardSecurityContextException)) {
61 return CardSecurityContextException(message, command, statusWord);
62 } else if (exceptionClass == typeid(CardSecurityDataException)) {
63 return CardSecurityDataException(message, command, statusWord);
64 } else if (exceptionClass == typeid(CardSessionBufferOverflowException)) {
65 return CardSessionBufferOverflowException(message, command, statusWord);
66 } else if (exceptionClass == typeid(CardTerminatedException)) {
67 return CardTerminatedException(message, command, statusWord);
68 } else {
69 return CardUnknownStatusException(message, command, statusWord);
70 }
71}
72
74 const std::string& message) const
75{
77 message,
79 std::make_shared<int>(getApduResponse()->getStatusWord()));
80 }
81
83 const std::shared_ptr<ApduResponseApi> apduResponse)
84{
85 return dynamic_cast<AbstractCardCommand&>(AbstractApduCommand::setApduResponse(apduResponse));
86}
87
89{
90 try {
92 } catch (CalypsoApduCommandException& e) {
93 throw reinterpret_cast<CardCommandException&>(e);
94 }
95}
96
97}
98}
99}
virtual AbstractApduCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse)
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual const CardCommand & getCommandRef() const
AbstractCardCommand(const CalypsoCardCommand &commandRef, const int le)
const CalypsoApduCommandException buildCommandException(const std::type_info &exceptionClass, const std::string &message) const final
const CalypsoCardCommand & getCommandRef() const override
const CalypsoApduCommandException buildUnexpectedResponseLengthException(const std::string &message) const final
AbstractCardCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override