Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdCardChangePin.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 "CmdCardChangePin.h"
14
15/* Keyple Core Util */
16#include "ApduUtil.h"
17#include "IllegalArgumentException.h"
18
19/* Keyple Card Calypso */
22#include "CardPinException.h"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30
31using namespace keyple::core::util;
32
33const CalypsoCardCommand CmdCardChangePin::mCommand = CalypsoCardCommand::CHANGE_PIN;
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdCardChangePin::STATUS_TABLE = initStatusTable();
36
37CmdCardChangePin::CmdCardChangePin(const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
38 const std::vector<uint8_t>& newPinData)
39: AbstractCardCommand(mCommand, 0, calypsoCard)
40{
41 if (newPinData.empty() || (newPinData.size() != 0x04 && newPinData.size() != 0x10)) {
42 throw IllegalArgumentException("Bad PIN data length.");
43 }
44
45 const uint8_t cla = calypsoCard->getCardClass().getValue();
46 const uint8_t p1 = 0x00;
47 const uint8_t p2 = 0xFF; /* CL-PIN-MP1P2.1 */
48
49 // APDU Case 3
51 std::make_shared<ApduRequestAdapter>(
52 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, newPinData)));
53}
54
56{
57 return false;
58}
59
60const std::map<const int, const std::shared_ptr<StatusProperties>>
61 CmdCardChangePin::initStatusTable()
62{
63 std::map<const int, const std::shared_ptr<StatusProperties>> m =
65
66 m.insert({0x6700,
67 std::make_shared<StatusProperties>("Lc value not supported (not 04h, 10h, 18h, 20h).",
69 m.insert({0x6900,
70 std::make_shared<StatusProperties>("Transaction Counter is 0.",
71 typeid(CardTerminatedException))});
72 m.insert({0x6982,
73 std::make_shared<StatusProperties>("Security conditions not fulfilled (Get " \
74 "Challenge not done: challenge unavailable).",
75 typeid(CardSecurityContextException))});
76 m.insert({0x6985,
77 std::make_shared<StatusProperties>("Access forbidden (a session is open or DF is " \
78 "invalidated).",
79 typeid(CardAccessForbiddenException))});
80 m.insert({0x6988,
81 std::make_shared<StatusProperties>("Incorrect Cryptogram.",
82 typeid(CardSecurityDataException))});
83 m.insert({0x6A80,
84 std::make_shared<StatusProperties>("Decrypted message incorrect (key algorithm not " \
85 "supported, incorrect padding, etc.).",
86 typeid(CardSecurityDataException))});
87 m.insert({0x6A87,
88 std::make_shared<StatusProperties>("Lc not compatible with P2.",
89 typeid(CardIllegalParameterException))});
90 m.insert({0x6B00,
91 std::make_shared<StatusProperties>("Incorrect P1, P2.",
92 typeid(CardIllegalParameterException))});
93
94 return m;
95}
96
97const std::map<const int, const std::shared_ptr<StatusProperties>>&
99{
100 return STATUS_TABLE;
101}
102
103}
104}
105}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const CalypsoCardCommand CHANGE_PIN
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdCardChangePin(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const std::vector< uint8_t > &newPinData)