Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamGiveRandom.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 "CmdSamGiveRandom.h"
14
15/* Keyple Card Calypso */
17#include "SamUtilAdapter.h"
18
19/* Keyple Core Util */
20#include "ApduUtil.h"
21#include "IllegalArgumentException.h"
22
23namespace keyple {
24namespace card {
25namespace calypso {
26
27using namespace keyple::core::util;
28using namespace keyple::core::util::cpp::exception;
29
30const CalypsoSamCommand CmdSamGiveRandom::mCommand = CalypsoSamCommand::GIVE_RANDOM;
31
32const std::map<const int, const std::shared_ptr<StatusProperties>>
33 CmdSamGiveRandom::STATUS_TABLE = initStatusTable();
34
35CmdSamGiveRandom::CmdSamGiveRandom(const std::shared_ptr<CalypsoSamAdapter> calypsoSam,
36 const std::vector<uint8_t>& random)
37: AbstractSamCommand(mCommand, -1, calypsoSam)
38{
39 const uint8_t cla = SamUtilAdapter::getClassByte(calypsoSam->getProductType());
40 const uint8_t p1 = 0x00;
41 const uint8_t p2 = 0x00;
42
43 if (random.empty() || random.size() != 8) {
44
45 throw IllegalArgumentException("Random value should be an 8 bytes long");
46 }
47
49 std::make_shared<ApduRequestAdapter>(
50 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, random)));
51}
52
53const std::map<const int, const std::shared_ptr<StatusProperties>>
54 CmdSamGiveRandom::initStatusTable()
55{
56 std::map<const int, const std::shared_ptr<StatusProperties>> m =
58
59 m.insert({0x6700,
60 std::make_shared<StatusProperties>("Incorrect Lc.",
62
63 return m;
64}
65
66const std::map<const int, const std::shared_ptr<StatusProperties>>&
68{
69 return STATUS_TABLE;
70}
71
72}
73}
74}
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 GIVE_RANDOM
CmdSamGiveRandom(const std::shared_ptr< CalypsoSamAdapter > calypsoSam, const std::vector< uint8_t > &random)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)