Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
ApduResponseAdapter.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 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/core/service/ApduResponseAdapter.hpp"
15
16#include <iomanip>
17#include <memory>
18#include <sstream>
19#include <vector>
20
21#include "keyple/core/util/cpp/Arrays.hpp"
22#include "keyple/core/util/cpp/KeypleStd.hpp"
23
24namespace keyple {
25namespace core {
26namespace service {
27
28using keyple::core::util::cpp::Arrays;
29
30ApduResponseAdapter::ApduResponseAdapter(const std::vector<uint8_t>& apdu)
31: mApdu(apdu)
32, mStatusWord(
33 ((apdu[apdu.size() - 2] & 0x000000FF) << 8)
34 + (apdu[apdu.size() - 1] & 0x000000FF))
35{
36}
37
38const std::vector<uint8_t>&
39ApduResponseAdapter::getApdu() const
40{
41 return mApdu;
42}
43
44void
45ApduResponseAdapter::setApdu(const std::vector<std::uint8_t>& apdu)
46{
47 mApdu = apdu;
48}
49
50std::vector<uint8_t>
51ApduResponseAdapter::getDataOut() const
52{
53 return Arrays::copyOfRange(mApdu, 0, static_cast<int>(mApdu.size()) - 2);
54}
55
56int
57ApduResponseAdapter::getStatusWord() const
58{
59 return mStatusWord;
60}
61
62std::ostream&
63operator<<(std::ostream& os, const ApduResponseAdapter& ara)
64{
65 std::stringstream ssSw;
66 ssSw << std::uppercase << std::hex << std::setfill('0') << std::setw(4)
67 << ara.mStatusWord;
68
69 os << "APDU_RESPONSE_ADAPTER: {"
70 << "APDU = " << ara.mApdu << ", "
71 << "STATUS_WORD = " << ssSw.str() << "}";
72
73 return os;
74}
75
76std::ostream&
77operator<<(std::ostream& os, const std::shared_ptr<ApduResponseAdapter> ara)
78{
79 os << *ara.get();
80
81 return os;
82}
83
84} /* namespace service */
85} /* namespace core */
86} /* namespace keyple */
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduResponseAdapter > ara)