Keypop Card C++ API - 2.0.1
Component of the Keypop C++ API
ApduResponseApi.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * This program and the accompanying materials are made available under the *
5 * terms of the MIT License which is available at *
6 * https://opensource.org/licenses/MIT. *
7 * *
8 * SPDX-License-Identifier: MIT *
9 ******************************************************************************/
10
11#pragma once
12
13#include <cstdint>
14#include <iomanip>
15#include <memory>
16#include <ostream>
17#include <sstream>
18#include <string>
19#include <vector>
20
21namespace keypop {
22namespace card {
23
33public:
40 virtual const std::vector<uint8_t>& getApdu() const = 0;
41
45 virtual void setApdu(const std::vector<std::uint8_t>& apdu) = 0;
46
54 virtual std::vector<uint8_t> getDataOut() const = 0;
55
62 virtual int getStatusWord() const = 0;
63
67 friend std::ostream&
68 operator<<(std::ostream& os, const ApduResponseApi& ara) {
69 const std::vector<uint8_t>& apdu = ara.getApdu();
70 const std::vector<uint8_t> dataOut = ara.getDataOut();
71
72 std::stringstream ssApdu;
73 for (const auto val : apdu) {
74 ssApdu << std::uppercase << std::hex << std::setfill('0')
75 << std::setw(2) << static_cast<int>(val);
76 }
77
78 std::stringstream ssDataOut;
79 for (const auto val : dataOut) {
80 ssDataOut << std::uppercase << std::hex << std::setfill('0')
81 << std::setw(2) << static_cast<int>(val);
82 }
83
84 std::stringstream ssSw;
85 ssSw << std::uppercase << std::hex << std::setfill('0') << std::setw(4)
86 << ara.getStatusWord();
87
88 os << "APDU_RESPONSE_API: {"
89 << "APDU: " << ssApdu.str() << ", "
90 << "DATA_OUT: " << ssDataOut.str() << ", "
91 << "STATUS_WORD: " << ssSw.str() << "}";
92
93 return os;
94 }
95
99 friend std::ostream&
100 operator<<(std::ostream& os, const std::shared_ptr<ApduResponseApi> ara) {
101 os << *ara.get();
102
103 return os;
104 }
105
109 friend std::ostream&
111 std::ostream& os,
112 const std::vector<std::shared_ptr<ApduResponseApi>>& aras) {
113 os << "APDU_RESPONSE_APIS: {";
114
115 for (auto it = std::begin(aras); it != std::end(aras); ++it) {
116 os << *it;
117 if (it != aras.end() - 1) {
118 os << ", ";
119 }
120 }
121
122 os << "}";
123
124 return os;
125 }
126};
127
128} /* namespace card */
129} /* namespace keypop */
Data received in response to an APDU command.
virtual void setApdu(const std::vector< std::uint8_t > &apdu)=0
C++.
virtual const std::vector< uint8_t > & getApdu() const =0
Gets the raw data received from the card (including the status word).
virtual std::vector< uint8_t > getDataOut() const =0
Gets the data part of the response received from the card (excluding the status word).
friend std::ostream & operator<<(std::ostream &os, const ApduResponseApi &ara)
virtual int getStatusWord() const =0
Gets the status word of the APDU as an int.