Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamDigestInit.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 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 CalypsoSam::ProductType productType,
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)
48{
49 if (workKif == 0x00 || workKvc == 0x00) {
50 throw IllegalArgumentException("Bad kif or kvc!");
51 }
52
53 if (digestData.empty()) {
54 throw IllegalArgumentException("Digest data is null!");
55 }
56
57 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
58 uint8_t p1 = 0x00;
59
60 if (verificationMode) {
61 p1 += 1;
62 }
63
64 if (confidentialSessionMode) {
65 p1 += 2;
66 }
67
68 const uint8_t p2 = 0xFF;
69
70 std::vector<uint8_t> dataIn(2 + digestData.size());
71 dataIn[0] = workKif;
72 dataIn[1] = workKvc;
73 System::arraycopy(digestData, 0, dataIn, 2, digestData.size());
74
76 std::make_shared<ApduRequestAdapter>(
77 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, dataIn)));
78}
79
80const std::map<const int, const std::shared_ptr<StatusProperties>>
81 CmdSamDigestInit::initStatusTable()
82{
83 std::map<const int, const std::shared_ptr<StatusProperties>> m =
85
86 m.insert({0x6700,
87 std::make_shared<StatusProperties>("Incorrect Lc.",
89 m.insert({0x6900,
90 std::make_shared<StatusProperties>("An event counter cannot be incremented.",
91 typeid(CalypsoSamCounterOverflowException))});
92 m.insert({0x6985,
93 std::make_shared<StatusProperties>("Preconditions not satisfied.",
94 typeid(CalypsoSamAccessForbiddenException))});
95 m.insert({0x6A00,
96 std::make_shared<StatusProperties>("Incorrect P2.",
97 typeid(CalypsoSamIllegalParameterException))});
98 m.insert({0x6A83,
99 std::make_shared<StatusProperties>("Record not found: signing key not found.",
100 typeid(CalypsoSamDataAccessException))});
101
102 return m;
103}
104
105const std::map<const int, const std::shared_ptr<StatusProperties>>&
107{
108 return STATUS_TABLE;
109}
110
111}
112}
113}
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
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamDigestInit(const CalypsoSam::ProductType productType, const bool verificationMode, const bool confidentialSessionMode, const uint8_t workKif, const uint8_t workKvc, const std::vector< uint8_t > &digestData)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType