Botan 3.0.0
Crypto and TLS for C&
parsing.h
Go to the documentation of this file.
1/*
2* Various string utils and parsing functions
3* (C) 1999-2007,2013 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_PARSING_UTILS_H_
9#define BOTAN_PARSING_UTILS_H_
10
11#include <botan/types.h>
12#include <string_view>
13#include <string>
14#include <vector>
15#include <istream>
16#include <map>
17
18namespace Botan {
19
20/**
21* Parse a SCAN-style algorithm name
22* @param scan_name the name
23* @return the name components
24*/
25std::vector<std::string>
26parse_algorithm_name(std::string_view scan_name);
27
28/**
29* Split a string
30* @param str the input string
31* @param delim the delimitor
32* @return string split by delim
33*/
34BOTAN_TEST_API std::vector<std::string> split_on(
35 std::string_view str, char delim);
36
37/**
38* Join a string
39* @param strs strings to join
40* @param delim the delimitor
41* @return string joined by delim
42*/
43std::string string_join(const std::vector<std::string>& strs,
44 char delim);
45
46/**
47* Convert a decimal string to a number
48* @param str the string to convert
49* @return number value of the string
50*/
51BOTAN_TEST_API uint32_t to_u32bit(std::string_view str);
52
53/**
54* Convert a decimal string to a number
55* @param str the string to convert
56* @return number value of the string
57*/
58uint16_t to_uint16(std::string_view str);
59
60/**
61* Convert a string representation of an IPv4 address to a number
62* @param ip_str the string representation
63* @return integer IPv4 address
64*/
65uint32_t string_to_ipv4(std::string_view ip_str);
66
67/**
68* Convert an IPv4 address to a string
69* @param ip_addr the IPv4 address to convert
70* @return string representation of the IPv4 address
71*/
72std::string ipv4_to_string(uint32_t ip_addr);
73
74std::map<std::string, std::string> read_cfg(std::istream& is);
75
76/**
77* Accepts key value pairs deliminated by commas:
78*
79* "" (returns empty map)
80* "K=V" (returns map {'K': 'V'})
81* "K1=V1,K2=V2"
82* "K1=V1,K2=V2,K3=V3"
83* "K1=V1,K2=V2,K3=a_value\,with\,commas_and_\=equals"
84*
85* Values may be empty, keys must be non-empty and unique. Duplicate
86* keys cause an exception.
87*
88* Within both key and value, comma and equals can be escaped with
89* backslash. Backslash can also be escaped.
90*/
92std::map<std::string, std::string> read_kv(std::string_view kv);
93
94std::string tolower_string(std::string_view s);
95
96/**
97* Check if the given hostname is a match for the specified wildcard
98*/
100bool host_wildcard_match(std::string_view wildcard,
101 std::string_view host);
102
103
104}
105
106#endif
#define BOTAN_TEST_API
Definition: compiler.h:51
Definition: alg_id.cpp:12
uint32_t to_u32bit(std::string_view str_view)
Definition: parsing.cpp:31
uint32_t string_to_ipv4(std::string_view str)
Definition: parsing.cpp:164
uint16_t to_uint16(std::string_view str)
Definition: parsing.cpp:21
std::map< std::string, std::string > read_cfg(std::istream &is)
Definition: read_cfg.cpp:32
BOTAN_TEST_API std::map< std::string, std::string > read_kv(std::string_view kv)
Definition: read_kv.cpp:12
std::vector< std::string > split_on(std::string_view str, char delim)
Definition: parsing.cpp:117
std::string tolower_string(std::string_view in)
Definition: parsing.cpp:211
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition: parsing.cpp:147
bool host_wildcard_match(std::string_view issued_, std::string_view host_)
Definition: parsing.cpp:223
std::vector< std::string > parse_algorithm_name(std::string_view namex)
Definition: parsing.cpp:61
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:193