Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdSamGetChallenge.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 "CmdSamGetChallenge.h"
14
15/* Keyple Card Calypso */
17#include "SamUtilAdapter.h"
18
19/* Keyple Core Util */
20#include "ApduUtil.h"
21#include "IllegalArgumentException.h"
22#include "System.h"
23
24namespace keyple {
25namespace card {
26namespace calypso {
27
28using namespace keyple::core::util;
29using namespace keyple::core::util::cpp;
30using namespace keyple::core::util::cpp::exception;
31
32const CalypsoSamCommand CmdSamGetChallenge::mCommand = CalypsoSamCommand::GET_CHALLENGE;
33
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdSamGetChallenge::STATUS_TABLE = initStatusTable();
36
38 const int expectedResponseLength)
39: AbstractSamCommand(mCommand, expectedResponseLength)
40{
42 std::make_shared<ApduRequestAdapter>(
43 ApduUtil::build(SamUtilAdapter::getClassByte(productType),
44 mCommand.getInstructionByte(),
45 0,
46 0,
47 static_cast<uint8_t>(expectedResponseLength))));
48}
49
50const std::vector<uint8_t> CmdSamGetChallenge::getChallenge() const
51{
52 return isSuccessful() ? getApduResponse()->getDataOut() : std::vector<uint8_t>();
53}
54
55const std::map<const int, const std::shared_ptr<StatusProperties>>
56 CmdSamGetChallenge::initStatusTable()
57{
58 std::map<const int, const std::shared_ptr<StatusProperties>> m =
60
61 m.insert({0x6700,
62 std::make_shared<StatusProperties>("Incorrect Lc.",
64
65 return m;
66}
67
68const std::map<const int, const std::shared_ptr<StatusProperties>>&
70{
71 return STATUS_TABLE;
72}
73
74}
75}
76}
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
static const CalypsoSamCommand GET_CHALLENGE
CmdSamGetChallenge(const CalypsoSam::ProductType productType, const int expectedResponseLength)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::vector< uint8_t > getChallenge() const
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType