Keypop Card C++ API 2.0.0
Reference Card API for C++
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
49 virtual const std::vector<uint8_t> getDataOut() const = 0;
50
57 virtual int getStatusWord() const = 0;
58
62 friend std::ostream&
63 operator<<(std::ostream& os, const ApduResponseApi& ara) {
64 const std::vector<uint8_t> apdu = ara.getApdu();
65 const std::vector<uint8_t> dataOut = ara.getDataOut();
66
67 std::stringstream ssApdu;
68 for (const auto val : apdu) {
69 ssApdu << std::uppercase << std::hex << std::setfill('0')
70 << std::setw(2) << static_cast<int>(val);
71 }
72
73 std::stringstream ssDataOut;
74 for (const auto val : dataOut) {
75 ssDataOut << std::uppercase << std::hex << std::setfill('0')
76 << std::setw(2) << static_cast<int>(val);
77 }
78
79 os << "APDU_RESPONSE_API: {"
80 << "APDU: " << ssApdu.str() << ", "
81 << "DATA_OUT: " << ssDataOut.str() << ", "
82 << "STATUS_WORD: " << ara.getStatusWord() << "}";
83
84 return os;
85 }
86
90 friend std::ostream&
91 operator<<(std::ostream& os, const std::shared_ptr<ApduResponseApi> ara) {
92 os << *ara.get();
93
94 return os;
95 }
96
100 friend std::ostream&
102 std::ostream& os,
103 const std::vector<std::shared_ptr<ApduResponseApi>>& aras) {
104 os << "APDU_RESPONSE_APIS: {";
105
106 for (auto it = std::begin(aras); it != std::end(aras); ++it) {
107 os << *it;
108 if (it != aras.end() - 1) {
109 os << ", ";
110 }
111 }
112
113 os << "}";
114
115 return os;
116 }
117};
118
119} /* namespace card */
120} /* namespace keypop */
virtual const std::vector< uint8_t > & getApdu() const =0
virtual const std::vector< uint8_t > getDataOut() const =0
friend std::ostream & operator<<(std::ostream &os, const ApduResponseApi &ara)
virtual int getStatusWord() const =0