Advanced Utility Extensions
TOML Configuration File Management
We support reading strings, integers and their arrays in toml files, but other types are not supported yet.
toml file example:
[server]
host="http://127.0.0.1"
port=80
toml file reading example:
TomlConfig config;
config.LoadFile("./test.toml");
std::optional<std::string> host = config.GetString("server", "host");
if (!host.has_value()) return false;
std::optional<int64_t> port = config.GetInteger("server", "port");
if (!port.has_value()) return false;
JSON Support
We provide a json library that can be used in a trusted environment.
nlohmann::json test_json = {{"name", "OpenAI"},
{"age", 3},
{"active", true},
{"tags", {"AI", "ML", "NLP"}},
{"info", {{"type", "organization"}, {"founded", 2015}}}};
bool ok;
std::string value;
std::string err_msg;
ok = ssgx::json_t::fetch_json_string_node(test_json, "name", value, err_msg);
if (!ok) return false;
High-precision Numerical Computation
We provide high-precision number calculations running in a trusted environment, which currently only supports addition, subtraction, multiplication and division.
BigDecimal a("8932483294839248234309483204802.38408499");
BigDecimal b("123");
BigDecimal result = a.Multiply(b);
if (result != BigDecimal("1098695445265227532820066434190693.24245377")) return false;
Precision prec3(RoundType::RoundFloor, 6);
result = a.Multiply(b, prec3);
if (result != BigDecimal("1098695445265227532820066434190693.242453")) return false;
Logging System Support
We provide a very easy to use logging function with no output length limit.
// Multiple placeholders with varying types
SSGX_LOG(INFO) << "User: " << "John" << ", Age: " << 30 << ", Height: " << 1.75 << ", Status: " << "OK" << "\n";
// Chaining logs
SSGX_LOG(INFO) << "Start of chain...\n";
SSGX_LOG(WARN) << "Middle of chain...\n";
SSGX_LOG(FATAL) << "End of chain!\n";
HTTP Functionality
We encapsulate secure HttpClient and server communication interfaces, to enhance enclaves networking capabilities.
http client example:
ssgx::http_t::Client client("http://127.0.0.1", 80);
ssgx::http_t::Result result = client.Get("/check");
ssgx::utils_t::Printf("%d\n", result->StatusCode());
ssgx::utils_t::Printf("%s\n\n", result->Body().c_str());
http server example:
Server srv;
std::string url = "http://0.0.0.0:83";
srv.Listen(url);
srv.Get("/hello", [](auto& req, auto& resp) { HandleHello(req, resp); });
srv.Post("/echo", [](auto& req, auto& resp) { HandleEcho(req, resp); });
srv.Start();
while (1) {
ssgx::utils_t::sleep(10);
}