diff options
Diffstat (limited to 'src/lib/utils/parsing.h')
-rw-r--r-- | src/lib/utils/parsing.h | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/lib/utils/parsing.h b/src/lib/utils/parsing.h new file mode 100644 index 000000000..b37e3cb62 --- /dev/null +++ b/src/lib/utils/parsing.h @@ -0,0 +1,133 @@ +/* +* Various string utils and parsing functions +* (C) 1999-2007,2013 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PARSER_H__ +#define BOTAN_PARSER_H__ + +#include <botan/types.h> +#include <string> +#include <vector> +#include <set> + +#include <istream> +#include <functional> +#include <map> + +namespace Botan { + +/** +* Parse a SCAN-style algorithm name +* @param scan_name the name +* @return the name components +*/ +BOTAN_DLL std::vector<std::string> +parse_algorithm_name(const std::string& scan_name); + +/** +* Split a string +* @param str the input string +* @param delim the delimitor +* @return string split by delim +*/ +BOTAN_DLL std::vector<std::string> split_on( + const std::string& str, char delim); + +/** +* Erase characters from a string +*/ +BOTAN_DLL std::string erase_chars(const std::string& str, const std::set<char>& chars); + +/** +* Replace a character in a string +* @param str the input string +* @param from_char the character to replace +* @param to_char the character to replace it with +* @return str with all instances of from_char replaced by to_char +*/ +BOTAN_DLL std::string replace_char(const std::string& str, + char from_char, + char to_char); + +/** +* Replace a character in a string +* @param str the input string +* @param from_chars the characters to replace +* @param to_char the character to replace it with +* @return str with all instances of from_chars replaced by to_char +*/ +BOTAN_DLL std::string replace_chars(const std::string& str, + const std::set<char>& from_chars, + char to_char); + +/** +* Join a string +* @param strs strings to join +* @param delim the delimitor +* @return string joined by delim +*/ +BOTAN_DLL std::string string_join(const std::vector<std::string>& strs, + char delim); + +/** +* Parse an ASN.1 OID +* @param oid the OID in string form +* @return OID components +*/ +BOTAN_DLL std::vector<u32bit> parse_asn1_oid(const std::string& oid); + +/** +* Compare two names using the X.509 comparison algorithm +* @param name1 the first name +* @param name2 the second name +* @return true if name1 is the same as name2 by the X.509 comparison rules +*/ +BOTAN_DLL bool x500_name_cmp(const std::string& name1, + const std::string& name2); + +/** +* Convert a string to a number +* @param str the string to convert +* @return number value of the string +*/ +BOTAN_DLL u32bit to_u32bit(const std::string& str); + +/** +* Convert a time specification to a number +* @param timespec the time specification +* @return number of seconds represented by timespec +*/ +BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec); + +/** +* Convert a string representation of an IPv4 address to a number +* @param ip_str the string representation +* @return integer IPv4 address +*/ +BOTAN_DLL u32bit string_to_ipv4(const std::string& ip_str); + +/** +* Convert an IPv4 address to a string +* @param ip_addr the IPv4 address to convert +* @return string representation of the IPv4 address +*/ +BOTAN_DLL std::string ipv4_to_string(u32bit ip_addr); + +void BOTAN_DLL lex_cfg(std::istream& is, + std::function<void (std::string)> cb); + +void BOTAN_DLL lex_cfg_w_headers(std::istream& is, + std::function<void (std::string)> cb, + std::function<void (std::string)> header_cb); + +std::map<std::string, std::map<std::string, std::string>> +BOTAN_DLL +parse_cfg(std::istream& is); + + +} + +#endif |