Keypop Card C++ API 2.0.0
Reference Card API for C++
ApduRequestSpi.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 {
23namespace spi {
24
32public:
36 virtual ~ApduRequestSpi() = default;
37
44 virtual std::vector<uint8_t> getApdu() const = 0;
45
53 virtual const std::vector<int>& getSuccessfulStatusWords() const = 0;
54
63 virtual const std::string& getInfo() const = 0;
64
68 friend std::ostream&
69 operator<<(std::ostream& os, const ApduRequestSpi& ars) {
70 const std::vector<uint8_t> apdu = ars.getApdu();
71 const std::vector<int> sw = ars.getSuccessfulStatusWords();
72
73 std::stringstream ssApdu;
74 for (const auto val : apdu) {
75 ssApdu << std::uppercase << std::hex << std::setfill('0')
76 << std::setw(2) << static_cast<int>(val);
77 }
78
79 std::stringstream ssSw;
80 for (auto it = std::begin(sw); it != std::end(sw); ++it) {
81 ssSw << std::uppercase << std::hex << std::setfill('0')
82 << std::setw(4) << static_cast<int>(*it);
83 if (it != sw.end() - 1) {
84 ssSw << ", ";
85 }
86 }
87
88 os << "APDU_REQUEST_SPI: {"
89 << "APDU: " << ssApdu.str() << ", "
90 << "SUCCESSFUL_STATUS_WORD: " << ssSw.str() << ", "
91 << "INFO: " << ars.getInfo() << "}";
92
93 return os;
94 }
95
99 friend std::ostream&
100 operator<<(std::ostream& os, const std::shared_ptr<ApduRequestSpi> ars) {
101 os << *ars.get();
102
103 return os;
104 }
105
109 friend std::ostream&
111 std::ostream& os,
112 const std::vector<std::shared_ptr<ApduRequestSpi>>& arss) {
113 os << "APDU_REQUEST_SPIS: {";
114
115 for (auto it = std::begin(arss); it != std::end(arss); ++it) {
116 os << *it;
117 if (it != arss.end() - 1) {
118 os << ", ";
119 }
120 }
121
122 os << "}";
123
124 return os;
125 }
126};
127
128} /* namespace spi */
129} /* namespace card */
130} /* namespace keypop */
virtual const std::string & getInfo() const =0
virtual const std::vector< int > & getSuccessfulStatusWords() const =0
virtual std::vector< uint8_t > getApdu() const =0
friend std::ostream & operator<<(std::ostream &os, const ApduRequestSpi &ars)