Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdSamSvCheck.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 "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
43 const std::vector<uint8_t>& svCardSignature)
44: AbstractSamCommand(mCommand, 0)
45{
46 if (!svCardSignature.empty() && svCardSignature.size() != 3 && svCardSignature.size() != 6) {
47 throw IllegalArgumentException("Invalid svCardSignature.");
48 }
49
50 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
51 const uint8_t p1 = 0x00;
52 const uint8_t p2 = 0x00;
53
54 if (!svCardSignature.empty()) {
55 /* The operation is not "abort" */
56 std::vector<uint8_t> data(svCardSignature.size());
57 System::arraycopy(svCardSignature, 0, data, 0, svCardSignature.size());
59 std::make_shared<ApduRequestAdapter>(
60 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, data)));
61 } else {
63 std::make_shared<ApduRequestAdapter>(
64 ApduUtil::build(cla,
65 mCommand.getInstructionByte(),
66 p1,
67 p2,
68 std::vector<uint8_t>{0x00})));
69 }
70}
71
72const std::map<const int, const std::shared_ptr<StatusProperties>> CmdSamSvCheck::initStatusTable()
73{
74 std::map<const int, const std::shared_ptr<StatusProperties>> m =
76
77 m.insert({0x6700,
78 std::make_shared<StatusProperties>("Incorrect Lc.",
80 m.insert({0x6985,
81 std::make_shared<StatusProperties>("No active SV transaction.",
82 typeid(CalypsoSamAccessForbiddenException))});
83 m.insert({0x6988,
84 std::make_shared<StatusProperties>("Incorrect SV signature.",
85 typeid(CalypsoSamSecurityDataException))});
86
87 return m;
88}
89
90const std::map<const int, const std::shared_ptr<StatusProperties>>& CmdSamSvCheck::getStatusTable()
91 const
92{
93 return STATUS_TABLE;
94}
95
96}
97}
98}
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 CalypsoSam::ProductType productType, 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)
CalypsoSam::ProductType ProductType