Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdCardChangeKey.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 "CmdCardChangeKey.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 CmdCardChangeKey::mCommand = CalypsoCardCommand::CHANGE_KEY;
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdCardChangeKey::STATUS_TABLE = initStatusTable();
36
37CmdCardChangeKey::CmdCardChangeKey(const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
38 const uint8_t keyIndex,
39 const std::vector<uint8_t>& cryptogram)
40: AbstractCardCommand(mCommand, 0, calypsoCard)
41{
42 const uint8_t cla = calypsoCard->getCardClass().getValue();
43 const uint8_t p1 = 0x00;
44
45 // APDU Case 3
47 std::make_shared<ApduRequestAdapter>(
48 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, keyIndex, cryptogram)));
49}
50
52{
53 return false;
54}
55
56const std::map<const int, const std::shared_ptr<StatusProperties>>
57 CmdCardChangeKey::initStatusTable()
58{
59 std::map<const int, const std::shared_ptr<StatusProperties>> m =
61
62 m.insert({0x6700,
63 std::make_shared<StatusProperties>("Lc value not supported (not 04h, 10h, 18h, 20h).",
65 m.insert({0x6900,
66 std::make_shared<StatusProperties>("Transaction Counter is 0.",
67 typeid(CardTerminatedException))});
68 m.insert({0x6982,
69 std::make_shared<StatusProperties>("Security conditions not fulfilled (Get " \
70 "Challenge not done: challenge unavailable).",
71 typeid(CardSecurityContextException))});
72 m.insert({0x6985,
73 std::make_shared<StatusProperties>("Access forbidden (a session is open or DF is " \
74 "invalidated).",
75 typeid(CardAccessForbiddenException))});
76 m.insert({0x6988,
77 std::make_shared<StatusProperties>("Incorrect Cryptogram.",
78 typeid(CardSecurityDataException))});
79 m.insert({0x6A80,
80 std::make_shared<StatusProperties>("Decrypted message incorrect (key algorithm not " \
81 "supported, incorrect padding, etc.).",
82 typeid(CardSecurityDataException))});
83 m.insert({0x6A87,
84 std::make_shared<StatusProperties>("Lc not compatible with P2.",
85 typeid(CardIllegalParameterException))});
86 m.insert({0x6B00,
87 std::make_shared<StatusProperties>("Incorrect P1, P2.",
88 typeid(CardIllegalParameterException))});
89
90 return m;
91}
92
93const std::map<const int, const std::shared_ptr<StatusProperties>>&
95{
96 return STATUS_TABLE;
97}
98
99}
100}
101}
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_KEY
CmdCardChangeKey(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t keyIndex, const std::vector< uint8_t > &cryptogram)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override