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