aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/charset.cpp2
-rw-r--r--src/utils/datastor/datastor.cpp35
-rw-r--r--src/utils/datastor/datastor.h17
-rw-r--r--src/utils/exceptn.h4
-rw-r--r--src/utils/parsing.cpp79
-rw-r--r--src/utils/parsing.h6
-rw-r--r--src/utils/stl_util.h37
-rw-r--r--src/utils/time.cpp15
-rw-r--r--src/utils/time.h12
-rw-r--r--src/utils/version.cpp6
10 files changed, 45 insertions, 168 deletions
diff --git a/src/utils/charset.cpp b/src/utils/charset.cpp
index 53125cad1..e98cf601e 100644
--- a/src/utils/charset.cpp
+++ b/src/utils/charset.cpp
@@ -119,7 +119,7 @@ std::string transcode(const std::string& str,
return ucs2_to_latin1(str);
throw Invalid_Argument("Unknown transcoding operation from " +
- to_string(from) + " to " + to_string(to));
+ std::to_string(from) + " to " + std::to_string(to));
}
/*
diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp
index 0d808eebd..85b0f22ba 100644
--- a/src/utils/datastor/datastor.cpp
+++ b/src/utils/datastor/datastor.cpp
@@ -14,16 +14,6 @@
namespace Botan {
/*
-* Default Matcher transform operation (identity)
-*/
-std::pair<std::string, std::string>
-Data_Store::Matcher::transform(const std::string& key,
- const std::string& value) const
- {
- return std::make_pair(key, value);
- }
-
-/*
* Data_Store Equality Comparison
*/
bool Data_Store::operator==(const Data_Store& other) const
@@ -42,20 +32,14 @@ bool Data_Store::has_value(const std::string& key) const
/*
* Search based on an arbitrary predicate
*/
-std::multimap<std::string, std::string>
-Data_Store::search_with(const Matcher& matcher) const
+std::multimap<std::string, std::string> Data_Store::search_for(
+ std::function<bool (std::string, std::string)> predicate) const
{
std::multimap<std::string, std::string> out;
- std::multimap<std::string, std::string>::const_iterator i =
- contents.begin();
-
- while(i != contents.end())
- {
- if(matcher(i->first, i->second))
- out.insert(matcher.transform(i->first, i->second));
- ++i;
- }
+ for(auto i = contents.begin(); i != contents.end(); ++i)
+ if(predicate(i->first, i->second))
+ out.insert(std::make_pair(i->first, i->second));
return out;
}
@@ -65,12 +49,9 @@ Data_Store::search_with(const Matcher& matcher) const
*/
std::vector<std::string> Data_Store::get(const std::string& looking_for) const
{
- typedef std::multimap<std::string, std::string>::const_iterator iter;
-
- std::pair<iter, iter> range = contents.equal_range(looking_for);
-
std::vector<std::string> out;
- for(iter i = range.first; i != range.second; ++i)
+ auto range = contents.equal_range(looking_for);
+ for(auto i = range.first; i != range.second; ++i)
out.push_back(i->second);
return out;
}
@@ -143,7 +124,7 @@ void Data_Store::add(const std::string& key, const std::string& val)
*/
void Data_Store::add(const std::string& key, u32bit val)
{
- add(key, to_string(val));
+ add(key, std::to_string(val));
}
/*
diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h
index 8d41b07a8..26a0d418c 100644
--- a/src/utils/datastor/datastor.h
+++ b/src/utils/datastor/datastor.h
@@ -9,6 +9,7 @@
#define BOTAN_DATA_STORE_H__
#include <botan/secmem.h>
+#include <functional>
#include <utility>
#include <string>
#include <vector>
@@ -25,22 +26,10 @@ class BOTAN_DLL Data_Store
/**
* A search function
*/
- class BOTAN_DLL Matcher
- {
- public:
- virtual bool operator()(const std::string&,
- const std::string&) const = 0;
-
- virtual std::pair<std::string, std::string>
- transform(const std::string&, const std::string&) const;
-
- virtual ~Matcher() {}
- };
-
bool operator==(const Data_Store&) const;
- std::multimap<std::string, std::string>
- search_with(const Matcher&) const;
+ std::multimap<std::string, std::string> search_for(
+ std::function<bool (std::string, std::string)> predicate) const;
std::vector<std::string> get(const std::string&) const;
diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h
index ef7b451bf..6dff970b6 100644
--- a/src/utils/exceptn.h
+++ b/src/utils/exceptn.h
@@ -56,7 +56,7 @@ struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
{
Invalid_Key_Length(const std::string& name, u32bit length) :
Invalid_Argument(name + " cannot accept a key of length " +
- to_string(length))
+ std::to_string(length))
{}
};
@@ -78,7 +78,7 @@ struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
{
Invalid_IV_Length(const std::string& mode, u32bit bad_len) :
- Invalid_Argument("IV length " + to_string(bad_len) +
+ Invalid_Argument("IV length " + std::to_string(bad_len) +
" is invalid for " + mode)
{}
};
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index e8259ac52..2c1a02c90 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -13,53 +13,6 @@
namespace Botan {
/*
-* Convert a string into an integer
-*/
-u32bit to_u32bit(const std::string& number)
- {
- u32bit n = 0;
-
- for(std::string::const_iterator j = number.begin(); j != number.end(); ++j)
- {
- const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10;
-
- if(*j == ' ')
- continue;
-
- byte digit = Charset::char2digit(*j);
-
- if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5))
- throw Decoding_Error("to_u32bit: Integer overflow");
- n *= 10;
- n += digit;
- }
- return n;
- }
-
-/*
-* Convert an integer into a string
-*/
-std::string to_string(u64bit n, u32bit min_len)
- {
- std::string lenstr;
- if(n)
- {
- while(n > 0)
- {
- lenstr = Charset::digit2char(n % 10) + lenstr;
- n /= 10;
- }
- }
- else
- lenstr = "0";
-
- while(lenstr.size() < min_len)
- lenstr = "0" + lenstr;
-
- return lenstr;
- }
-
-/*
* Convert a string into a time duration
*/
u32bit timespec_to_u32bit(const std::string& timespec)
@@ -106,15 +59,15 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex)
elems.push_back(name.substr(0, name.find('(')));
name = name.substr(name.find('('));
- for(std::string::const_iterator j = name.begin(); j != name.end(); ++j)
+ for(auto i = name.begin(); i != name.end(); ++i)
{
- char c = *j;
+ char c = *i;
if(c == '(')
++level;
if(c == ')')
{
- if(level == 1 && j == name.end() - 1)
+ if(level == 1 && i == name.end() - 1)
{
if(elems.size() == 1)
elems.push_back(substring.substr(1));
@@ -123,7 +76,7 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex)
return elems;
}
- if(level == 0 || (level == 1 && j != name.end() - 1))
+ if(level == 0 || (level == 1 && i != name.end() - 1))
throw Invalid_Algorithm_Name(namex);
--level;
}
@@ -155,16 +108,16 @@ std::vector<std::string> split_on(const std::string& str, char delim)
if(str == "") return elems;
std::string substr;
- for(std::string::const_iterator j = str.begin(); j != str.end(); ++j)
+ for(auto i = str.begin(); i != str.end(); ++i)
{
- if(*j == delim)
+ if(*i == delim)
{
if(substr != "")
elems.push_back(substr);
substr.clear();
}
else
- substr += *j;
+ substr += *i;
}
if(substr == "")
@@ -182,9 +135,9 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid)
std::string substring;
std::vector<u32bit> oid_elems;
- for(std::string::const_iterator j = oid.begin(); j != oid.end(); ++j)
+ for(auto i = oid.begin(); i != oid.end(); ++i)
{
- char c = *j;
+ char c = *i;
if(c == '.')
{
@@ -212,8 +165,8 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid)
*/
bool x500_name_cmp(const std::string& name1, const std::string& name2)
{
- std::string::const_iterator p1 = name1.begin();
- std::string::const_iterator p2 = name2.begin();
+ auto p1 = name1.begin();
+ auto p2 = name2.begin();
while((p1 != name1.end()) && Charset::is_space(*p1)) ++p1;
while((p2 != name2.end()) && Charset::is_space(*p2)) ++p2;
@@ -258,9 +211,9 @@ u32bit string_to_ipv4(const std::string& str)
u32bit ip = 0;
- for(size_t j = 0; j != parts.size(); j++)
+ for(auto part = parts.begin(); part != parts.end(); ++part)
{
- u32bit octet = to_u32bit(parts[j]);
+ u32bit octet = to_u32bit(*part);
if(octet > 255)
throw Decoding_Error("Invalid IP string " + str);
@@ -278,11 +231,11 @@ std::string ipv4_to_string(u32bit ip)
{
std::string str;
- for(size_t j = 0; j != sizeof(ip); j++)
+ for(size_t i = 0; i != sizeof(ip); i++)
{
- if(j)
+ if(i)
str += ".";
- str += to_string(get_byte(j, ip));
+ str += std::to_string(get_byte(i, ip));
}
return str;
diff --git a/src/utils/parsing.h b/src/utils/parsing.h
index 2c29d5b4d..cb8d61cee 100644
--- a/src/utils/parsing.h
+++ b/src/utils/parsing.h
@@ -23,10 +23,10 @@ BOTAN_DLL std::vector<u32bit> parse_asn1_oid(const std::string&);
BOTAN_DLL bool x500_name_cmp(const std::string&, const std::string&);
/*
-* String/Integer Conversions
+* Convert a string into an integer
*/
-BOTAN_DLL std::string to_string(u64bit, u32bit = 0);
-BOTAN_DLL u32bit to_u32bit(const std::string&);
+inline u32bit to_u32bit(const std::string& number)
+ { return stoul(number); }
BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec);
diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h
index dddb48f12..4cc081733 100644
--- a/src/utils/stl_util.h
+++ b/src/utils/stl_util.h
@@ -13,22 +13,6 @@
namespace Botan {
/*
-* Copy-on-Predicate Algorithm
-*/
-template<typename InputIterator, typename OutputIterator, typename Predicate>
-OutputIterator copy_if(InputIterator current, InputIterator end,
- OutputIterator dest, Predicate copy_p)
- {
- while(current != end)
- {
- if(copy_p(*current))
- *dest++ = *current;
- ++current;
- }
- return dest;
- }
-
-/*
* Searching through a std::map
*/
template<typename K, typename V>
@@ -52,26 +36,7 @@ inline R search_map(const std::map<K, V>& mapping, const K& key,
return found_result;
}
-/**
-* Function adaptor for delete operation
-*/
-template<class T>
-class del_fun : public std::unary_function<T, void>
- {
- public:
- void operator()(T* ptr) { delete ptr; }
- };
-
-/**
-* Delete the second half of a pair of objects
-*/
-template<typename Pair>
-void delete2nd(Pair& pair)
- {
- delete pair.second;
- }
-
-/**
+/*
* Insert a key/value pair into a multimap
*/
template<typename K, typename V>
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 65e808c04..d5b74828b 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -47,7 +47,7 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
return res;
}
-std::tm do_gmtime(time_t time_val)
+std::tm do_gmtime(std::time_t time_val)
{
std::tm tm;
@@ -68,19 +68,12 @@ std::tm do_gmtime(time_t time_val)
}
/*
-* Get the system clock
-*/
-u64bit system_time()
- {
- return static_cast<u64bit>(std::time(0));
- }
-
-/*
* Convert a time_point to a calendar_point
*/
-calendar_point calendar_value(u64bit a_time_t)
+calendar_point calendar_value(
+ const std::chrono::system_clock::time_point& time_point)
{
- std::tm tm = do_gmtime(static_cast<std::time_t>(a_time_t));
+ std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point));
return calendar_point(tm.tm_year + 1900,
tm.tm_mon + 1,
diff --git a/src/utils/time.h b/src/utils/time.h
index 56d15513c..516efba3e 100644
--- a/src/utils/time.h
+++ b/src/utils/time.h
@@ -9,7 +9,7 @@
#define BOTAN_TIME_H__
#include <botan/types.h>
-#include <ctime>
+#include <chrono>
namespace Botan {
@@ -51,16 +51,12 @@ struct BOTAN_DLL calendar_point
year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
};
-/**
+/*
* @param time_point a time point from the system clock
* @return calendar_point object representing this time point
*/
-BOTAN_DLL calendar_point calendar_value(u64bit time_point);
-
-/**
-* @return seconds resolution timestamp, unknown epoch
-*/
-BOTAN_DLL u64bit system_time();
+BOTAN_DLL calendar_point calendar_value(
+ const std::chrono::system_clock::time_point& time_point);
/**
* @return nanoseconds resolution timestamp, unknown epoch
diff --git a/src/utils/version.cpp b/src/utils/version.cpp
index 22827cbe5..ce2083bc0 100644
--- a/src/utils/version.cpp
+++ b/src/utils/version.cpp
@@ -21,9 +21,9 @@ namespace Botan {
*/
std::string version_string()
{
- return to_string(version_major()) + "." +
- to_string(version_minor()) + "." +
- to_string(version_patch());
+ return std::to_string(version_major()) + "." +
+ std::to_string(version_minor()) + "." +
+ std::to_string(version_patch());
}
u32bit version_datestamp() { return BOTAN_VERSION_DATESTAMP; }