14#include "keyple/card/calypso/crypto/legacysam/CommandDigestUpdate.hpp"
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"
33using keyple::core::util::ApduUtil;
34using keyple::core::util::cpp::exception::IllegalArgumentException;
36const std::map<int, const std::shared_ptr<StatusProperties>>
37 CommandDigestUpdate::STATUS_TABLE = [] {
38 std::map<int, const std::shared_ptr<StatusProperties>> m(
39 Command::STATUS_TABLE);
43 std::make_shared<StatusProperties>(
44 "Incorrect Lc",
typeid(IllegalParameterException))},
46 std::make_shared<StatusProperties>(
47 "Preconditions not satisfied",
48 typeid(AccessForbiddenException))},
50 std::make_shared<StatusProperties>(
51 std::string(
"Incorrect value in the incoming data: session")
52 +
" in Rev.3.2 mode with encryption/decryption active "
54 +
" enough data (less than 5 bytes for and odd "
56 +
"less than 2 bytes for an even occurrence)",
57 typeid(IncorrectInputDataException))},
59 std::make_shared<StatusProperties>(
60 "Incorrect P1 or P2",
typeid(IllegalParameterException))}});
64CommandDigestUpdate::CommandDigestUpdate(
65 std::shared_ptr<CommandContextDto> context,
66 bool encryptedSession,
67 const std::vector<uint8_t>& digestData)
68: Command(CommandRef::DIGEST_UPDATE, 0, context)
70 const std::uint8_t cla = context->getTargetSam()->getClassByte();
71 const std::uint8_t p1 = 0x00;
72 const std::uint8_t p2 = encryptedSession ? 0x80 : 0x00;
74 if (digestData.size() > 255) {
75 throw IllegalArgumentException(
76 "Digest data is too long. Expected 0-255 bytes, got "
77 + std::to_string(digestData.size()));
81 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
82 cla, getCommandRef().getInstructionByte(), p1, p2, digestData)));
85const std::vector<std::uint8_t>&
86CommandDigestUpdate::getProcessedData()
const
88 return mProcessedData;
92CommandDigestUpdate::finalizeRequest()
98CommandDigestUpdate::isControlSamRequiredToFinalizeRequest()
const
104CommandDigestUpdate::parseResponse(
105 const std::shared_ptr<ApduResponseApi> apduResponse)
107 setResponseAndCheckStatus(apduResponse);
109 mProcessedData = apduResponse->getDataOut();
112const std::map<int, const std::shared_ptr<StatusProperties>>&
113CommandDigestUpdate::getStatusTable()
const