Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamUnlock.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 "CmdSamUnlock.h"
14
15/* Keyple Card Calypso */
19#include "SamUtilAdapter.h"
20
21/* Keyple Core Util */
22#include "ApduUtil.h"
23#include "IllegalArgumentException.h"
24
25namespace keyple {
26namespace card {
27namespace calypso {
28
29using namespace keyple::core::util;
30using namespace keyple::core::util::cpp::exception;
31
32const CalypsoSamCommand CmdSamUnlock::mCommand = CalypsoSamCommand::UNLOCK;
33const std::map<const int, const std::shared_ptr<StatusProperties>>
34 CmdSamUnlock::STATUS_TABLE = initStatusTable();
35
36
37CmdSamUnlock::CmdSamUnlock(const CalypsoSam::ProductType productType, const std::vector<uint8_t>& unlockData)
38: AbstractSamCommand(mCommand)
39{
40 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
41 const uint8_t p1 = 0x00;
42 const uint8_t p2 = 0x00;
43
44 if (unlockData.empty()) {
45 throw IllegalArgumentException("Unlock data null!");
46 }
47
48 if (unlockData.size() != 8 && unlockData.size() != 16) {
49 throw IllegalArgumentException("Unlock data should be 8 ou 16 bytes long!");
50 }
51
53 std::make_shared<ApduRequestAdapter>(
54 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, unlockData)));
55}
56
57const std::map<const int, const std::shared_ptr<StatusProperties>>& CmdSamUnlock::getStatusTable()
58 const
59{
60 return STATUS_TABLE;
61}
62
63const std::map<const int, const std::shared_ptr<StatusProperties>> CmdSamUnlock::initStatusTable()
64{
65 std::map<const int, const std::shared_ptr<StatusProperties>> m =
67
68 m.insert({0x6700,
69 std::make_shared<StatusProperties>("Incorrect Lc.",
71 m.insert({0x6985,
72 std::make_shared<StatusProperties>("Preconditions not satisfied (SAM not locked?).",
73 typeid(CalypsoSamAccessForbiddenException))});
74 m.insert({0x6988,
75 std::make_shared<StatusProperties>("Incorrect UnlockData.",
76 typeid(CalypsoSamSecurityDataException))});
77
78 return m;
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
static const CalypsoSamCommand UNLOCK
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamUnlock(const CalypsoSam::ProductType productType, const std::vector< uint8_t > &unlockData)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType