Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamSelectDiversifier.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
14
15/* Keyple Card Calypso */
18#include "SamUtilAdapter.h"
19
20/* Keyple Core Util */
21#include "ApduUtil.h"
22#include "IllegalArgumentException.h"
23
24namespace keyple {
25namespace card {
26namespace calypso {
27
28using namespace keyple::core::util;
29using namespace keyple::core::util::cpp::exception;
30
31const CalypsoSamCommand CmdSamSelectDiversifier::mCommand = CalypsoSamCommand::SELECT_DIVERSIFIER;
32
33const std::map<const int, const std::shared_ptr<StatusProperties>>
34 CmdSamSelectDiversifier::STATUS_TABLE = initStatusTable();
35
37 const std::vector<uint8_t>& diversifier)
38: AbstractSamCommand(mCommand)
39{
40 if (diversifier.empty() || (diversifier.size() != 4 && diversifier.size() != 8)) {
41 throw IllegalArgumentException("Bad diversifier value!");
42 }
43
44 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
45 const uint8_t p1 = 0x00;
46 const uint8_t p2 = 0x00;
47
49 std::make_shared<ApduRequestAdapter>(
50 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, diversifier)));
51}
52
53const std::map<const int, const std::shared_ptr<StatusProperties>>
54 CmdSamSelectDiversifier::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 m.insert({0x6985,
63 std::make_shared<StatusProperties>("Preconditions not satisfied: the SAM is locked.",
64 typeid(CalypsoSamAccessForbiddenException))});
65
66 return m;
67}
68
69const std::map<const int, const std::shared_ptr<StatusProperties>>&
71{
72 return STATUS_TABLE;
73}
74
75}
76}
77}
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 SELECT_DIVERSIFIER
CmdSamSelectDiversifier(const CalypsoSam::ProductType productType, const std::vector< uint8_t > &diversifier)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType