Keypop Calypso Card C++ API - 2.1.2
Component of the Keypop C++ API
FileHeader.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 <vector>
19
21
22namespace keypop {
23namespace calypso {
24namespace card {
25namespace card {
26
33public:
40 virtual uint16_t getLid() const = 0;
41
50 virtual const std::shared_ptr<uint8_t>& getDfStatus() const = 0;
51
58 virtual ElementaryFile::Type getEfType() const = 0;
59
72 virtual int getRecordsNumber() const = 0;
73
87 virtual int getRecordSize() const = 0;
88
97 virtual const std::vector<std::uint8_t>& getAccessConditions() const = 0;
98
107 virtual const std::vector<std::uint8_t>& getKeyIndexes() const = 0;
108
118 virtual const std::shared_ptr<std::uint16_t> getSharedReference() const = 0;
119
124 friend std::ostream&
125 operator<<(std::ostream& os, const FileHeader& fh) {
126 const char* efType;
127 switch (fh.getEfType()) {
128 case ElementaryFile::Type::LINEAR: efType = "LINEAR"; break;
129 case ElementaryFile::Type::BINARY: efType = "BINARY"; break;
130 case ElementaryFile::Type::CYCLIC: efType = "CYCLIC"; break;
131 case ElementaryFile::Type::COUNTERS: efType = "COUNTERS"; break;
132 case ElementaryFile::Type::SIMULATED_COUNTERS:
133 efType = "SIMULATED_COUNTERS";
134 break;
135 default: efType = "UNKNOWN"; break;
136 }
137
138 /* Formatted apart so the caller's stream keeps its own flags. */
139 std::ostringstream ss;
140 ss << std::uppercase << std::hex << std::setfill('0');
141
142 ss << "FILE_HEADER: {LID: " << std::setw(4) << fh.getLid()
143 << "h, EF_TYPE: " << efType << std::dec
144 << ", RECORDS: " << fh.getRecordsNumber()
145 << ", RECORD_SIZE: " << fh.getRecordSize() << std::hex
146 << ", ACCESS_CONDITIONS: ";
147 for (const auto byte : fh.getAccessConditions()) {
148 ss << std::setw(2) << static_cast<int>(byte);
149 }
150 ss << ", KEY_INDEXES: ";
151 for (const auto byte : fh.getKeyIndexes()) {
152 ss << std::setw(2) << static_cast<int>(byte);
153 }
154 ss << ", DF_STATUS: ";
155 if (fh.getDfStatus() != nullptr) {
156 ss << std::setw(2) << static_cast<int>(*fh.getDfStatus()) << "h";
157 } else {
158 ss << "null";
159 }
160 ss << ", SHARED_REFERENCE: ";
161 if (fh.getSharedReference() != nullptr) {
162 ss << std::setw(4) << *fh.getSharedReference() << "h";
163 } else {
164 ss << "null";
165 }
166 ss << "}";
167
168 os << ss.str();
169
170 return os;
171 }
172
176 friend std::ostream&
177 operator<<(std::ostream& os, const std::shared_ptr<FileHeader>& fh) {
178 if (fh == nullptr) {
179 os << "FILE_HEADER: null";
180 } else {
181 os << *fh;
182 }
183
184 return os;
185 }
186};
187
188} /* namespace card */
189} /* namespace card */
190} /* namespace calypso */
191} /* namespace keypop */
friend std::ostream & operator<<(std::ostream &os, const FileHeader &fh)
Renders the header fields, so that a log shows the content and not the address of the object.
Definition: FileHeader.hpp:125
virtual const std::shared_ptr< uint8_t > & getDfStatus() const =0
Gets the DF status.
virtual const std::shared_ptr< std::uint16_t > getSharedReference() const =0
Gets the non-zero unique identifier of the shared data when the file data is shared.
virtual int getRecordsNumber() const =0
Gets the number of records :
virtual ElementaryFile::Type getEfType() const =0
Gets the Elementary File type.
virtual const std::vector< std::uint8_t > & getAccessConditions() const =0
Gets a reference to the access conditions.
virtual int getRecordSize() const =0
Gets the size of a record :
virtual const std::vector< std::uint8_t > & getKeyIndexes() const =0
Gets a reference to the keys indexes.
virtual uint16_t getLid() const =0
Gets the associated LID.