Skip to content
API Documentation
BastionGuard™
BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp} Namespace Reference

Functions

std::optional< std::string > json_string (const std::string &jsonjson, const std::string &key)
std::optional< std::uint64_t > json_u64 (const std::string &jsonjson, const std::string &key)
std::optional< std::int64_t > json_i64 (const std::string &jsonjson, const std::string &key)
std::uint32_t as_u32 (const std::optional< std::uint64_t > &value)
std::int32_t as_i32 (const std::optional< std::int64_t > &value)
std::string octal_mode (const std::uint32_t mode)
bool has_prefix (const std::string &path, const std::string &prefix)

Function Documentation

◆ as_i32()

std::int32_t BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::as_i32 ( const std::optional< std::int64_t > & value)

Definition at line 96 of file RootGuardEvent.cpp.

97{
98 if (!value ||
99 *value < std::numeric_limits<std::int32_t>::min() ||
100 *value > std::numeric_limits<std::int32_t>::max())
101 return 0;
102 return static_cast<std::int32_t>(*value);
103}

References as_i32().

Referenced by as_i32().

◆ as_u32()

std::uint32_t BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::as_u32 ( const std::optional< std::uint64_t > & value)

Definition at line 90 of file RootGuardEvent.cpp.

91{
92 return value && *value <= 0xffffffffULL
93 ? static_cast<std::uint32_t>(*value) : 0U;
94}

References as_u32().

Referenced by as_u32().

◆ has_prefix()

bool BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::has_prefix ( const std::string & path,
const std::string & prefix )

Definition at line 112 of file RootGuardEvent.cpp.

113{
114 return path == prefix ||
115 (path.size() > prefix.size() && path.compare(0, prefix.size(), prefix) == 0 &&
116 path[prefix.size()] == '/');
117}

References has_prefix().

Referenced by has_prefix().

◆ json_i64()

std::optional< std::int64_t > BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::json_i64 ( const std::string & json,
const std::string & key )

Definition at line 70 of file RootGuardEvent.cpp.

72{
73 const std::string marker = "\"" + key + "\":";
74 const auto begin = json.find(marker);
75 if (begin == std::string::npos)
76 return std::nullopt;
77
78 std::size_t consumed = 0;
79 try {
80 const long long value =
81 std::stoll(json.substr(begin + marker.size()), &consumed, 10);
82 if (consumed == 0)
83 return std::nullopt;
84 return static_cast<std::int64_t>(value);
85 } catch (...) {
86 return std::nullopt;
87 }
88}
nlohmann::json json
Definition Backend.cpp:2908

References json_i64().

Referenced by json_i64().

◆ json_string()

std::optional< std::string > BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::json_string ( const std::string & json,
const std::string & key )

Definition at line 17 of file RootGuardEvent.cpp.

19{
20 const std::string marker = "\"" + key + "\":\"";
21 const auto begin = json.find(marker);
22 if (begin == std::string::npos)
23 return std::nullopt;
24
25 std::string result;
26 bool escaped = false;
27 for (std::size_t index = begin + marker.size(); index < json.size(); ++index) {
28 const char character = json[index];
29 if (escaped) {
30 switch (character) {
31 case 'n': result.push_back('\n'); break;
32 case 'r': result.push_back('\r'); break;
33 case 't': result.push_back('\t'); break;
34 case '\\': result.push_back('\\'); break;
35 case '"': result.push_back('"'); break;
36 default: result.push_back(character); break;
37 }
38 escaped = false;
39 } else if (character == '\\') {
40 escaped = true;
41 } else if (character == '"') {
42 return result;
43 } else {
44 result.push_back(character);
45 }
46 }
47 return std::nullopt;
48}

References json_string().

Referenced by json_string().

◆ json_u64()

std::optional< std::uint64_t > BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::json_u64 ( const std::string & json,
const std::string & key )

Definition at line 50 of file RootGuardEvent.cpp.

52{
53 const std::string marker = "\"" + key + "\":";
54 const auto begin = json.find(marker);
55 if (begin == std::string::npos)
56 return std::nullopt;
57
58 std::size_t consumed = 0;
59 try {
60 const unsigned long long value =
61 std::stoull(json.substr(begin + marker.size()), &consumed, 10);
62 if (consumed == 0)
63 return std::nullopt;
64 return static_cast<std::uint64_t>(value);
65 } catch (...) {
66 return std::nullopt;
67 }
68}

References json_u64().

Referenced by json_u64().

◆ octal_mode()

std::string BastionGuard::RootGuard::anonymous_namespace{RootGuardEvent.cpp}::octal_mode ( const std::uint32_t mode)

Definition at line 105 of file RootGuardEvent.cpp.

106{
107 std::ostringstream output;
108 output << std::oct << (mode & 07777U);
109 return output.str();
110}

References octal_mode().

Referenced by octal_mode().