keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommandDigestUpdateMultiple.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/CommandDigestUpdateMultiple.hpp"
15
16#include <map>
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
23#include "keyple/card/calypso/crypto/legacysam/IncorrectInputDataException.hpp"
24#include "keyple/core/util/ApduUtil.hpp"
25#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30namespace crypto {
31namespace legacysam {
32
33using keyple::core::util::ApduUtil;
34using keyple::core::util::cpp::exception::IllegalArgumentException;
35
36const std::map<int, const std::shared_ptr<StatusProperties>>
37 CommandDigestUpdateMultiple::STATUS_TABLE = [] {
38 std::map<int, const std::shared_ptr<StatusProperties>> m(
39 Command::STATUS_TABLE);
40
41 m.insert(
42 {{0x6700,
43 std::make_shared<StatusProperties>(
44 "Incorrect Lc", typeid(IllegalParameterException))},
45 {0x6985,
46 std::make_shared<StatusProperties>(
47 "Preconditions not satisfied",
48 typeid(AccessForbiddenException))},
49 {0x6A80,
50 std::make_shared<StatusProperties>(
51 "Incorrect value in the incoming data: incorrect structure",
52 typeid(IncorrectInputDataException))},
53 {0x6B00,
54 std::make_shared<StatusProperties>(
55 "Incorrect P1 or P2", typeid(IllegalParameterException))}});
56 return m;
57 }();
58
59CommandDigestUpdateMultiple::CommandDigestUpdateMultiple(
60 std::shared_ptr<CommandContextDto> context,
61 const std::vector<uint8_t>& digestData)
62: Command(CommandRef::DIGEST_UPDATE_MULTIPLE, 0, context)
63{
64 const std::uint8_t cla = context->getTargetSam()->getClassByte();
65 const std::uint8_t p1 = 0x80;
66 const std::uint8_t p2 = 0x00;
67
68 if (digestData.size() > 255) {
69 throw IllegalArgumentException(
70 "Digest data is too long. Expected 0-255 bytes, got "
71 + std::to_string(digestData.size()));
72 }
73
74 setApduRequest(
75 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
76 cla, getCommandRef().getInstructionByte(), p1, p2, digestData)));
77}
78
79void
80CommandDigestUpdateMultiple::finalizeRequest()
81{
82 /* Nothing to do */
83}
84
85bool
86CommandDigestUpdateMultiple::isControlSamRequiredToFinalizeRequest() const
87{
88 return false;
89}
90
91void
92CommandDigestUpdateMultiple::parseResponse(
93 const std::shared_ptr<ApduResponseApi> apduResponse)
94{
95 setResponseAndCheckStatus(apduResponse);
96}
97
98const std::map<int, const std::shared_ptr<StatusProperties>>&
99CommandDigestUpdateMultiple::getStatusTable() const
100{
101 return STATUS_TABLE;
102}
103
104} /* namespace legacysam */
105} /* namespace crypto */
106} /* namespace calypso */
107} /* namespace card */
108} /* namespace keyple */