14#include "keyple/card/calypso/crypto/legacysam/CommandDigestInit.hpp"
20#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
21#include "keyple/card/calypso/crypto/legacysam/CounterOverflowException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
23#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
24#include "keyple/core/util/ApduUtil.hpp"
25#include "keyple/core/util/cpp/System.hpp"
26#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
34using keyple::core::util::ApduUtil;
35using keyple::core::util::cpp::System;
36using keyple::core::util::cpp::exception::IllegalArgumentException;
38const std::map<int, const std::shared_ptr<StatusProperties>>
39 CommandDigestInit::STATUS_TABLE = [] {
40 std::map<int, const std::shared_ptr<StatusProperties>> m(
41 Command::STATUS_TABLE);
45 std::make_shared<StatusProperties>(
46 "Incorrect Lc",
typeid(IllegalParameterException))},
48 std::make_shared<StatusProperties>(
49 "An event counter cannot be incremented",
50 typeid(CounterOverflowException))},
52 std::make_shared<StatusProperties>(
53 "Preconditions not satisfied",
54 typeid(AccessForbiddenException))},
56 std::make_shared<StatusProperties>(
57 "Incorrect P2",
typeid(IllegalParameterException))},
59 std::make_shared<StatusProperties>(
60 "Record not found: signing key not found",
61 typeid(DataAccessException))}});
65CommandDigestInit::CommandDigestInit(
66 std::shared_ptr<CommandContextDto> context,
67 bool verificationMode,
68 bool confidentialSessionMode,
71 const std::vector<std::uint8_t>& digestData)
72: Command(CommandRef::DIGEST_INIT, 0, context)
74 if (workKif == 0x00 || workKvc == 0x00) {
75 throw IllegalArgumentException(
76 "KIF or KVC is not set. KIF: " + std::to_string(workKif)
77 +
", KVC: " + std::to_string(workKvc) +
"]");
80 const std::uint8_t cla = context->getTargetSam()->getClassByte();
81 std::uint8_t p1 = 0x00;
83 if (verificationMode) {
87 if (confidentialSessionMode) {
91 const std::uint8_t p2 = 0xFF;
93 std::vector<std::uint8_t> dataIn(2 + digestData.size());
97 System::arraycopy(digestData, 0, dataIn, 2, digestData.size());
100 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
101 cla, getCommandRef().getInstructionByte(), p1, p2, dataIn)));
105CommandDigestInit::finalizeRequest()
111CommandDigestInit::isControlSamRequiredToFinalizeRequest()
const
117CommandDigestInit::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
119 setResponseAndCheckStatus(apduResponse);
122const std::map<int, const std::shared_ptr<StatusProperties>>&
123CommandDigestInit::getStatusTable()
const