Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamGetChallenge.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 "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 uint8_t expectedResponseLength)
39: AbstractSamCommand(mCommand)
40{
41 if (expectedResponseLength != 0x04 && expectedResponseLength != 0x08) {
42 throw IllegalArgumentException("Bad challenge length! Expected 4 or 8, got " +
43 std::to_string(expectedResponseLength));
44 }
45
46 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
47 const uint8_t p1 = 0x00;
48 const uint8_t p2 = 0x00;
49
51 std::make_shared<ApduRequestAdapter>(
52 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, expectedResponseLength)));
53}
54
55const std::vector<uint8_t> CmdSamGetChallenge::getChallenge() const
56{
57 return isSuccessful() ? getApduResponse()->getDataOut() : std::vector<uint8_t>();
58}
59
60const std::map<const int, const std::shared_ptr<StatusProperties>>
61 CmdSamGetChallenge::initStatusTable()
62{
63 std::map<const int, const std::shared_ptr<StatusProperties>> m =
65
66 m.insert({0x6700,
67 std::make_shared<StatusProperties>("Incorrect Lc.",
69
70 return m;
71}
72
73const std::map<const int, const std::shared_ptr<StatusProperties>>&
75{
76 return STATUS_TABLE;
77}
78
79}
80}
81}
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 uint8_t 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