Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamDigestClose.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 "CmdSamDigestClose.h"
14
15/* Keyple Card Calypso */
17#include "SamUtilAdapter.h"
18
19/* Keyple Core Util */
20#include "ApduUtil.h"
21#include "IllegalArgumentException.h"
22
23namespace keyple {
24namespace card {
25namespace calypso {
26
27using namespace keyple::core::util;
28
29const CalypsoSamCommand CmdSamDigestClose::mCommand = CalypsoSamCommand::DIGEST_CLOSE;
30
31const std::map<const int, const std::shared_ptr<StatusProperties>>
32 CmdSamDigestClose::STATUS_TABLE = initStatusTable();
33
35 const uint8_t expectedResponseLength)
36: AbstractSamCommand(mCommand)
37{
38 if (expectedResponseLength != 0x04 && expectedResponseLength != 0x08) {
39 throw IllegalArgumentException("Bad digest length! Expected 4 or 8, got " +
40 std::to_string(expectedResponseLength));
41 }
42
43 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
44 const uint8_t p1 = 0x00;
45 const uint8_t p2 = 0x00;
46
48 std::make_shared<ApduRequestAdapter>(
49 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, expectedResponseLength)));
50}
51
52const std::vector<uint8_t> CmdSamDigestClose::getSignature() const
53{
54 return isSuccessful() ? getApduResponse()->getDataOut() : std::vector<uint8_t>();
55}
56
57const std::map<const int, const std::shared_ptr<StatusProperties>>
58 CmdSamDigestClose::initStatusTable()
59{
60 std::map<const int, const std::shared_ptr<StatusProperties>> m =
62
63 m.insert({0x6985,
64 std::make_shared<StatusProperties>("Preconditions not satisfied.",
66
67 return m;
68}
69
70const std::map<const int, const std::shared_ptr<StatusProperties>>&
72{
73 return STATUS_TABLE;
74}
75
76}
77}
78}
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
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_CLOSE
CmdSamDigestClose(const CalypsoSam::ProductType productType, const uint8_t expectedResponseLength)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::vector< uint8_t > getSignature() const
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType