Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamDigestInit.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 "CmdSamDigestInit.h"
14
15/* Keyple Card Calypso */
20#include "SamUtilAdapter.h"
21
22/* Keyple Core Util */
23#include "ApduUtil.h"
24#include "IllegalArgumentException.h"
25#include "System.h"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30
31using namespace keyple::core::util;
32using namespace keyple::core::util::cpp;
33using namespace keyple::core::util::cpp::exception;
34
35const CalypsoSamCommand CmdSamDigestInit::mCommand = CalypsoSamCommand::DIGEST_INIT;
36
37const std::map<const int, const std::shared_ptr<StatusProperties>>
38 CmdSamDigestInit::STATUS_TABLE = initStatusTable();
39
41 const std::shared_ptr<CalypsoSamAdapter> calypsoSam,
42 const bool verificationMode,
43 const bool confidentialSessionMode,
44 const uint8_t workKif,
45 const uint8_t workKvc,
46 const std::vector<uint8_t>& digestData)
47: AbstractSamCommand(mCommand, -1, calypsoSam)
48{
49 if (workKif == 0x00 || workKvc == 0x00) {
50
51 throw IllegalArgumentException("Bad kif or kvc!");
52 }
53
54 if (digestData.empty()) {
55
56 throw IllegalArgumentException("Digest data is null!");
57 }
58
59 const uint8_t cla = SamUtilAdapter::getClassByte(calypsoSam->getProductType());
60 uint8_t p1 = 0x00;
61
62 if (verificationMode) {
63
64 p1 += 1;
65 }
66
67 if (confidentialSessionMode) {
68
69 p1 += 2;
70 }
71
72 const uint8_t p2 = 0xFF;
73
74 std::vector<uint8_t> dataIn(2 + digestData.size());
75 dataIn[0] = workKif;
76 dataIn[1] = workKvc;
77 System::arraycopy(digestData, 0, dataIn, 2, digestData.size());
78
80 std::make_shared<ApduRequestAdapter>(
81 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, dataIn)));
82}
83
84const std::map<const int, const std::shared_ptr<StatusProperties>>
85 CmdSamDigestInit::initStatusTable()
86{
87 std::map<const int, const std::shared_ptr<StatusProperties>> m =
89
90 m.insert({0x6700,
91 std::make_shared<StatusProperties>("Incorrect Lc.",
93 m.insert({0x6900,
94 std::make_shared<StatusProperties>("An event counter cannot be incremented.",
95 typeid(CalypsoSamCounterOverflowException))});
96 m.insert({0x6985,
97 std::make_shared<StatusProperties>("Preconditions not satisfied.",
98 typeid(CalypsoSamAccessForbiddenException))});
99 m.insert({0x6A00,
100 std::make_shared<StatusProperties>("Incorrect P2.",
101 typeid(CalypsoSamIllegalParameterException))});
102 m.insert({0x6A83,
103 std::make_shared<StatusProperties>("Record not found: signing key not found.",
104 typeid(CalypsoSamDataAccessException))});
105
106 return m;
107}
108
109const std::map<const int, const std::shared_ptr<StatusProperties>>&
111{
112 return STATUS_TABLE;
113}
114
115}
116}
117}
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 DIGEST_INIT
CmdSamDigestInit(const std::shared_ptr< CalypsoSamAdapter > calypsoSam, const bool verificationMode, const bool confidentialSessionMode, const uint8_t workKif, const uint8_t workKvc, const std::vector< uint8_t > &digestData)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)