Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx_config_t.h
Go to the documentation of this file.
1#ifndef SAFEHERON_SGX_TRUSTED_CONFIG_H
2#define SAFEHERON_SGX_TRUSTED_CONFIG_H
3
4#include <optional>
5#include <string>
6#include <vector>
7
8namespace ssgx {
47namespace config_t {
48
54struct TomlKey {
55 enum class KeyType {
56 Integer = 0,
57 String = 1
58 };
63 explicit TomlKey(int index_key) {
65 index_key_ = index_key;
66 }
71 explicit TomlKey(const char* str_key) {
73 str_key_.assign(str_key);
74 }
78 ~TomlKey() = default;
79
81 int index_key_{};
82 std::string str_key_;
83};
84
93template <typename T>
94std::vector<TomlKey> MakeArgs(T first) {
95 std::vector<TomlKey> vec;
96 vec.reserve(6);
97 vec.push_back(TomlKey(first));
98 return vec;
99}
100
112template <typename T, typename... Types>
113std::vector<TomlKey> MakeArgs(T first, Types... args) {
114 std::vector<TomlKey> vec = std::move(MakeArgs(args...));
115 vec.push_back(TomlKey(first));
116 return vec;
117}
118
130 public:
134 TomlConfig() : ref_untrusted_toml_obj_(0) {};
135
139 ~TomlConfig();
140
141 public:
157 bool LoadFile(const char* toml_file_path);
158
182 template <typename... Types>
183 std::optional<int64_t> GetInteger(Types... args) {
184 std::vector<TomlKey> path = std::move(MakeArgs(args...));
185 return GetInteger(path);
186 };
187
211 template <typename... Types>
212 std::optional<std::string> GetString(Types... args) {
213 std::vector<TomlKey> path = std::move(MakeArgs(args...));
214 return GetString(path);
215 };
216
240 template <typename... Types>
241 std::optional<std::vector<int64_t>> GetIntegerArray(Types... args) {
242 std::vector<TomlKey> path = std::move(MakeArgs(args...));
243 return GetIntegerArray(path);
244 };
245
269 template <typename... Types>
270 std::optional<std::vector<std::string>> GetStringArray(Types... args) {
271 std::vector<TomlKey> path = std::move(MakeArgs(args...));
272 return GetStringArray(path);
273 };
274
290 [[nodiscard]] std::string GetLastErrorMsg() const {
291 return err_msg_;
292 }
293
294 private:
302 std::optional<int64_t> GetInteger(const std::vector<TomlKey>& path);
303
311 std::optional<std::string> GetString(const std::vector<TomlKey>& path);
312
320 std::optional<std::vector<int64_t>> GetIntegerArray(const std::vector<TomlKey>& path);
321
329 std::optional<std::vector<std::string>> GetStringArray(const std::vector<TomlKey>& path);
330
340 bool GetArrayValues(uint64_t ptr_toml, const std::string &path_str, std::string &values);
341
342 private:
343 uint64_t ref_untrusted_toml_obj_;
345 std::string err_msg_;
346};
347
348} // namespace config_t
349} // namespace ssgx
350
351#endif // SAFEHERON_SGX_TRUSTED_CONFIG_H
A trusted wrapper around the untrusted toml library
Definition ssgx_config_t.h:124
std::optional< std::vector< std::string > > GetStringArray(Types... args)
Finds a string array of values in the TOML file.
Definition ssgx_config_t.h:265
bool LoadFile(const char *toml_file_path)
Load a TOML file and initialize the TOML object.
std::optional< int64_t > GetInteger(Types... args)
Finds an integer value in the TOML file.
Definition ssgx_config_t.h:178
TomlConfig()
Default constructor for the TOML class.
Definition ssgx_config_t.h:129
std::optional< std::string > GetString(Types... args)
Finds a string value in the TOML file.
Definition ssgx_config_t.h:207
std::string GetLastErrorMsg() const
Get the error code when the function returns false.
Definition ssgx_config_t.h:285
std::optional< std::vector< int64_t > > GetIntegerArray(Types... args)
Finds an integer array of values in the TOML file.
Definition ssgx_config_t.h:236
std::vector< TomlKey > MakeArgs(T first)
Creates a vector of TomlKey objects from a single key.
Definition ssgx_config_t.h:89
Definition ssgx_attestation_t.h:6
std::string str_key_
Store the string key (if type is string)
Definition ssgx_config_t.h:77
int index_key_
Store the integer key (if type is integer)
Definition ssgx_config_t.h:76
~TomlKey()=default
Destruction.
TomlKey(int index_key)
Constructs a TomlKey with an integer key.
Definition ssgx_config_t.h:58
KeyType type_
The type of key: integer or string.
Definition ssgx_config_t.h:75
KeyType
Definition ssgx_config_t.h:50
@ String
The key is a String type.
@ Integer
The key is an Integer type.