Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
AbstractCardCommand.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 "AbstractCardCommand.h"
14
15/* Keyple Card Calypso */
22#include "CardPinException.h"
29
30namespace keyple {
31namespace card {
32namespace calypso {
33
35 const int expectedResponseLength,
36 const std::shared_ptr<CalypsoCardAdapter> calypsoCard)
37: AbstractApduCommand(commandRef, expectedResponseLength), mCalypsoCard(calypsoCard) {}
38
40{
41 return dynamic_cast<const CalypsoCardCommand&>(AbstractApduCommand::getCommandRef());
42}
43
45 const std::type_info& exceptionClass, const std::string& message) const
46{
47 const auto& command = getCommandRef();
48 const auto statusWord = std::make_shared<int>(getApduResponse()->getStatusWord());
49
50 if (exceptionClass == typeid(CardAccessForbiddenException)) {
51 return CardAccessForbiddenException(message, command, statusWord);
52 } else if (exceptionClass == typeid(CardDataAccessException)) {
53 return CardDataAccessException(message, command, statusWord);
54 } else if (exceptionClass == typeid(CardDataOutOfBoundsException)) {
55 return CardDataOutOfBoundsException(message, command, statusWord);
56 } else if (exceptionClass == typeid(CardIllegalArgumentException)) {
57 return CardIllegalArgumentException(message, command);
58 } else if (exceptionClass == typeid(CardIllegalParameterException)) {
59 return CardIllegalParameterException(message, command, statusWord);
60 } else if (exceptionClass == typeid(CardPinException)) {
61 return CardPinException(message, command, statusWord);
62 } else if (exceptionClass == typeid(CardSecurityContextException)) {
63 return CardSecurityContextException(message, command, statusWord);
64 } else if (exceptionClass == typeid(CardSecurityDataException)) {
65 return CardSecurityDataException(message, command, statusWord);
66 } else if (exceptionClass == typeid(CardSessionBufferOverflowException)) {
67 return CardSessionBufferOverflowException(message, command, statusWord);
68 } else if (exceptionClass == typeid(CardTerminatedException)) {
69 return CardTerminatedException(message, command, statusWord);
70 } else {
71 return CardUnknownStatusException(message, command, statusWord);
72 }
73}
74
76 const std::string& message) const
77{
79 message,
81 std::make_shared<int>(getApduResponse()->getStatusWord()));
82 }
83
84void AbstractCardCommand::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse)
85{
87}
88
89std::shared_ptr<CalypsoCardAdapter> AbstractCardCommand::getCalypsoCard() const
90{
91 return mCalypsoCard;
92}
93
94void AbstractCardCommand::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse,
95 const std::shared_ptr<CalypsoCardAdapter> calypsoCard)
96{
97 mCalypsoCard = calypsoCard;
98
99 parseApduResponse(apduResponse);
100}
101
102}
103}
104}
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual const CardCommand & getCommandRef() const
virtual void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse)
AbstractCardCommand(const CalypsoCardCommand &commandRef, const int expectedResponseLength, const std::shared_ptr< CalypsoCardAdapter > calypsoCard)
const CalypsoApduCommandException buildCommandException(const std::type_info &exceptionClass, const std::string &message) const final
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const CalypsoCardCommand & getCommandRef() const override
const CalypsoApduCommandException buildUnexpectedResponseLengthException(const std::string &message) const final
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const