10#include <botan/internal/parsing.h>
11#include <botan/internal/loadstor.h>
12#include <botan/exceptn.h>
26 return static_cast<uint16_t
>(x);
32 for(
const char chr : str)
34 if(chr < '0' || chr >
'9')
36 std::string chrAsString(1, chr);
41 const unsigned long int x = std::stoul(str);
43 if constexpr(
sizeof(
unsigned long int) > 4)
46 if(x > std::numeric_limits<uint32_t>::max())
52 return static_cast<uint32_t
>(x);
60 if(namex.find(
'(') == std::string::npos &&
61 namex.find(
')') == std::string::npos)
62 return std::vector<std::string>(1, namex);
64 std::string
name = namex, substring;
65 std::vector<std::string> elems;
68 elems.push_back(
name.substr(0,
name.find(
'(')));
71 for(
auto i =
name.begin(); i !=
name.end(); ++i)
79 if(level == 1 && i ==
name.end() - 1)
82 elems.push_back(substring.substr(1));
84 elems.push_back(substring);
88 if(level == 0 || (level == 1 && i !=
name.end() - 1))
93 if(c ==
',' && level == 1)
96 elems.push_back(substring.substr(1));
98 elems.push_back(substring);
105 if(!substring.empty())
111std::vector<std::string>
split_on(
const std::string& str,
char delim)
113 std::vector<std::string> elems;
114 if(str.empty())
return elems;
117 for(
auto i = str.begin(); i != str.end(); ++i)
122 elems.push_back(substr);
131 elems.push_back(substr);
139std::string
string_join(
const std::vector<std::string>& strs,
char delim)
141 std::string out =
"";
143 for(
size_t i = 0; i != strs.size(); ++i)
158 std::vector<std::string> parts =
split_on(str,
'.');
160 if(parts.size() != 4)
165 for(
auto part = parts.begin(); part != parts.end(); ++part)
172 ip = (ip << 8) | (octet & 0xFF);
187 for(
size_t i = 0; i != 4; ++i)
202 for(
size_t i = 0; i != s.size(); ++i)
204 const int cu =
static_cast<unsigned char>(s[i]);
206 s[i] =
static_cast<char>(std::tolower(cu));
216 if(host.empty() || issued.empty())
223 if(std::count(issued.begin(), issued.end(),
char(0)) > 0)
227 const size_t stars = std::count(issued.begin(), issued.end(),
'*');
232 if(std::count(host.begin(), host.end(),
'*') != 0)
236 if(host[host.size() - 1] ==
'.')
240 if(host.find(
"..") != std::string::npos)
257 if(issued.size() > host.size() + 1)
278 size_t dots_seen = 0;
281 for(
size_t i = 0; i != issued.size(); ++i)
283 dots_seen += (issued[i] ==
'.');
298 const size_t advance = (host.size() - issued.size() + 1);
300 if(host_idx + advance > host.size())
304 if(std::count(host.begin() + host_idx,
305 host.begin() + host_idx + advance,
'.') != 0)
312 if(issued[i] != host[host_idx])
std::string to_string(const BER_Object &obj)
uint32_t string_to_ipv4(const std::string &str)
uint16_t to_uint16(const std::string &str)
bool host_wildcard_match(const std::string &issued_, const std::string &host_)
std::string string_join(const std::vector< std::string > &strs, char delim)
std::vector< std::string > split_on(const std::string &str, char delim)
constexpr void store_be(uint16_t in, uint8_t out[2])
std::string tolower_string(const std::string &in)
std::vector< std::string > parse_algorithm_name(const std::string &namex)
std::string ipv4_to_string(uint32_t ip)
uint32_t to_u32bit(const std::string &str)