10#include <botan/internal/parsing.h>
11#include <botan/internal/loadstor.h>
12#include <botan/internal/fmt.h>
13#include <botan/exceptn.h>
28 return static_cast<uint16_t
>(x);
33 const std::string str(str_view);
36 for(
const char chr : str)
38 if(chr <
'0' || chr >
'9')
44 const unsigned long int x = std::stoul(str);
46 if constexpr(
sizeof(
unsigned long int) > 4)
49 if(x > std::numeric_limits<uint32_t>::max())
55 return static_cast<uint32_t
>(x);
63 if(namex.find(
'(') == std::string::npos &&
64 namex.find(
')') == std::string::npos)
66 return {std::string(namex)};
69 std::string
name(namex);
70 std::string substring;
71 std::vector<std::string> elems;
74 elems.push_back(
name.substr(0,
name.find(
'(')));
77 for(
auto i =
name.begin(); i !=
name.end(); ++i)
85 if(level == 1 && i ==
name.end() - 1)
88 elems.push_back(substring.substr(1));
90 elems.push_back(substring);
94 if(level == 0 || (level == 1 && i !=
name.end() - 1))
99 if(c ==
',' && level == 1)
101 if(elems.size() == 1)
102 elems.push_back(substring.substr(1));
104 elems.push_back(substring);
111 if(!substring.empty())
117std::vector<std::string>
split_on(std::string_view str,
char delim)
119 std::vector<std::string> elems;
120 if(str.empty())
return elems;
123 for(
auto i = str.begin(); i != str.end(); ++i)
128 elems.push_back(substr);
139 elems.push_back(substr);
147std::string
string_join(
const std::vector<std::string>& strs,
char delim)
149 std::ostringstream out;
151 for(
size_t i = 0; i != strs.size(); ++i)
166 const auto parts =
split_on(str,
'.');
168 if(parts.size() != 4)
175 for(
auto part = parts.begin(); part != parts.end(); ++part)
184 ip = (ip << 8) | (octet & 0xFF);
199 for(
size_t i = 0; i != 4; ++i)
205 str += std::to_string(bits[i]);
214 for(
size_t i = 0; i != s.size(); ++i)
216 const int cu =
static_cast<unsigned char>(s[i]);
218 s[i] =
static_cast<char>(std::tolower(cu));
228 if(host.empty() || issued.empty())
235 if(std::count(issued.begin(), issued.end(),
char(0)) > 0)
239 const size_t stars = std::count(issued.begin(), issued.end(),
'*');
244 if(std::count(host.begin(), host.end(),
'*') != 0)
248 if(host[host.size() - 1] ==
'.')
252 if(host.find(
"..") != std::string::npos)
269 if(issued.size() > host.size() + 1)
290 size_t dots_seen = 0;
293 for(
size_t i = 0; i != issued.size(); ++i)
295 dots_seen += (issued[i] ==
'.');
310 const size_t advance = (host.size() - issued.size() + 1);
312 if(host_idx + advance > host.size())
316 if(std::count(host.begin() + host_idx,
317 host.begin() + host_idx + advance,
'.') != 0)
324 if(issued[i] != host[host_idx])
uint32_t to_u32bit(std::string_view str_view)
uint32_t string_to_ipv4(std::string_view str)
uint16_t to_uint16(std::string_view str)
std::string fmt(std::string_view format, const T &... args)
std::vector< std::string > split_on(std::string_view str, char delim)
std::string tolower_string(std::string_view in)
std::string string_join(const std::vector< std::string > &strs, char delim)
bool host_wildcard_match(std::string_view issued_, std::string_view host_)
constexpr void store_be(uint16_t in, uint8_t out[2])
std::vector< std::string > parse_algorithm_name(std::string_view namex)
std::string ipv4_to_string(uint32_t ip)