Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamDigestUpdate.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 "CmdSamDigestUpdate.h"
14
15/* Keyple Card Calypso */
20#include "SamUtilAdapter.h"
21
22/* Keyple Core Util */
23#include "ApduUtil.h"
24#include "IllegalArgumentException.h"
25
26namespace keyple {
27namespace card {
28namespace calypso {
29
30using namespace keyple::core::util;
31using namespace keyple::core::util::cpp::exception;
32
33const CalypsoSamCommand CmdSamDigestUpdate::mCommand = CalypsoSamCommand::DIGEST_UPDATE;
34
35const std::map<const int, const std::shared_ptr<StatusProperties>>
36 CmdSamDigestUpdate::STATUS_TABLE = initStatusTable();
37
39 const bool encryptedSession,
40 const std::vector<uint8_t>& digestData)
41: AbstractSamCommand(mCommand)
42{
43 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
44 const uint8_t p1 = 0x00;
45 const uint8_t p2 = encryptedSession ? 0x80 : 0x00;
46
47 if (digestData.empty() || digestData.size() > 255) {
48 throw IllegalArgumentException("Digest data null or too long!");
49 }
50
52 std::make_shared<ApduRequestAdapter>(
53 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, digestData)));
54}
55
56const std::map<const int, const std::shared_ptr<StatusProperties>>
57 CmdSamDigestUpdate::initStatusTable()
58{
59 std::map<const int, const std::shared_ptr<StatusProperties>> m =
61
62 m.insert({0x6700,
63 std::make_shared<StatusProperties>("Incorrect Lc.",
65 m.insert({0x6985,
66 std::make_shared<StatusProperties>("Preconditions not satisfied.",
67 typeid(CalypsoSamAccessForbiddenException))});
68 m.insert({0x6A80,
69 std::make_shared<StatusProperties>("Incorrect value in the incoming data: session " \
70 "in Rev.3.2 mode with encryption/decryption " \
71 "active and not enough data (less than 5 bytes " \
72 "for and odd occurrence or less than 2 bytes " \
73 "CalypsoSamIllegalParameterException for an even" \
74 " occurrence).",
75 typeid(CalypsoSamIncorrectInputDataException))});
76 m.insert({0x6B00,
77 std::make_shared<StatusProperties>("Incorrect P1 or P2.",
78 typeid(CalypsoSamIllegalParameterException))});
79
80 return m;
81}
82
83const std::map<const int, const std::shared_ptr<StatusProperties>>&
85{
86 return STATUS_TABLE;
87}
88
89}
90}
91}
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_UPDATE
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamDigestUpdate(const CalypsoSam::ProductType productType, const bool encryptedSession, const std::vector< uint8_t > &digestData)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType