Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdSamDigestAuthenticate.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
14
15/* Keyple Card Calypso */
19#include "SamUtilAdapter.h"
20
21/* Keyple Core Util */
22#include "ApduUtil.h"
23#include "IllegalArgumentException.h"
24
25namespace keyple {
26namespace card {
27namespace calypso {
28
29using namespace keyple::core::util;
30using namespace keyple::core::util::cpp::exception;
31
32const CalypsoSamCommand CmdSamDigestAuthenticate::mCommand = CalypsoSamCommand::DIGEST_AUTHENTICATE;
33
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdSamDigestAuthenticate::STATUS_TABLE = initStatusTable();
36
38 const std::vector<uint8_t>& signature)
39: AbstractSamCommand(mCommand)
40{
41 if (signature.empty()) {
42 throw IllegalArgumentException("Signature can't be null");
43 }
44
45 if (signature.size() != 4 && signature.size() != 8 && signature.size() != 16) {
46 throw IllegalArgumentException("Signature is not the right length : length is " +
47 std::to_string(signature.size()));
48 }
49
50 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
51 const uint8_t p1 = 0x00;
52 const uint8_t p2 = 0x00;
53
55 std::make_shared<ApduRequestAdapter>(
56 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, signature)));
57}
58
59const std::map<const int, const std::shared_ptr<StatusProperties>>
60 CmdSamDigestAuthenticate::initStatusTable()
61{
62 std::map<const int, const std::shared_ptr<StatusProperties>> m =
64
65 m.insert({0x6700,
66 std::make_shared<StatusProperties>("Incorrect Lc.",
68 m.insert({0x6985,
69 std::make_shared<StatusProperties>("Preconditions not satisfied.",
70 typeid(CalypsoSamAccessForbiddenException))});
71 m.insert({0x6988,
72 std::make_shared<StatusProperties>("Incorrect signature.",
73 typeid(CalypsoSamSecurityDataException))});
74
75 return m;
76}
77
78const std::map<const int, const std::shared_ptr<StatusProperties>>&
80{
81 return STATUS_TABLE;
82}
83
84}
85}
86}
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
static const CalypsoSamCommand DIGEST_AUTHENTICATE
CmdSamDigestAuthenticate(const CalypsoSam::ProductType productType, const std::vector< uint8_t > &signature)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType