10#include <botan/internal/parsing.h>
12#include <botan/exceptn.h>
13#include <botan/internal/fmt.h>
14#include <botan/internal/loadstor.h>
29 return static_cast<uint16_t
>(x);
33 const std::string str(str_view);
36 for(
const char chr : str) {
37 if(chr <
'0' || chr >
'9') {
42 const unsigned long int x = std::stoul(str);
44 if constexpr(
sizeof(
unsigned long int) > 4) {
46 if(x > std::numeric_limits<uint32_t>::max()) {
51 return static_cast<uint32_t
>(x);
58 if(namex.find(
'(') == std::string::npos && namex.find(
')') == std::string::npos) {
59 return {std::string(namex)};
62 std::string
name(namex);
63 std::string substring;
64 std::vector<std::string> elems;
67 elems.push_back(
name.substr(0,
name.find(
'(')));
70 for(
auto i =
name.begin(); i !=
name.end(); ++i) {
77 if(level == 1 && i ==
name.end() - 1) {
78 if(elems.size() == 1) {
79 elems.push_back(substring.substr(1));
81 elems.push_back(substring);
86 if(level == 0 || (level == 1 && i !=
name.end() - 1)) {
92 if(c ==
',' && level == 1) {
93 if(elems.size() == 1) {
94 elems.push_back(substring.substr(1));
96 elems.push_back(substring);
104 if(!substring.empty()) {
111std::vector<std::string>
split_on(std::string_view str,
char delim) {
112 std::vector<std::string> elems;
118 for(
auto i = str.begin(); i != str.end(); ++i) {
120 if(!substr.empty()) {
121 elems.push_back(substr);
132 elems.push_back(substr);
140std::string
string_join(
const std::vector<std::string>& strs,
char delim) {
141 std::ostringstream out;
143 for(
size_t i = 0; i != strs.size(); ++i) {
157 const auto parts =
split_on(str,
'.');
159 if(parts.size() != 4) {
165 for(
auto part = parts.begin(); part != parts.end(); ++part) {
172 ip = (ip << 8) | (octet & 0xFF);
186 for(
size_t i = 0; i != 4; ++i) {
190 str += std::to_string(bits[i]);
198 for(
size_t i = 0; i != s.size(); ++i) {
199 const int cu =
static_cast<unsigned char>(s[i]);
200 if(std::isalpha(cu)) {
201 s[i] =
static_cast<char>(std::tolower(cu));
211 if(host.empty() || issued.empty()) {
219 if(std::count(issued.begin(), issued.end(),
char(0)) > 0) {
224 const size_t stars = std::count(issued.begin(), issued.end(),
'*');
230 if(std::count(host.begin(), host.end(),
'*') != 0) {
235 if(host[host.size() - 1] ==
'.') {
240 if(host.find(
"..") != std::string::npos) {
257 if(issued.size() > host.size() + 1) {
276 size_t dots_seen = 0;
279 for(
size_t i = 0; i != issued.size(); ++i) {
280 dots_seen += (issued[i] ==
'.');
282 if(issued[i] ==
'*') {
293 const size_t advance = (host.size() - issued.size() + 1);
295 if(host_idx + advance > host.size()) {
300 if(std::count(host.begin() + host_idx, host.begin() + host_idx + advance,
'.') != 0) {
306 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)