Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdSamWriteKey.cpp
Go to the documentation of this file.
1#include "CmdSamWriteKey.h"
2
3/* Keyple Card Calypso */
10#include "SamUtilAdapter.h"
11
12/* Keyple Core Util */
13#include "ApduUtil.h"
14#include "IllegalArgumentException.h"
15
16namespace keyple {
17namespace card {
18namespace calypso {
19
20using namespace keyple::core::util;
21using namespace keyple::core::util::cpp::exception;
22
23const CalypsoSamCommand CmdSamWriteKey::mCommand = CalypsoSamCommand::WRITE_KEY;
24const std::map<const int, const std::shared_ptr<StatusProperties>>
25 CmdSamWriteKey::STATUS_TABLE = initStatusTable();
26
27
29 const uint8_t writingMode,
30 const uint8_t keyReference,
31 const std::vector<uint8_t>& keyData)
32: AbstractSamCommand(mCommand, 0)
33{
34 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
35
36 if (keyData.empty()) {
37 throw IllegalArgumentException("Key data null!");
38 }
39
40 if (keyData.size() < 48 && keyData.size() > 80) {
41 throw IllegalArgumentException("Key data should be between 40 and 80 bytes long!");
42 }
43
45 std::make_shared<ApduRequestAdapter>(
46 ApduUtil::build(cla,
47 mCommand.getInstructionByte(),
48 writingMode,
49 keyReference,
50 keyData)));
51}
52
53const std::map<const int, const std::shared_ptr<StatusProperties>>& CmdSamWriteKey::getStatusTable()
54 const
55{
56 return STATUS_TABLE;
57}
58
59const std::map<const int, const std::shared_ptr<StatusProperties>> CmdSamWriteKey::initStatusTable()
60{
61 std::map<const int, const std::shared_ptr<StatusProperties>> m =
63
64 m.insert({0x6700,
65 std::make_shared<StatusProperties>("Incorrect Lc.",
67 m.insert({0x6900,
68 std::make_shared<StatusProperties>("An event counter cannot be incremented.",
69 typeid(CalypsoSamCounterOverflowException))});
70 m.insert({0x6985,
71 std::make_shared<StatusProperties>("Preconditions not satisfied.",
72 typeid(CalypsoSamAccessForbiddenException))});
73 m.insert({0x6988,
74 std::make_shared<StatusProperties>("Incorrect signature.",
75 typeid(CalypsoSamSecurityDataException))});
76 m.insert({0x6A00,
77 std::make_shared<StatusProperties>("P1 or P2 incorrect.",
78 typeid(CalypsoSamIllegalParameterException))});
79 m.insert({0x6A80,
80 std::make_shared<StatusProperties>("Incorrect plain or decrypted data.",
81 typeid(CalypsoSamIncorrectInputDataException))});
82 m.insert({0x6A83,
83 std::make_shared<StatusProperties>("Record not found: deciphering key not found.",
84 typeid(CalypsoSamDataAccessException))});
85 m.insert({0x6A87,
86 std::make_shared<StatusProperties>("Lc inconsistent with P1 or P2.",
87 typeid(CalypsoSamIncorrectInputDataException))});
88
89 return m;
90}
91
92}
93}
94}
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 WRITE_KEY
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamWriteKey(const CalypsoSam::ProductType productType, const uint8_t writingMode, const uint8_t keyReference, const std::vector< uint8_t > &keyData)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType