keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommandDigestClose.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 *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/card/calypso/crypto/legacysam/CommandDigestClose.hpp"
15
16#include <map>
17#include <memory>
18#include <vector>
19
20#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
21#include "keyple/core/util/ApduUtil.hpp"
22
23namespace keyple {
24namespace card {
25namespace calypso {
26namespace crypto {
27namespace legacysam {
28
29using keyple::core::util::ApduUtil;
30
31const std::map<int, const std::shared_ptr<StatusProperties>>
32 CommandDigestClose::STATUS_TABLE = [] {
33 std::map<int, const std::shared_ptr<StatusProperties>> m(
34 Command::STATUS_TABLE);
35
36 m.insert(
37 {{0x6985,
38 std::make_shared<StatusProperties>(
39 "Preconditions not satisfied",
40 typeid(AccessForbiddenException))}});
41 return m;
42 }();
43
44CommandDigestClose::CommandDigestClose(
45 std::shared_ptr<CommandContextDto> context, int expectedResponseLength)
46: Command(CommandRef::DIGEST_CLOSE, expectedResponseLength, context)
47{
48 setApduRequest(
49 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
50 context->getTargetSam()->getClassByte(),
51 getCommandRef().getInstructionByte(),
52 0x00,
53 0x00,
54 static_cast<uint8_t>(expectedResponseLength))));
55}
56const std::vector<std::uint8_t>&
57CommandDigestClose::getMac() const
58{
59 return mMac;
60}
61
62void
63CommandDigestClose::finalizeRequest()
64{
65 /* nothing to do */
66}
67
68bool
69CommandDigestClose::isControlSamRequiredToFinalizeRequest() const
70{
71 return false;
72}
73
74void
75CommandDigestClose::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
76{
77 setResponseAndCheckStatus(apduResponse);
78 mMac = apduResponse->getDataOut();
79}
80
81const std::map<int, const std::shared_ptr<StatusProperties>>&
82CommandDigestClose::getStatusTable() const
83{
84 return STATUS_TABLE;
85}
86
87} /* namespace legacysam */
88} /* namespace crypto */
89} /* namespace calypso */
90} /* namespace card */
91} /* namespace keyple */