14#include "keyple/card/calypso/crypto/legacysam/CommandDigestAuthenticate.hpp"
20#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
21#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/SecurityDataException.hpp"
23#include "keyple/core/util/ApduUtil.hpp"
24#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
32using keyple::core::util::ApduUtil;
33using keyple::core::util::cpp::exception::IllegalArgumentException;
35const std::map<int, const std::shared_ptr<StatusProperties>>
36 CommandDigestAuthenticate::STATUS_TABLE = [] {
37 std::map<int, const std::shared_ptr<StatusProperties>> m(
38 Command::STATUS_TABLE);
42 std::make_shared<StatusProperties>(
43 "Incorrect Lc",
typeid(IllegalParameterException))},
45 std::make_shared<StatusProperties>(
46 "Preconditions not satisfied",
47 typeid(AccessForbiddenException))},
49 std::make_shared<StatusProperties>(
50 "Incorrect signature",
typeid(SecurityDataException))}});
54CommandDigestAuthenticate::CommandDigestAuthenticate(
55 std::shared_ptr<CommandContextDto> context,
56 const std::vector<uint8_t>& signature)
57: Command(CommandRef::DIGEST_AUTHENTICATE, 0, context)
59 if (signature.size() != 4 && signature.size() != 8
60 && signature.size() != 16) {
61 throw IllegalArgumentException(
62 "Signature is not the right length. Expected: 4|8|16, Actual: "
63 + std::to_string(signature.size()));
66 const std::uint8_t cla = context->getTargetSam()->getClassByte();
67 const std::uint8_t p1 = 0x00;
68 const std::uint8_t p2 = 0x00;
71 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
72 cla, getCommandRef().getInstructionByte(), p1, p2, signature)));
76CommandDigestAuthenticate::finalizeRequest()
82CommandDigestAuthenticate::isControlSamRequiredToFinalizeRequest()
const
88CommandDigestAuthenticate::parseResponse(
89 std::shared_ptr<ApduResponseApi> apduResponse)
91 setResponseAndCheckStatus(apduResponse);
94const std::map<int, const std::shared_ptr<StatusProperties>>&
95CommandDigestAuthenticate::getStatusTable()
const