Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamGiveRandom.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 "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
36 const std::vector<uint8_t>& random)
37: AbstractSamCommand(mCommand)
38{
39 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
40 const uint8_t p1 = 0x00;
41 const uint8_t p2 = 0x00;
42
43 if (random.empty() || random.size() != 8) {
44 throw IllegalArgumentException("Random value should be an 8 bytes long");
45 }
46
48 std::make_shared<ApduRequestAdapter>(
49 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, random)));
50}
51
52const std::map<const int, const std::shared_ptr<StatusProperties>>
53 CmdSamGiveRandom::initStatusTable()
54{
55 std::map<const int, const std::shared_ptr<StatusProperties>> m =
57
58 m.insert({0x6700,
59 std::make_shared<StatusProperties>("Incorrect Lc.",
61
62 return m;
63}
64
65const std::map<const int, const std::shared_ptr<StatusProperties>>&
67{
68 return STATUS_TABLE;
69}
70
71}
72}
73}
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
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamGiveRandom(const CalypsoSam::ProductType productType, const std::vector< uint8_t > &random)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType