diff options
author | lloyd <[email protected]> | 2010-10-13 03:25:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 03:25:16 +0000 |
commit | ba142ed2eaa21445d49cbbc8ae3b3d4dc625b9d7 (patch) | |
tree | be1a9fa07d0ea26fd7713bb52205f7a3bcc3e907 /src/utils | |
parent | 406d4f8556d41083bfa551e7a777b0cb02925b6c (diff) | |
parent | 5913bf42b4c32e43d0db11bf9299130f3b0b62a4 (diff) |
propagate from branch 'net.randombit.botan' (head 2898d79f992f27a328a3e41d34b46eb1052da0de)
to branch 'net.randombit.botan.c++0x' (head 6cba76268fd69a73195760c021b7f881b8a6552c)
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/charset.cpp | 2 | ||||
-rw-r--r-- | src/utils/datastor/datastor.cpp | 41 | ||||
-rw-r--r-- | src/utils/datastor/datastor.h | 17 | ||||
-rw-r--r-- | src/utils/exceptn.h | 4 | ||||
-rw-r--r-- | src/utils/info.txt | 2 | ||||
-rw-r--r-- | src/utils/parsing.cpp | 63 | ||||
-rw-r--r-- | src/utils/stl_util.h | 37 | ||||
-rw-r--r-- | src/utils/time.cpp | 15 | ||||
-rw-r--r-- | src/utils/time.h | 12 | ||||
-rw-r--r-- | src/utils/ui.cpp | 36 | ||||
-rw-r--r-- | src/utils/ui.h | 37 | ||||
-rw-r--r-- | src/utils/version.cpp | 6 |
12 files changed, 34 insertions, 238 deletions
diff --git a/src/utils/charset.cpp b/src/utils/charset.cpp index 8e20e6492..7ee637f80 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 49e7b2dda..363136c69 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,26 +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)) - { - std::pair<std::string, std::string> p( - matcher.transform(i->first, i->second)); - - multimap_insert(out, p.first, p.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; } @@ -71,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; } @@ -144,7 +119,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 1177a4e7d..8c74420df 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, size_t 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, size_t 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/info.txt b/src/utils/info.txt index fcf16bd5a..4350ed410 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -9,7 +9,6 @@ cpuid.cpp mlock.cpp parsing.cpp time.cpp -ui.cpp version.cpp </source> @@ -34,7 +33,6 @@ parsing.h rotate.h time.h types.h -ui.h version.h get_byte.h </header:public> diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index f46e2687d..50696bbbf 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 i = number.begin(); i != number.end(); ++i) - { - const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - - if(*i == ' ') - continue; - - byte digit = Charset::char2digit(*i); - - 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, size_t 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,7 +59,7 @@ 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 i = name.begin(); i != name.end(); ++i) + for(auto i = name.begin(); i != name.end(); ++i) { char c = *i; @@ -155,7 +108,7 @@ std::vector<std::string> split_on(const std::string& str, char delim) if(str == "") return elems; std::string substr; - for(std::string::const_iterator i = str.begin(); i != str.end(); ++i) + for(auto i = str.begin(); i != str.end(); ++i) { if(*i == delim) { @@ -182,7 +135,7 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid) std::string substring; std::vector<u32bit> oid_elems; - for(std::string::const_iterator i = oid.begin(); i != oid.end(); ++i) + for(auto i = oid.begin(); i != oid.end(); ++i) { char c = *i; @@ -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 i = 0; i != parts.size(); i++) + for(auto part = parts.begin(); part != parts.end(); ++part) { - u32bit octet = to_u32bit(parts[i]); + u32bit octet = to_u32bit(*part); if(octet > 255) throw Decoding_Error("Invalid IP string " + str); @@ -282,7 +235,7 @@ std::string ipv4_to_string(u32bit ip) { if(i) str += "."; - str += to_string(get_byte(i, ip)); + str += std::to_string(get_byte(i, ip)); } return str; diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h index 5a17f46a9..0d672fc50 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/ui.cpp b/src/utils/ui.cpp deleted file mode 100644 index e6c3430ff..000000000 --- a/src/utils/ui.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -* User Interface -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/ui.h> - -namespace Botan { - -/* -* Get a passphrase from the user -*/ -std::string User_Interface::get_passphrase(const std::string&, - const std::string&, - UI_Result& action) const - { - action = OK; - - if(!first_try) - action = CANCEL_ACTION; - - return preset_passphrase; - } - -/* -* User_Interface Constructor -*/ -User_Interface::User_Interface(const std::string& preset) : - preset_passphrase(preset) - { - first_try = true; - } - -} diff --git a/src/utils/ui.h b/src/utils/ui.h deleted file mode 100644 index f69bb2c6d..000000000 --- a/src/utils/ui.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* User Interface -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_UI_H__ -#define BOTAN_UI_H__ - -#include <botan/build.h> -#include <string> - -namespace Botan { - -/** -* User Interface -* Only really used for callbacks for PKCS #8 decryption -*/ -class BOTAN_DLL User_Interface - { - public: - enum UI_Result { OK, CANCEL_ACTION }; - - virtual std::string get_passphrase(const std::string&, - const std::string&, - UI_Result&) const; - User_Interface(const std::string& = ""); - virtual ~User_Interface() {} - protected: - std::string preset_passphrase; - mutable bool first_try; - }; - -} - -#endif 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; } |