Keyple Card Calypso C++ Library 2.2.2
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#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 std::vector<uint8_t>& diversifier)
38: AbstractSamCommand(CalypsoSamCommand::SELECT_DIVERSIFIER, 0)
39{
40 /* Format the diversifier on 4 or 8 bytes if needed */
41 if (static_cast<int>(diversifier.size()) != 4 &&
42 static_cast<int>(diversifier.size()) != 8) {
43 const int newLength = static_cast<int>(diversifier.size()) < 4 ? 4 : 8;
44 std::vector<uint8_t> tmp(newLength);
45 System::arraycopy(diversifier, 0, tmp, newLength - diversifier.size(), diversifier.size());
46 diversifier = tmp;
47 }
48
50 std::make_shared<ApduRequestAdapter>(
51 ApduUtil::build(SamUtilAdapter::getClassByte(productType),
52 getCommandRef().getInstructionByte(),
53 0,
54 0,
55 diversifier)));
56}
57
58const std::map<const int, const std::shared_ptr<StatusProperties>>
59 CmdSamSelectDiversifier::initStatusTable()
60{
61 std::map<const int, const std::shared_ptr<StatusProperties>> m =
63
64 m.insert({0x6700,
65 std::make_shared<StatusProperties>("Incorrect Lc.",
67 m.insert({0x6985,
68 std::make_shared<StatusProperties>("Preconditions not satisfied: the SAM is locked.",
69 typeid(CalypsoSamAccessForbiddenException))});
70
71 return m;
72}
73
74const std::map<const int, const std::shared_ptr<StatusProperties>>&
76{
77 return STATUS_TABLE;
78}
79
80}
81}
82}
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
CmdSamSelectDiversifier(const CalypsoSam::ProductType productType, 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