Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamSvCheck.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 "CmdSamSvCheck.h"
14
15/* Keyple Card Calypso */
16#include "CalypsoCardAdapter.h"
17#include "CalypsoCardClass.h"
21#include "SamUtilAdapter.h"
22
23/* Keyple Core Util */
24#include "ApduUtil.h"
25#include "IllegalArgumentException.h"
26#include "IllegalStateException.h"
27#include "System.h"
28
29namespace keyple {
30namespace card {
31namespace calypso {
32
33using namespace keyple::core::util;
34using namespace keyple::core::util::cpp;
35using namespace keyple::core::util::cpp::exception;
36
37const CalypsoSamCommand CmdSamSvCheck::mCommand = CalypsoSamCommand::SV_CHECK;
38
39const std::map<const int, const std::shared_ptr<StatusProperties>>
40 CmdSamSvCheck::STATUS_TABLE = initStatusTable();
41
42CmdSamSvCheck::CmdSamSvCheck(const std::shared_ptr<CalypsoSamAdapter> calypsoSam,
43 const std::vector<uint8_t>& svCardSignature)
44: AbstractSamCommand(mCommand, -1, calypsoSam)
45{
46 if (!svCardSignature.empty() && svCardSignature.size() != 3 && svCardSignature.size() != 6) {
47
48 throw IllegalArgumentException("Invalid svCardSignature.");
49 }
50
51 const uint8_t cla = SamUtilAdapter::getClassByte(calypsoSam->getProductType());
52 const uint8_t p1 = 0x00;
53 const uint8_t p2 = 0x00;
54
55 if (!svCardSignature.empty()) {
56
57 /* The operation is not "abort" */
58 std::vector<uint8_t> data(svCardSignature.size());
59 System::arraycopy(svCardSignature, 0, data, 0, svCardSignature.size());
61 std::make_shared<ApduRequestAdapter>(
62 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, data)));
63
64 } else {
65
67 std::make_shared<ApduRequestAdapter>(
68 ApduUtil::build(cla,
69 mCommand.getInstructionByte(),
70 p1,
71 p2,
72 std::vector<uint8_t>{0x00})));
73 }
74}
75
76const std::map<const int, const std::shared_ptr<StatusProperties>> CmdSamSvCheck::initStatusTable()
77{
78 std::map<const int, const std::shared_ptr<StatusProperties>> m =
80
81 m.insert({0x6700,
82 std::make_shared<StatusProperties>("Incorrect Lc.",
84 m.insert({0x6985,
85 std::make_shared<StatusProperties>("No active SV transaction.",
86 typeid(CalypsoSamAccessForbiddenException))});
87 m.insert({0x6988,
88 std::make_shared<StatusProperties>("Incorrect SV signature.",
89 typeid(CalypsoSamSecurityDataException))});
90
91 return m;
92}
93
94const std::map<const int, const std::shared_ptr<StatusProperties>>& CmdSamSvCheck::getStatusTable()
95 const
96{
97 return STATUS_TABLE;
98}
99
100}
101}
102}
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 SV_CHECK
CmdSamSvCheck(const std::shared_ptr< CalypsoSamAdapter > calypsoSam, const std::vector< uint8_t > &svCardSignature)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)