Botan 2.19.5 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>
13#include <vector>
14#include <set>
15
16#include <istream>
17#include <functional>
18#include <map>
19
20 BOTAN_FUTURE_INTERNAL_HEADER(parsing.h)
21
22namespace Botan {
23
24/**
25* Parse a SCAN-style algorithm name
26* @param scan_name the name
27* @return the name components
28*/
29 BOTAN_PUBLIC_API(2,0) std::vector<std::string>
30 parse_algorithm_name(const std::string& scan_name);
31
32/**
33* Split a string
34* @param str the input string
35* @param delim the delimitor
36* @return string split by delim
37*/
38 BOTAN_PUBLIC_API(2,0) std::vector<std::string> split_on(
39 const std::string& str, char delim);
40
41/**
42* Split a string on a character predicate
43* @param str the input string
44* @param pred the predicate
45*
46* This function will likely be removed in a future release
47*/
48 BOTAN_PUBLIC_API(2,0) std::vector<std::string>
49 split_on_pred(const std::string& str,
50 std::function<bool (char)> pred);
51
52/**
53* Erase characters from a string
54*/
55 BOTAN_PUBLIC_API(2,0)
56BOTAN_DEPRECATED("Unused")
57 std::string erase_chars(const std::string& str, const std::set<char>& chars);
58
59/**
60* Replace a character in a string
61* @param str the input string
62* @param from_char the character to replace
63* @param to_char the character to replace it with
64* @return str with all instances of from_char replaced by to_char
65*/
66 BOTAN_PUBLIC_API(2,0)
67BOTAN_DEPRECATED("Unused")
68 std::string replace_char(const std::string& str,
69 char from_char,
70 char to_char);
71
72/**
73* Replace a character in a string
74* @param str the input string
75* @param from_chars the characters to replace
76* @param to_char the character to replace it with
77* @return str with all instances of from_chars replaced by to_char
78*/
79 BOTAN_PUBLIC_API(2,0)
80BOTAN_DEPRECATED("Unused")
81 std::string replace_chars(const std::string& str,
82 const std::set<char>& from_chars,
83 char to_char);
84
85/**
86* Join a string
87* @param strs strings to join
88* @param delim the delimitor
89* @return string joined by delim
90*/
91 BOTAN_PUBLIC_API(2,0)
92 std::string string_join(const std::vector<std::string>& strs,
93 char delim);
94
95/**
96* Parse an ASN.1 OID
97* @param oid the OID in string form
98* @return OID components
99*/
100 BOTAN_PUBLIC_API(2,0) std::vector<uint32_t>
101BOTAN_DEPRECATED("Use OID::from_string(oid).get_components()") parse_asn1_oid(const std::string& oid);
102
103/**
104* Compare two names using the X.509 comparison algorithm
105* @param name1 the first name
106* @param name2 the second name
107* @return true if name1 is the same as name2 by the X.509 comparison rules
108*/
109 BOTAN_PUBLIC_API(2,0)
110 bool x500_name_cmp(const std::string& name1,
111 const std::string& name2);
112
113/**
114* Convert a string to a number
115* @param str the string to convert
116* @return number value of the string
117*/
118 BOTAN_PUBLIC_API(2,0) uint32_t to_u32bit(const std::string& str);
119
120/**
121* Convert a string to a number
122* @param str the string to convert
123* @return number value of the string
124*/
125 BOTAN_PUBLIC_API(2,3) uint16_t to_uint16(const std::string& str);
126
127/**
128* Convert a time specification to a number
129* @param timespec the time specification
130* @return number of seconds represented by timespec
131*/
132 BOTAN_PUBLIC_API(2,0) uint32_t BOTAN_DEPRECATED("Not used anymore")
133 timespec_to_u32bit(const std::string& timespec);
134
135/**
136* Convert a string representation of an IPv4 address to a number
137* @param ip_str the string representation
138* @return integer IPv4 address
139*/
140 BOTAN_PUBLIC_API(2,0) uint32_t string_to_ipv4(const std::string& ip_str);
141
142/**
143* Convert an IPv4 address to a string
144* @param ip_addr the IPv4 address to convert
145* @return string representation of the IPv4 address
146*/
147 BOTAN_PUBLIC_API(2,0) std::string ipv4_to_string(uint32_t ip_addr);
148
149 std::map<std::string, std::string> BOTAN_PUBLIC_API(2,0) read_cfg(std::istream& is);
150
151/**
152* Accepts key value pairs deliminated by commas:
153*
154* "" (returns empty map)
155* "K=V" (returns map {'K': 'V'})
156* "K1=V1,K2=V2"
157* "K1=V1,K2=V2,K3=V3"
158* "K1=V1,K2=V2,K3=a_value\,with\,commas_and_\=equals"
159*
160* Values may be empty, keys must be non-empty and unique. Duplicate
161* keys cause an exception.
162*
163* Within both key and value, comma and equals can be escaped with
164* backslash. Backslash can also be escaped.
165*/
166 std::map<std::string, std::string> BOTAN_PUBLIC_API(2,8) read_kv(const std::string& kv);
167
168 std::string BOTAN_PUBLIC_API(2,0) clean_ws(const std::string& s);
169
170 std::string tolower_string(const std::string& s);
171
172/**
173* Check if the given hostname is a match for the specified wildcard
174*/
175 bool BOTAN_PUBLIC_API(2,0) host_wildcard_match(const std::string& wildcard,
176 const std::string& host);
177
178
179}
180
181#endif
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136
Botan
Definition: alg_id.cpp:13
Botan::read_cfg
std::map< std::string, std::string > read_cfg(std::istream &is)
Definition: read_cfg.cpp:28
Botan::split_on
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:148
Botan::erase_chars
std::string erase_chars(const std::string &str, const std::set< char > &chars)
Definition: parsing.cpp:292
Botan::replace_char
std::string replace_char(const std::string &str, char from_char, char to_char)
Definition: parsing.cpp:316
Botan::string_to_ipv4
uint32_t string_to_ipv4(const std::string &str)
Definition: parsing.cpp:253
Botan::to_uint16
uint16_t to_uint16(const std::string &str)
Definition: parsing.cpp:25
Botan::replace_chars
std::string replace_chars(const std::string &str, const std::set< char > &chars, char to_char)
Definition: parsing.cpp:303
Botan::timespec_to_u32bit
uint32_t timespec_to_u32bit(const std::string &timespec)
Definition: parsing.cpp:64
Botan::clean_ws
std::string clean_ws(const std::string &s)
Definition: read_cfg.cpp:13
Botan::string_join
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition: parsing.cpp:182
Botan::tolower_string
std::string tolower_string(const std::string &in)
Definition: parsing.cpp:327
Botan::parse_asn1_oid
std::vector< uint32_t > parse_asn1_oid(const std::string &oid)
Definition: parsing.cpp:199
Botan::x500_name_cmp
bool x500_name_cmp(const std::string &name1, const std::string &name2)
Definition: parsing.cpp:212
Botan::split_on_pred
std::vector< std::string > split_on_pred(const std::string &str, std::function< bool(char)> pred)
Definition: parsing.cpp:153
Botan::parse_algorithm_name
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:95
Botan::ipv4_to_string
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:278
Botan::to_u32bit
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:35
Botan::read_kv
std::map< std::string, std::string > read_kv(const std::string &kv)
Definition: read_kv.cpp:12
Botan::host_wildcard_match
bool host_wildcard_match(const std::string &issued_, const std::string &host_)
Definition: parsing.cpp:339
std
Definition: bigint.h:1155