Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamSelectDiversifier.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
14
15/* Keyple Card Calypso */
18#include "SamUtilAdapter.h"
19
20/* Keyple Core Util */
21#include "ApduUtil.h"
22#include "IllegalArgumentException.h"
23#include "System.h"
24
25namespace keyple {
26namespace card {
27namespace calypso {
28
29using namespace keyple::core::util;
30using namespace keyple::core::util::cpp;
31using namespace keyple::core::util::cpp::exception;
32
33const std::map<const int, const std::shared_ptr<StatusProperties>>
34 CmdSamSelectDiversifier::STATUS_TABLE = initStatusTable();
35
37 const std::shared_ptr<CalypsoSamAdapter> calypsoSam,
38 std::vector<uint8_t>& diversifier)
39: AbstractSamCommand(CalypsoSamCommand::SELECT_DIVERSIFIER, -1, calypsoSam)
40{
41 /* Format the diversifier on 4 or 8 bytes if needed */
42 if (static_cast<int>(diversifier.size()) != 4 &&
43 static_cast<int>(diversifier.size()) != 8) {
44 const int newLength = static_cast<int>(diversifier.size()) < 4 ? 4 : 8;
45 std::vector<uint8_t> tmp(newLength);
46 System::arraycopy(diversifier, 0, tmp, newLength - diversifier.size(), diversifier.size());
47 diversifier = tmp;
48 }
49
51 std::make_shared<ApduRequestAdapter>(
52 ApduUtil::build(SamUtilAdapter::getClassByte(calypsoSam->getProductType()),
53 getCommandRef().getInstructionByte(),
54 0,
55 0,
56 diversifier)));
57}
58
59const std::map<const int, const std::shared_ptr<StatusProperties>>
60 CmdSamSelectDiversifier::initStatusTable()
61{
62 std::map<const int, const std::shared_ptr<StatusProperties>> m =
64
65 m.insert({0x6700,
66 std::make_shared<StatusProperties>("Incorrect Lc.",
68 m.insert({0x6985,
69 std::make_shared<StatusProperties>("Preconditions not satisfied: the SAM is locked.",
70 typeid(CalypsoSamAccessForbiddenException))});
71
72 return m;
73}
74
75const std::map<const int, const std::shared_ptr<StatusProperties>>&
77{
78 return STATUS_TABLE;
79}
80
81}
82}
83}
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const CalypsoSamCommand & getCommandRef() const override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamSelectDiversifier(const std::shared_ptr< CalypsoSamAdapter > calypsoSam, std::vector< uint8_t > &diversifier)
static uint8_t getClassByte(const ProductType productType)