Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardChangePin.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 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
38 const std::vector<uint8_t>& newPinData)
39: AbstractCardCommand(mCommand)
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 = calypsoCardClass.getValue();
46 const uint8_t p1 = 0x00;
47 const uint8_t p2 = 0xFF; /* CL-PIN-MP1P2.1 */
48
50 std::make_shared<ApduRequestAdapter>(
51 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, newPinData)));
52}
53
55{
56 return false;
57}
58
59const std::map<const int, const std::shared_ptr<StatusProperties>>
60 CmdCardChangePin::initStatusTable()
61{
62 std::map<const int, const std::shared_ptr<StatusProperties>> m =
64
65 m.insert({0x6700,
66 std::make_shared<StatusProperties>("Lc value not supported (not 04h, 10h, 18h, 20h).",
68 m.insert({0x6900,
69 std::make_shared<StatusProperties>("Transaction Counter is 0.",
70 typeid(CardTerminatedException))});
71 m.insert({0x6982,
72 std::make_shared<StatusProperties>("Security conditions not fulfilled (Get " \
73 "Challenge not done: challenge unavailable).",
74 typeid(CardSecurityContextException))});
75 m.insert({0x6985,
76 std::make_shared<StatusProperties>("Access forbidden (a session is open or DF is " \
77 "invalidated).",
78 typeid(CardAccessForbiddenException))});
79 m.insert({0x6988,
80 std::make_shared<StatusProperties>("Incorrect Cryptogram.",
81 typeid(CardSecurityDataException))});
82 m.insert({0x6A80,
83 std::make_shared<StatusProperties>("Decrypted message incorrect (key algorithm not " \
84 "supported, incorrect padding, etc.).",
85 typeid(CardSecurityDataException))});
86 m.insert({0x6A87,
87 std::make_shared<StatusProperties>("Lc not compatible with P2.",
88 typeid(CardIllegalParameterException))});
89 m.insert({0x6B00,
90 std::make_shared<StatusProperties>("Incorrect P1, P2.",
91 typeid(CardIllegalParameterException))});
92
93 return m;
94}
95
96const std::map<const int, const std::shared_ptr<StatusProperties>>&
98{
99 return STATUS_TABLE;
100}
101
102}
103}
104}
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
CmdCardChangePin(const CalypsoCardClass calypsoCardClass, const std::vector< uint8_t > &newPinData)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override