aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/algo_factory/algo_cache.h46
-rw-r--r--src/algo_factory/algo_factory.cpp14
-rw-r--r--src/algo_factory/algo_factory.h4
-rw-r--r--src/algo_factory/info.txt1
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.h1
-rw-r--r--src/alloc/mem_pool/info.txt4
-rw-r--r--src/alloc/mem_pool/mem_pool.cpp15
-rw-r--r--src/alloc/mem_pool/mem_pool.h6
-rw-r--r--src/alloc/system_alloc/defalloc.h2
-rw-r--r--src/asn1/asn1_alt.cpp27
-rw-r--r--src/asn1/asn1_dn.cpp70
-rw-r--r--src/asn1/asn1_int.cpp4
-rw-r--r--src/asn1/asn1_obj.h3
-rw-r--r--src/asn1/asn1_oid.cpp2
-rw-r--r--src/asn1/asn1_str.cpp2
-rw-r--r--src/asn1/asn1_tm.cpp53
-rw-r--r--src/asn1/ber_dec.h4
-rw-r--r--src/asn1/der_enc.cpp2
-rw-r--r--src/benchmark/benchmark.cpp53
-rw-r--r--src/benchmark/benchmark.h3
-rw-r--r--src/block/lion/lion.cpp2
-rw-r--r--src/block/misty1/misty1.cpp2
-rw-r--r--src/block/rc5/rc5.cpp2
-rw-r--r--src/block/safer/safer_sk.cpp2
-rw-r--r--src/build-data/cc/compaq.txt26
-rw-r--r--src/build-data/cc/gcc.txt14
-rw-r--r--src/build-data/cc/icc.txt4
-rw-r--r--src/build-data/cc/kai.txt27
-rw-r--r--src/build-data/cc/mipspro.txt39
-rw-r--r--src/build-data/cc/sgipro64.txt27
-rw-r--r--src/build-data/os/windows.txt5
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp112
-rw-r--r--src/cert/cvc/cvc_gen_cert.h6
-rw-r--r--src/cert/cvc/cvc_self.cpp23
-rw-r--r--src/cert/cvc/eac_asn_obj.h62
-rw-r--r--src/cert/cvc/info.txt1
-rw-r--r--src/cert/x509/crl_ent.cpp3
-rw-r--r--src/cert/x509/pkcs10.cpp2
-rw-r--r--src/cert/x509/x509_ca.cpp14
-rw-r--r--src/cert/x509/x509_ca.h6
-rw-r--r--src/cert/x509/x509_crl.cpp2
-rw-r--r--src/cert/x509/x509cert.cpp61
-rw-r--r--src/cert/x509/x509find.cpp95
-rw-r--r--src/cert/x509/x509find.h58
-rw-r--r--src/cert/x509/x509opt.cpp8
-rw-r--r--src/cert/x509/x509self.cpp4
-rw-r--r--src/cert/x509/x509stor.cpp40
-rw-r--r--src/cert/x509/x509stor.h36
-rw-r--r--src/cms/cms_dalg.cpp5
-rw-r--r--src/engine/openssl/arc4_openssl.cpp2
-rw-r--r--src/entropy/hres_timer/hres_timer.cpp6
-rw-r--r--src/filters/data_snk.h6
-rw-r--r--src/filters/data_src.h5
-rw-r--r--src/filters/filter.h11
-rw-r--r--src/filters/hex/hex.cpp2
-rw-r--r--src/filters/modes/cfb/cfb.cpp8
-rw-r--r--src/filters/modes/eax/eax.cpp2
-rw-r--r--src/filters/pipe.cpp7
-rw-r--r--src/filters/pipe.h14
-rw-r--r--src/hash/par_hash/par_hash.cpp41
-rw-r--r--src/hash/skein/skein_512.cpp2
-rw-r--r--src/hash/tiger/tiger.cpp6
-rw-r--r--src/libstate/info.txt2
-rw-r--r--src/libstate/init.cpp35
-rw-r--r--src/libstate/libstate.cpp103
-rw-r--r--src/libstate/libstate.h32
-rw-r--r--src/math/bigint/bigint.cpp21
-rw-r--r--src/math/bigint/bigint.h19
-rw-r--r--src/math/numbertheory/dsa_gen.cpp8
-rw-r--r--src/math/numbertheory/make_prm.cpp4
-rw-r--r--src/math/numbertheory/numthry.cpp2
-rw-r--r--src/mutex/info.txt5
-rw-r--r--src/mutex/mutex.h56
-rw-r--r--src/mutex/noop_mutex/info.txt9
-rw-r--r--src/mutex/noop_mutex/mux_noop.cpp50
-rw-r--r--src/mutex/noop_mutex/mux_noop.h26
-rw-r--r--src/mutex/pthreads/info.txt29
-rw-r--r--src/mutex/pthreads/mux_pthr.cpp58
-rw-r--r--src/mutex/pthreads/mux_pthr.h26
-rw-r--r--src/mutex/qt_mutex/info.txt17
-rw-r--r--src/mutex/qt_mutex/mux_qt.cpp35
-rw-r--r--src/mutex/qt_mutex/mux_qt.h27
-rw-r--r--src/mutex/win32_crit_section/info.txt15
-rw-r--r--src/mutex/win32_crit_section/mux_win32.cpp34
-rw-r--r--src/mutex/win32_crit_section/mux_win32.h26
-rw-r--r--src/pubkey/dl_group/dl_group.cpp8
-rw-r--r--src/pubkey/pkcs8.cpp4
-rw-r--r--src/pubkey/pubkey.cpp4
-rw-r--r--src/pubkey/rsa/rsa.cpp2
-rw-r--r--src/pubkey/rw/rw.cpp2
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp5
-rw-r--r--src/rng/randpool/randpool.cpp6
-rw-r--r--src/s2k/s2k.h6
-rw-r--r--src/selftest/selftest.cpp3
-rw-r--r--src/ssl/rec_wri.cpp2
-rw-r--r--src/ssl/tls_suites.cpp2
-rw-r--r--src/stream/arc4/arc4.cpp2
-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.h35
-rw-r--r--src/utils/time.cpp15
-rw-r--r--src/utils/time.h12
-rw-r--r--src/utils/version.cpp6
107 files changed, 607 insertions, 1405 deletions
diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h
index c9fbf5b26..bafea45e9 100644
--- a/src/algo_factory/algo_cache.h
+++ b/src/algo_factory/algo_cache.h
@@ -8,8 +8,9 @@
#ifndef BOTAN_ALGORITHM_CACHE_TEMPLATE_H__
#define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__
-#include <botan/internal/mutex.h>
+#include <botan/types.h>
#include <botan/internal/stl_util.h>
+#include <mutex>
#include <string>
#include <vector>
#include <map>
@@ -50,17 +51,12 @@ class Algorithm_Cache
*/
std::vector<std::string> providers_of(const std::string& algo_name);
- Algorithm_Cache(Mutex* m) : mutex(m) {}
~Algorithm_Cache();
private:
- typedef typename std::map<std::string, std::map<std::string, T*> >::iterator
- algorithms_iterator;
+ typename std::map<std::string, std::map<std::string, T*> >::const_iterator
+ find_algorithm(const std::string& algo_spec);
- typedef typename std::map<std::string, T*>::iterator provider_iterator;
-
- algorithms_iterator find_algorithm(const std::string& algo_spec);
-
- Mutex* mutex;
+ std::mutex mutex;
std::map<std::string, std::string> aliases;
std::map<std::string, std::string> pref_providers;
std::map<std::string, std::map<std::string, T*> > algorithms;
@@ -71,16 +67,15 @@ class Algorithm_Cache
* Assumes object lock is held
*/
template<typename T>
-typename Algorithm_Cache<T>::algorithms_iterator
+typename std::map<std::string, std::map<std::string, T*> >::const_iterator
Algorithm_Cache<T>::find_algorithm(const std::string& algo_spec)
{
- algorithms_iterator algo = algorithms.find(algo_spec);
+ auto algo = algorithms.find(algo_spec);
// Not found? Check if a known alias
if(algo == algorithms.end())
{
- std::map<std::string, std::string>::const_iterator alias =
- aliases.find(algo_spec);
+ auto alias = aliases.find(algo_spec);
if(alias != aliases.end())
algo = algorithms.find(alias->second);
@@ -96,16 +91,16 @@ template<typename T>
const T* Algorithm_Cache<T>::get(const std::string& algo_spec,
const std::string& requested_provider)
{
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
- algorithms_iterator algo = find_algorithm(algo_spec);
+ auto algo = find_algorithm(algo_spec);
if(algo == algorithms.end()) // algo not found at all (no providers)
return 0;
// If a provider is requested specifically, return it or fail entirely
if(requested_provider != "")
{
- provider_iterator prov = algo->second.find(requested_provider);
+ auto prov = algo->second.find(requested_provider);
if(prov != algo->second.end())
return prov->second;
return 0;
@@ -117,7 +112,7 @@ const T* Algorithm_Cache<T>::get(const std::string& algo_spec,
const std::string pref_provider = search_map(pref_providers, algo_spec);
- for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i)
+ for(auto i = algo->second.begin(); i != algo->second.end(); ++i)
{
const std::string prov_name = i->first;
const u32bit prov_weight = static_provider_weight(prov_name);
@@ -148,7 +143,7 @@ void Algorithm_Cache<T>::add(T* algo,
if(!algo)
return;
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
delete algorithms[algo->name()][provider];
algorithms[algo->name()][provider] = algo;
@@ -166,15 +161,14 @@ void Algorithm_Cache<T>::add(T* algo,
template<typename T> std::vector<std::string>
Algorithm_Cache<T>::providers_of(const std::string& algo_name)
{
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
std::vector<std::string> providers;
- algorithms_iterator algo = find_algorithm(algo_name);
-
+ auto algo = find_algorithm(algo_name);
if(algo != algorithms.end())
{
- provider_iterator provider = algo->second.begin();
+ auto provider = algo->second.begin();
while(provider != algo->second.end())
{
@@ -193,7 +187,7 @@ template<typename T>
void Algorithm_Cache<T>::set_preferred_provider(const std::string& algo_spec,
const std::string& provider)
{
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
pref_providers[algo_spec] = provider;
}
@@ -204,11 +198,11 @@ void Algorithm_Cache<T>::set_preferred_provider(const std::string& algo_spec,
template<typename T>
Algorithm_Cache<T>::~Algorithm_Cache()
{
- algorithms_iterator algo = algorithms.begin();
+ auto algo = algorithms.begin();
while(algo != algorithms.end())
{
- provider_iterator provider = algo->second.begin();
+ auto provider = algo->second.begin();
while(provider != algo->second.end())
{
@@ -218,8 +212,6 @@ Algorithm_Cache<T>::~Algorithm_Cache()
++algo;
}
-
- delete mutex;
}
}
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp
index ad8b1215f..05de330c3 100644
--- a/src/algo_factory/algo_factory.cpp
+++ b/src/algo_factory/algo_factory.cpp
@@ -83,15 +83,14 @@ const T* factory_prototype(const std::string& algo_spec,
/**
* Setup caches
*/
-Algorithm_Factory::Algorithm_Factory(const std::vector<Engine*>& engines_in,
- Mutex_Factory& mf)
+Algorithm_Factory::Algorithm_Factory(const std::vector<Engine*>& engines_in)
{
engines = engines_in;
- block_cipher_cache = new Algorithm_Cache<BlockCipher>(mf.make());
- stream_cipher_cache = new Algorithm_Cache<StreamCipher>(mf.make());
- hash_cache = new Algorithm_Cache<HashFunction>(mf.make());
- mac_cache = new Algorithm_Cache<MessageAuthenticationCode>(mf.make());
+ block_cipher_cache = new Algorithm_Cache<BlockCipher>();
+ stream_cipher_cache = new Algorithm_Cache<StreamCipher>();
+ hash_cache = new Algorithm_Cache<HashFunction>();
+ mac_cache = new Algorithm_Cache<MessageAuthenticationCode>();
}
/**
@@ -99,7 +98,8 @@ Algorithm_Factory::Algorithm_Factory(const std::vector<Engine*>& engines_in,
*/
Algorithm_Factory::~Algorithm_Factory()
{
- std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
+ for(auto i = engines.begin(); i != engines.end(); ++i)
+ delete *i;
delete block_cipher_cache;
delete stream_cipher_cache;
diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h
index 3b479c2d7..8c1c47060 100644
--- a/src/algo_factory/algo_factory.h
+++ b/src/algo_factory/algo_factory.h
@@ -25,7 +25,6 @@ class MessageAuthenticationCode;
template<typename T> class Algorithm_Cache;
class Engine;
-class Mutex_Factory;
/**
* Algorithm Factory
@@ -38,8 +37,7 @@ class BOTAN_DLL Algorithm_Factory
* @param engines_in the list of engines to use
* @param mf a mutex factory
*/
- Algorithm_Factory(const std::vector<Engine*>& engines_in,
- Mutex_Factory& mf);
+ Algorithm_Factory(const std::vector<Engine*>& engines_in);
/**
* Destructor
diff --git a/src/algo_factory/info.txt b/src/algo_factory/info.txt
index eae4b3934..236fdda0e 100644
--- a/src/algo_factory/info.txt
+++ b/src/algo_factory/info.txt
@@ -20,6 +20,5 @@ block
engine
hash
mac
-mutex
stream
</requires>
diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h
index da3dda31d..14caf5db1 100644
--- a/src/alloc/alloc_mmap/mmap_mem.h
+++ b/src/alloc/alloc_mmap/mmap_mem.h
@@ -18,7 +18,6 @@ namespace Botan {
class MemoryMapping_Allocator : public Pooling_Allocator
{
public:
- MemoryMapping_Allocator(Mutex* m) : Pooling_Allocator(m) {}
std::string type() const { return "mmap"; }
private:
void* alloc_block(u32bit);
diff --git a/src/alloc/mem_pool/info.txt b/src/alloc/mem_pool/info.txt
index 5097c325f..f87ea4c4c 100644
--- a/src/alloc/mem_pool/info.txt
+++ b/src/alloc/mem_pool/info.txt
@@ -6,7 +6,3 @@ mem_pool.cpp
<header:internal>
mem_pool.h
</header:internal>
-
-<requires>
-mutex
-</requires>
diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp
index 4180d2602..ba82fefdc 100644
--- a/src/alloc/mem_pool/mem_pool.cpp
+++ b/src/alloc/mem_pool/mem_pool.cpp
@@ -96,7 +96,7 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks)
/*
* Pooling_Allocator Constructor
*/
-Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m)
+Pooling_Allocator::Pooling_Allocator()
{
last_used = blocks.begin();
}
@@ -106,7 +106,6 @@ Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m)
*/
Pooling_Allocator::~Pooling_Allocator()
{
- delete mutex;
if(blocks.size())
throw Invalid_State("Pooling_Allocator: Never released memory");
}
@@ -116,7 +115,7 @@ Pooling_Allocator::~Pooling_Allocator()
*/
void Pooling_Allocator::destroy()
{
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
blocks.clear();
@@ -133,7 +132,7 @@ void* Pooling_Allocator::allocate(u32bit n)
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
const u32bit BLOCK_SIZE = Memory_Block::block_size();
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
if(n <= BITMAP_SIZE * BLOCK_SIZE)
{
@@ -170,7 +169,7 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n)
if(ptr == 0 && n == 0)
return;
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
if(n > BITMAP_SIZE * BLOCK_SIZE)
dealloc_block(ptr, n);
@@ -178,8 +177,8 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n)
{
const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE;
- std::vector<Memory_Block>::iterator i =
- std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
+ auto i = std::lower_bound(blocks.begin(), blocks.end(),
+ Memory_Block(ptr));
if(i == blocks.end() || !i->contains(ptr, block_no))
throw Invalid_State("Pointer released to the wrong allocator");
@@ -196,7 +195,7 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n)
if(blocks.empty())
return 0;
- std::vector<Memory_Block>::iterator i = last_used;
+ auto i = last_used;
do
{
diff --git a/src/alloc/mem_pool/mem_pool.h b/src/alloc/mem_pool/mem_pool.h
index 9735a547d..f0a564965 100644
--- a/src/alloc/mem_pool/mem_pool.h
+++ b/src/alloc/mem_pool/mem_pool.h
@@ -10,7 +10,7 @@
#include <botan/allocate.h>
#include <botan/exceptn.h>
-#include <botan/internal/mutex.h>
+#include <mutex>
#include <utility>
#include <vector>
@@ -27,7 +27,7 @@ class Pooling_Allocator : public Allocator
void destroy();
- Pooling_Allocator(Mutex*);
+ Pooling_Allocator();
~Pooling_Allocator();
private:
void get_more_core(u32bit);
@@ -66,7 +66,7 @@ class Pooling_Allocator : public Allocator
std::vector<Memory_Block> blocks;
std::vector<Memory_Block>::iterator last_used;
std::vector<std::pair<void*, u32bit> > allocated;
- Mutex* mutex;
+ std::mutex mutex;
};
}
diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h
index 0c8804223..436549540 100644
--- a/src/alloc/system_alloc/defalloc.h
+++ b/src/alloc/system_alloc/defalloc.h
@@ -30,8 +30,6 @@ class Malloc_Allocator : public Allocator
class Locking_Allocator : public Pooling_Allocator
{
public:
- Locking_Allocator(Mutex* m) : Pooling_Allocator(m) {}
-
std::string type() const { return "locking"; }
private:
void* alloc_block(u32bit);
diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp
index 9fe159356..0539215ad 100644
--- a/src/asn1/asn1_alt.cpp
+++ b/src/asn1/asn1_alt.cpp
@@ -40,9 +40,8 @@ void AlternativeName::add_attribute(const std::string& type,
if(type == "" || str == "")
return;
- typedef std::multimap<std::string, std::string>::iterator iter;
- std::pair<iter, iter> range = alt_info.equal_range(type);
- for(iter j = range.first; j != range.second; ++j)
+ auto range = alt_info.equal_range(type);
+ for(auto j = range.first; j != range.second; ++j)
if(j->second == str)
return;
@@ -83,13 +82,11 @@ std::multimap<std::string, std::string> AlternativeName::contents() const
{
std::multimap<std::string, std::string> names;
- typedef std::multimap<std::string, std::string>::const_iterator rdn_iter;
- for(rdn_iter j = alt_info.begin(); j != alt_info.end(); ++j)
- multimap_insert(names, j->first, j->second);
+ for(auto i = alt_info.begin(); i != alt_info.end(); ++i)
+ multimap_insert(names, i->first, i->second);
- typedef std::multimap<OID, ASN1_String>::const_iterator on_iter;
- for(on_iter j = othernames.begin(); j != othernames.end(); ++j)
- multimap_insert(names, OIDS::lookup(j->first), j->second.value());
+ for(auto i = othernames.begin(); i != othernames.end(); ++i)
+ multimap_insert(names, OIDS::lookup(i->first), i->second.value());
return names;
}
@@ -111,19 +108,18 @@ void encode_entries(DER_Encoder& encoder,
const std::multimap<std::string, std::string>& attr,
const std::string& type, ASN1_Tag tagging)
{
- typedef std::multimap<std::string, std::string>::const_iterator iter;
+ auto range = attr.equal_range(type);
- std::pair<iter, iter> range = attr.equal_range(type);
- for(iter j = range.first; j != range.second; ++j)
+ for(auto i = range.first; i != range.second; ++i)
{
if(type == "RFC822" || type == "DNS" || type == "URI")
{
- ASN1_String asn1_string(j->second, IA5_STRING);
+ ASN1_String asn1_string(i->second, IA5_STRING);
encoder.add_object(tagging, CONTEXT_SPECIFIC, asn1_string.iso_8859());
}
else if(type == "IP")
{
- u32bit ip = string_to_ipv4(j->second);
+ u32bit ip = string_to_ipv4(i->second);
byte ip_buf[4] = { 0 };
store_be(ip, ip_buf);
encoder.add_object(tagging, CONTEXT_SPECIFIC, ip_buf, 4);
@@ -145,8 +141,7 @@ void AlternativeName::encode_into(DER_Encoder& der) const
encode_entries(der, alt_info, "URI", ASN1_Tag(6));
encode_entries(der, alt_info, "IP", ASN1_Tag(7));
- std::multimap<OID, ASN1_String>::const_iterator i;
- for(i = othernames.begin(); i != othernames.end(); ++i)
+ for(auto i = othernames.begin(); i != othernames.end(); ++i)
{
der.start_explicit(0)
.encode(i->first)
diff --git a/src/asn1/asn1_dn.cpp b/src/asn1/asn1_dn.cpp
index 6b08fa1ff..e474458b3 100644
--- a/src/asn1/asn1_dn.cpp
+++ b/src/asn1/asn1_dn.cpp
@@ -26,9 +26,8 @@ X509_DN::X509_DN()
*/
X509_DN::X509_DN(const std::multimap<OID, std::string>& args)
{
- std::multimap<OID, std::string>::const_iterator j;
- for(j = args.begin(); j != args.end(); ++j)
- add_attribute(j->first, j->second);
+ for(auto i = args.begin(); i != args.end(); ++i)
+ add_attribute(i->first, i->second);
}
/*
@@ -36,9 +35,8 @@ X509_DN::X509_DN(const std::multimap<OID, std::string>& args)
*/
X509_DN::X509_DN(const std::multimap<std::string, std::string>& args)
{
- std::multimap<std::string, std::string>::const_iterator j;
- for(j = args.begin(); j != args.end(); ++j)
- add_attribute(OIDS::lookup(j->first), j->second);
+ for(auto i = args.begin(); i != args.end(); ++i)
+ add_attribute(OIDS::lookup(i->first), i->second);
}
/*
@@ -59,11 +57,9 @@ void X509_DN::add_attribute(const OID& oid, const std::string& str)
if(str == "")
return;
- typedef std::multimap<OID, ASN1_String>::iterator rdn_iter;
-
- std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
- for(rdn_iter j = range.first; j != range.second; ++j)
- if(j->second.value() == str)
+ auto range = dn_info.equal_range(oid);
+ for(auto i = range.first; i != range.second; ++i)
+ if(i->second.value() == str)
return;
multimap_insert(dn_info, oid, ASN1_String(str));
@@ -75,11 +71,9 @@ void X509_DN::add_attribute(const OID& oid, const std::string& str)
*/
std::multimap<OID, std::string> X509_DN::get_attributes() const
{
- typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
-
std::multimap<OID, std::string> retval;
- for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
- multimap_insert(retval, j->first, j->second.value());
+ for(auto i = dn_info.begin(); i != dn_info.end(); ++i)
+ multimap_insert(retval, i->first, i->second.value());
return retval;
}
@@ -88,11 +82,9 @@ std::multimap<OID, std::string> X509_DN::get_attributes() const
*/
std::multimap<std::string, std::string> X509_DN::contents() const
{
- typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
-
std::multimap<std::string, std::string> retval;
- for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
- multimap_insert(retval, OIDS::lookup(j->first), j->second.value());
+ for(auto i = dn_info.begin(); i != dn_info.end(); ++i)
+ multimap_insert(retval, OIDS::lookup(i->first), i->second.value());
return retval;
}
@@ -101,14 +93,13 @@ std::multimap<std::string, std::string> X509_DN::contents() const
*/
std::vector<std::string> X509_DN::get_attribute(const std::string& attr) const
{
- typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
-
const OID oid = OIDS::lookup(deref_info_field(attr));
- std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
+
+ auto range = dn_info.equal_range(oid);
std::vector<std::string> values;
- for(rdn_iter j = range.first; j != range.second; ++j)
- values.push_back(j->second.value());
+ for(auto i = range.first; i != range.second; ++i)
+ values.push_back(i->second.value());
return values;
}
@@ -171,15 +162,13 @@ std::string X509_DN::deref_info_field(const std::string& info)
*/
bool operator==(const X509_DN& dn1, const X509_DN& dn2)
{
- typedef std::multimap<OID, std::string>::const_iterator rdn_iter;
-
- std::multimap<OID, std::string> attr1 = dn1.get_attributes();
- std::multimap<OID, std::string> attr2 = dn2.get_attributes();
+ auto attr1 = dn1.get_attributes();
+ auto attr2 = dn2.get_attributes();
if(attr1.size() != attr2.size()) return false;
- rdn_iter p1 = attr1.begin();
- rdn_iter p2 = attr2.begin();
+ auto p1 = attr1.begin();
+ auto p2 = attr2.begin();
while(true)
{
@@ -209,18 +198,15 @@ bool operator!=(const X509_DN& dn1, const X509_DN& dn2)
*/
bool operator<(const X509_DN& dn1, const X509_DN& dn2)
{
- typedef std::multimap<OID, std::string>::const_iterator rdn_iter;
-
- std::multimap<OID, std::string> attr1 = dn1.get_attributes();
- std::multimap<OID, std::string> attr2 = dn2.get_attributes();
+ auto attr1 = dn1.get_attributes();
+ auto attr2 = dn2.get_attributes();
if(attr1.size() < attr2.size()) return true;
if(attr1.size() > attr2.size()) return false;
- for(rdn_iter p1 = attr1.begin(); p1 != attr1.end(); ++p1)
+ for(auto p1 = attr1.begin(); p1 != attr1.end(); ++p1)
{
- std::multimap<OID, std::string>::const_iterator p2;
- p2 = attr2.find(p1->first);
+ auto p2 = attr2.find(p1->first);
if(p2 == attr2.end()) return false;
if(p1->second > p2->second) return false;
if(p1->second < p2->second) return true;
@@ -238,8 +224,6 @@ void do_ava(DER_Encoder& encoder,
ASN1_Tag string_type, const std::string& oid_str,
bool must_exist = false)
{
- typedef std::multimap<OID, std::string>::const_iterator rdn_iter;
-
const OID oid = OIDS::lookup(oid_str);
const bool exists = (dn_info.find(oid) != dn_info.end());
@@ -247,14 +231,14 @@ void do_ava(DER_Encoder& encoder,
throw Encoding_Error("X509_DN: No entry for " + oid_str);
if(!exists) return;
- std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
+ auto range = dn_info.equal_range(oid);
- for(rdn_iter j = range.first; j != range.second; ++j)
+ for(auto i = range.first; i != range.second; ++i)
{
encoder.start_cons(SET)
.start_cons(SEQUENCE)
.encode(oid)
- .encode(ASN1_String(j->second, string_type))
+ .encode(ASN1_String(i->second, string_type))
.end_cons()
.end_cons();
}
@@ -267,7 +251,7 @@ void do_ava(DER_Encoder& encoder,
*/
void X509_DN::encode_into(DER_Encoder& der) const
{
- std::multimap<OID, std::string> dn_info = get_attributes();
+ auto dn_info = get_attributes();
der.start_cons(SEQUENCE);
diff --git a/src/asn1/asn1_int.cpp b/src/asn1/asn1_int.cpp
index 5e18f3961..af01d8fa3 100644
--- a/src/asn1/asn1_int.cpp
+++ b/src/asn1/asn1_int.cpp
@@ -20,11 +20,11 @@ BER_Decoding_Error::BER_Decoding_Error(const std::string& str) :
Decoding_Error("BER: " + str) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) :
- BER_Decoding_Error(str + ": " + to_string(tag)) {}
+ BER_Decoding_Error(str + ": " + std::to_string(tag)) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str,
ASN1_Tag tag1, ASN1_Tag tag2) :
- BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {}
+ BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {}
namespace ASN1 {
diff --git a/src/asn1/asn1_obj.h b/src/asn1/asn1_obj.h
index ea21c475f..a640f712b 100644
--- a/src/asn1/asn1_obj.h
+++ b/src/asn1/asn1_obj.h
@@ -14,6 +14,7 @@
#include <botan/alg_id.h>
#include <vector>
#include <map>
+#include <chrono>
namespace Botan {
@@ -52,7 +53,7 @@ class BOTAN_DLL X509_Time : public ASN1_Object
void set_to(const std::string&);
void set_to(const std::string&, ASN1_Tag);
- X509_Time(u64bit);
+ X509_Time(const std::chrono::system_clock::time_point& time);
X509_Time(const std::string& = "");
X509_Time(const std::string&, ASN1_Tag);
private:
diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp
index 6c420ff0d..4f2c70231 100644
--- a/src/asn1/asn1_oid.cpp
+++ b/src/asn1/asn1_oid.cpp
@@ -52,7 +52,7 @@ std::string OID::as_string() const
std::string oid_str;
for(u32bit j = 0; j != id.size(); ++j)
{
- oid_str += to_string(id[j]);
+ oid_str += std::to_string(id[j]);
if(j != id.size() - 1)
oid_str += '.';
}
diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp
index 25782e239..892a44472 100644
--- a/src/asn1/asn1_str.cpp
+++ b/src/asn1/asn1_str.cpp
@@ -89,7 +89,7 @@ ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : tag(t)
tag != UTF8_STRING &&
tag != BMP_STRING)
throw Invalid_Argument("ASN1_String: Unknown string type " +
- to_string(tag));
+ std::to_string(tag));
}
/*
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index 01d31cfbd..6e56bb8d1 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -23,11 +23,11 @@ X509_Time::X509_Time(const std::string& time_str)
}
/*
-* Create an X509_Time
+* Create a X509_Time from a time point
*/
-X509_Time::X509_Time(u64bit timer)
+X509_Time::X509_Time(const std::chrono::system_clock::time_point& time)
{
- calendar_point cal = calendar_value(timer);
+ calendar_point cal = calendar_value(time);
year = cal.year;
month = cal.month;
@@ -103,11 +103,13 @@ void X509_Time::set_to(const std::string& time_str)
void X509_Time::set_to(const std::string& t_spec, ASN1_Tag tag)
{
if(tag != GENERALIZED_TIME && tag != UTC_TIME)
- throw Invalid_Argument("X509_Time: Invalid tag " + to_string(tag));
+ throw Invalid_Argument("X509_Time: Invalid tag " + std::to_string(tag));
+
if(tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15)
throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec);
if(tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13)
throw Invalid_Argument("Invalid UTCTime: " + t_spec);
+
if(t_spec[t_spec.size()-1] != 'Z')
throw Invalid_Argument("Invalid time encoding: " + t_spec);
@@ -179,21 +181,30 @@ std::string X509_Time::as_string() const
if(time_is_set() == false)
throw Invalid_State("X509_Time::as_string: No time set");
- std::string asn1rep;
- if(tag == GENERALIZED_TIME)
- asn1rep = to_string(year, 4);
- else
+ u32bit full_year = year;
+
+ if(tag == UTC_TIME)
{
if(year < 1950 || year >= 2050)
throw Encoding_Error("X509_Time: The time " + readable_string() +
" cannot be encoded as a UTCTime");
- u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900);
- asn1rep = to_string(asn1year, 2);
+
+ full_year = (year >= 2000) ? (year - 2000) : (year - 1900);
}
- asn1rep += to_string(month, 2) + to_string(day, 2);
- asn1rep += to_string(hour, 2) + to_string(minute, 2) + to_string(second, 2);
- asn1rep += "Z";
- return asn1rep;
+
+ std::string repr = std::to_string(full_year*10000000000 +
+ month*100000000 +
+ day*1000000 +
+ hour*10000 +
+ minute*100 +
+ second) + "Z";
+
+ u32bit desired_size = (tag == UTC_TIME) ? 13 : 15;
+
+ while(repr.size() < desired_size)
+ repr = "0" + repr;
+
+ return repr;
}
/*
@@ -212,14 +223,12 @@ std::string X509_Time::readable_string() const
if(time_is_set() == false)
throw Invalid_State("X509_Time::readable_string: No time set");
- std::string readable;
- readable += to_string(year, 4) + "/";
- readable += to_string(month ) + "/";
- readable += to_string(day ) + " ";
- readable += to_string(hour ) + ":";
- readable += to_string(minute, 2) + ":";
- readable += to_string(second, 2) + " UTC";
- return readable;
+ std::string output(24, 0);
+
+ std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC",
+ year, month, day, hour, minute, second);
+
+ return output;
}
/*
diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h
index 2e38af301..7de7f3753 100644
--- a/src/asn1/ber_dec.h
+++ b/src/asn1/ber_dec.h
@@ -55,14 +55,14 @@ class BOTAN_DLL BER_Decoder
BER_Decoder& decode_optional_string(MemoryRegion<byte>&,
ASN1_Tag, u16bit);
+ BER_Decoder& operator=(const BER_Decoder&) = delete;
+
BER_Decoder(DataSource&);
BER_Decoder(const byte[], u32bit);
BER_Decoder(const MemoryRegion<byte>&);
BER_Decoder(const BER_Decoder&);
~BER_Decoder();
private:
- BER_Decoder& operator=(const BER_Decoder&) { return (*this); }
-
BER_Decoder* parent;
DataSource* source;
BER_Object pushed;
diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp
index e410292bb..06aaa3dfa 100644
--- a/src/asn1/der_enc.cpp
+++ b/src/asn1/der_enc.cpp
@@ -24,7 +24,7 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if((class_tag | 0xE0) != 0xE0)
throw Encoding_Error("DER_Encoder: Invalid class tag " +
- to_string(class_tag));
+ std::to_string(class_tag));
SecureVector<byte> encoded_tag;
if(type_tag <= 30)
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp
index 01f6b99da..7a78461c2 100644
--- a/src/benchmark/benchmark.cpp
+++ b/src/benchmark/benchmark.cpp
@@ -1,6 +1,6 @@
/**
* Runtime benchmarking
-* (C) 2008 Jack Lloyd
+* (C) 2008-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -11,13 +11,15 @@
#include <botan/stream_cipher.h>
#include <botan/hash.h>
#include <botan/mac.h>
-#include <botan/time.h>
#include <memory>
-
+#include <vector>
+#include <chrono>
namespace Botan {
namespace {
+typedef std::chrono::high_resolution_clock benchmark_clock;
+
/**
* Benchmark BufferedComputation (hash or MAC)
*/
@@ -26,18 +28,23 @@ std::pair<u64bit, u64bit> bench_buf_comp(BufferedComputation* buf_comp,
const byte buf[], u32bit buf_len)
{
u64bit reps = 0;
- u64bit nanoseconds_used = 0;
- while(nanoseconds_used < nanoseconds_max)
+ std::chrono::nanoseconds max_time(nanoseconds_max);
+ std::chrono::nanoseconds time_used(0);
+
+ while(time_used < max_time)
{
- const u64bit start = get_nanoseconds_clock();
+ auto start = benchmark_clock::now();
buf_comp->update(buf, buf_len);
- nanoseconds_used += get_nanoseconds_clock() - start;
+ time_used += benchmark_clock::now() - start;
++reps;
}
- return std::make_pair(reps * buf_len, nanoseconds_used);
+ u64bit ns_taken =
+ std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count();
+
+ return std::make_pair(reps * buf_len, ns_taken);
}
/**
@@ -51,21 +58,26 @@ bench_block_cipher(BlockCipher* block_cipher,
const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE;
u64bit reps = 0;
- u64bit nanoseconds_used = 0;
+
+ std::chrono::nanoseconds max_time(nanoseconds_max);
+ std::chrono::nanoseconds time_used(0);
block_cipher->set_key(buf, block_cipher->MAXIMUM_KEYLENGTH);
- while(nanoseconds_used < nanoseconds_max)
+ while(time_used < max_time)
{
- const u64bit start = get_nanoseconds_clock();
+ auto start = benchmark_clock::now();
block_cipher->encrypt_n(buf, buf, in_blocks);
- nanoseconds_used += get_nanoseconds_clock() - start;
+ time_used += benchmark_clock::now() - start;
++reps;
}
+ u64bit ns_taken =
+ std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count();
+
return std::make_pair(reps * in_blocks * block_cipher->BLOCK_SIZE,
- nanoseconds_used);
+ ns_taken);
}
/**
@@ -77,20 +89,25 @@ bench_stream_cipher(StreamCipher* stream_cipher,
byte buf[], u32bit buf_len)
{
u64bit reps = 0;
- u64bit nanoseconds_used = 0;
stream_cipher->set_key(buf, stream_cipher->MAXIMUM_KEYLENGTH);
- while(nanoseconds_used < nanoseconds_max)
+ std::chrono::nanoseconds max_time(nanoseconds_max);
+ std::chrono::nanoseconds time_used(0);
+
+ while(time_used < max_time)
{
- const u64bit start = get_nanoseconds_clock();
+ auto start = benchmark_clock::now();
stream_cipher->cipher1(buf, buf_len);
- nanoseconds_used += get_nanoseconds_clock() - start;
+ time_used += benchmark_clock::now() - start;
++reps;
}
- return std::make_pair(reps * buf_len, nanoseconds_used);
+ u64bit ns_taken =
+ std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count();
+
+ return std::make_pair(reps * buf_len, ns_taken);
}
/**
diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h
index 9c4e410f1..baabc14ca 100644
--- a/src/benchmark/benchmark.h
+++ b/src/benchmark/benchmark.h
@@ -1,6 +1,6 @@
/**
* Runtime benchmarking
-* (C) 2008 Jack Lloyd
+* (C) 2008-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -12,7 +12,6 @@
#include <botan/rng.h>
#include <map>
#include <string>
-
namespace Botan {
/**
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index d8dfd1fcb..cfb1406d7 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -81,7 +81,7 @@ std::string Lion::name() const
{
return "Lion(" + hash->name() + "," +
cipher->name() + "," +
- to_string(BLOCK_SIZE) + ")";
+ std::to_string(BLOCK_SIZE) + ")";
}
/*
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index 8a92824cc..56cd7446c 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -255,7 +255,7 @@ MISTY1::MISTY1(u32bit rounds) : BlockCipher(8, 16)
{
if(rounds != 8)
throw Invalid_Argument("MISTY1: Invalid number of rounds: "
- + to_string(rounds));
+ + std::to_string(rounds));
}
}
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index 0bd596b10..1b71de85a 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -99,7 +99,7 @@ void RC5::key_schedule(const byte key[], u32bit length)
*/
std::string RC5::name() const
{
- return "RC5(" + to_string(ROUNDS) + ")";
+ return "RC5(" + std::to_string(ROUNDS) + ")";
}
/*
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index eb5c22fc9..fcbe84c8b 100644
--- a/src/block/safer/safer_sk.cpp
+++ b/src/block/safer/safer_sk.cpp
@@ -112,7 +112,7 @@ void SAFER_SK::key_schedule(const byte key[], u32bit)
*/
std::string SAFER_SK::name() const
{
- return "SAFER-SK(" + to_string(ROUNDS) + ")";
+ return "SAFER-SK(" + std::to_string(ROUNDS) + ")";
}
/*
diff --git a/src/build-data/cc/compaq.txt b/src/build-data/cc/compaq.txt
deleted file mode 100644
index 7e7f1ea56..000000000
--- a/src/build-data/cc/compaq.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-macro_name COMPAQ
-
-binary_name cxx
-
-compile_option "-c "
-output_to_option "-o "
-add_include_dir_option -I
-add_lib_dir_option -L
-add_lib_option -l
-
-# -O3 and up seem to be unhappy with Botan
-lib_opt_flags "-O2"
-check_opt_flags "-O2"
-debug_flags -g
-no_debug_flags ""
-lang_flags "-std ansi -D__USE_STD_IOSTREAM"
-
-makefile_style unix
-
-<so_link_flags>
-default -> "$(CXX) -shared -soname $(SONAME)"
-</so_link_flags>
-
-<mach_opt>
-alpha -> "-arch=SUBMODEL" alpha-
-</mach_opt>
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index 42567ba03..14701718c 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -1,8 +1,6 @@
macro_name GCC
-binary_name g++
-
-compiler_has_tr1 yes
+binary_name g++-4.5
compile_option "-c "
output_to_option "-o "
@@ -10,7 +8,7 @@ add_include_dir_option -I
add_lib_dir_option -L
add_lib_option -l
-lang_flags "-D_REENTRANT -ansi -Wno-long-long"
+lang_flags "-ansi -std=c++0x"
warning_flags "-W -Wall"
#warning_flags "-Werror -Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wno-unused-parameter"
@@ -71,6 +69,8 @@ ppc64 -> "-mcpu=SUBMODEL" ppc
# Note that the 'linking' bit means "use this for both compiling *and* linking"
<mach_abi_linking>
+all -> "-pthread"
+
amd64 -> "-m64"
mips64 -> "-mabi=64"
s390 -> "-m31"
@@ -79,10 +79,6 @@ sparc32 -> "-m32 -mno-app-regs"
sparc64 -> "-m64 -mno-app-regs"
ppc64 -> "-m64"
-# This should probably be used on most/all targets, but the docs are incomplete
-openbsd -> "-pthread"
-freebsd -> "-pthread"
-dragonfly -> "-pthread"
-netbsd -> "-pthread -D_NETBSD_SOURCE"
+netbsd -> "-D_NETBSD_SOURCE"
qnx -> "-fexceptions -D_QNX_SOURCE"
</mach_abi_linking>
diff --git a/src/build-data/cc/icc.txt b/src/build-data/cc/icc.txt
index ea7936870..1aab4d111 100644
--- a/src/build-data/cc/icc.txt
+++ b/src/build-data/cc/icc.txt
@@ -2,8 +2,6 @@ macro_name INTEL
binary_name icpc
-compiler_has_tr1 yes
-
compile_option "-c "
output_to_option "-o "
add_include_dir_option -I
@@ -14,7 +12,7 @@ lib_opt_flags "-O2 -ip -unroll"
check_opt_flags "-O2"
debug_flags -g
no_debug_flags "-fomit-frame-pointer"
-lang_flags ""
+lang_flags "-std=c++0x"
warning_flags "-w1"
shared_flags "-fPIC"
diff --git a/src/build-data/cc/kai.txt b/src/build-data/cc/kai.txt
deleted file mode 100644
index 2d9c0cd65..000000000
--- a/src/build-data/cc/kai.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-macro_name KAI
-
-binary_name KCC
-
-compile_option "-c "
-output_to_option "-o "
-add_include_dir_option -I
-add_lib_dir_option -L
-add_lib_option -l
-
-ar_command "KCC -o"
-
-lib_opt_flags "+K3 --inline_auto_space_time=65 --abstract_pointer"
-check_opt_flags "+K3"
-lang_flags "-D__KAI_STRICT"
-debug_flags -g
-no_debug_flags ""
-
-makefile_style unix
-
-<so_link_flags>
-default -> "$(CXX) --soname $(SONAME)"
-</so_link_flags>
-
-<mach_abi_linking>
-all -> "--one_per"
-</mach_abi_linking>
diff --git a/src/build-data/cc/mipspro.txt b/src/build-data/cc/mipspro.txt
deleted file mode 100644
index 28b47b30d..000000000
--- a/src/build-data/cc/mipspro.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-macro_name MIPSPRO
-
-binary_name CC
-
-compile_option "-c "
-output_to_option "-o "
-add_include_dir_option -I
-add_lib_dir_option -L
-add_lib_option -l
-
-lib_opt_flags "-O3 -OPT:alias=TYPED"
-check_opt_flags "-O3 -OPT:alias=TYPED"
-debug_flags "-g3"
-no_debug_flags ""
-shared_flags "-KPIC"
-lang_flags "-ansi -LANG:ansi-for-init-scope=ON"
-# Disabled, because, while my code is fine, it warns about a lot of it's own
-# headers <g>
-#warning_flags "-fullwarn"
-
-makefile_style unix
-
-<so_link_flags>
-default -> "$(CXX) -shared -Wl,-soname,$(SONAME)"
-</so_link_flags>
-
-<mach_opt>
-mips32 -> "-mips1"
-mips64 -> "-mips3"
-
-mips64-r5000 -> "-mips4 -r5000"
-mips64-r8000 -> "-mips4 -r8000"
-mips64-r10000 -> "-mips4 -r10000"
-</mach_opt>
-
-<mach_abi_linking>
-mips32 -> "-n32"
-mips64 -> "-64"
-</mach_abi_linking>
diff --git a/src/build-data/cc/sgipro64.txt b/src/build-data/cc/sgipro64.txt
deleted file mode 100644
index e6a58f16d..000000000
--- a/src/build-data/cc/sgipro64.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-macro_name SGI_PRO64
-
-binary_name sgiCC
-
-compile_option "-c "
-output_to_option "-o "
-add_include_dir_option -I
-add_lib_dir_option -L
-add_lib_option -l
-
-lib_opt_flags "-O3 -OPT:alias=TYPED"
-check_opt_flags "-O3 -OPT:alias=TYPED"
-debug_flags "-g3"
-no_debug_flags ""
-shared_flags "-KPIC"
-lang_flags "-ansi -LANG:ansi-for-init-scope=ON"
-warning_flags "-Wall -W"
-
-makefile_style unix
-
-<so_link_flags>
-default -> "$(CXX) -shared -Wl,-soname,$(SONAME)"
-</so_link_flags>
-
-<mach_opt>
-
-</mach_opt>
diff --git a/src/build-data/os/windows.txt b/src/build-data/os/windows.txt
index 4d8879dd8..23838eb6d 100644
--- a/src/build-data/os/windows.txt
+++ b/src/build-data/os/windows.txt
@@ -11,9 +11,10 @@ install_cmd_data "copy"
install_cmd_exec "copy"
<target_features>
-win32_virtual_lock
-win32_get_systemtime
gmtime_s
+win32_get_systemtime
+win32_query_perf_counter
+win32_virtual_lock
</target_features>
<supports_shared>
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index 73a2843f7..5a464ba3c 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -1,7 +1,7 @@
/*
* EAC Time Types
* (C) 2007 FlexSecure GmbH
-* 2008 Jack Lloyd
+* 2008-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -22,7 +22,7 @@ SecureVector<byte> enc_two_digit(u32bit in)
{
SecureVector<byte> result;
in %= 100;
- if (in < 10)
+ if(in < 10)
result.append(0x00);
else
{
@@ -50,9 +50,10 @@ u32bit dec_two_digit(byte b1, byte b2)
/*
* Create an EAC_Time
*/
-EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) : tag(t)
+EAC_Time::EAC_Time(const std::chrono::system_clock::time_point& time,
+ ASN1_Tag t) : tag(t)
{
- calendar_point cal = calendar_value(timer);
+ calendar_point cal = calendar_value(time);
year = cal.year;
month = cal.month;
@@ -62,11 +63,11 @@ EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) : tag(t)
/*
* Create an EAC_Time
*/
-EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t)
- :tag(t)
+EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t) : tag(t)
{
set_to(t_spec);
}
+
/*
* Create an EAC_Time
*/
@@ -83,7 +84,7 @@ EAC_Time::EAC_Time(u32bit y, u32bit m, u32bit d, ASN1_Tag t)
*/
void EAC_Time::set_to(const std::string& time_str)
{
- if (time_str == "")
+ if(time_str == "")
{
year = month = day = 0;
return;
@@ -92,28 +93,28 @@ void EAC_Time::set_to(const std::string& time_str)
std::vector<std::string> params;
std::string current;
- for (u32bit j = 0; j != time_str.size(); ++j)
+ for(u32bit j = 0; j != time_str.size(); ++j)
{
- if (Charset::is_digit(time_str[j]))
+ if(Charset::is_digit(time_str[j]))
current += time_str[j];
else
{
- if (current != "")
+ if(current != "")
params.push_back(current);
current.clear();
}
}
- if (current != "")
+ if(current != "")
params.push_back(current);
- if (params.size() != 3)
+ if(params.size() != 3)
throw Invalid_Argument("Invalid time specification " + time_str);
year = to_u32bit(params[0]);
month = to_u32bit(params[1]);
day = to_u32bit(params[2]);
- if (!passes_sanity_check())
+ if(!passes_sanity_check())
throw Invalid_Argument("Invalid time specification " + time_str);
}
@@ -132,15 +133,10 @@ void EAC_Time::encode_into(DER_Encoder& der) const
*/
std::string EAC_Time::as_string() const
{
- if (time_is_set() == false)
+ if(time_is_set() == false)
throw Invalid_State("EAC_Time::as_string: No time set");
- std::string asn1rep;
- asn1rep = to_string(year, 2);
-
- asn1rep += to_string(month, 2) + to_string(day, 2);
-
- return asn1rep;
+ return std::to_string(year * 10000 + month * 100 + day);
}
/*
@@ -156,15 +152,14 @@ bool EAC_Time::time_is_set() const
*/
std::string EAC_Time::readable_string() const
{
- if (time_is_set() == false)
+ if(time_is_set() == false)
throw Invalid_State("EAC_Time::readable_string: No time set");
- std::string readable;
- readable += to_string(year, 2) + "/";
- readable += to_string(month, 2) + "/";
- readable += to_string(day, 2) + " ";
+ std::string output(11, 0);
+
+ std::sprintf(&output[0], "%04d/%02d/%02d", year, month, day);
- return readable;
+ return output;
}
/*
@@ -172,11 +167,11 @@ std::string EAC_Time::readable_string() const
*/
bool EAC_Time::passes_sanity_check() const
{
- if (year < 2000 || year > 2099)
+ if(year < 2000 || year > 2099)
return false;
- if (month == 0 || month > 12)
+ if(month == 0 || month > 12)
return false;
- if (day == 0 || day > 31)
+ if(day == 0 || day > 31)
return false;
return true;
@@ -185,11 +180,11 @@ bool EAC_Time::passes_sanity_check() const
/*
* modification functions
*/
-
void EAC_Time::add_years(u32bit years)
{
year += years;
}
+
void EAC_Time::add_months(u32bit months)
{
year += months/12;
@@ -201,23 +196,22 @@ void EAC_Time::add_months(u32bit months)
}
}
-
/*
* Compare this time against another
*/
s32bit EAC_Time::cmp(const EAC_Time& other) const
{
- if (time_is_set() == false)
+ if(time_is_set() == false)
throw Invalid_State("EAC_Time::cmp: No time set");
const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0;
- if (year < other.year) return EARLIER;
- if (year > other.year) return LATER;
- if (month < other.month) return EARLIER;
- if (month > other.month) return LATER;
- if (day < other.day) return EARLIER;
- if (day > other.day) return LATER;
+ if(year < other.year) return EARLIER;
+ if(year > other.year) return LATER;
+ if(month < other.month) return EARLIER;
+ if(month > other.month) return LATER;
+ if(day < other.day) return EARLIER;
+ if(day > other.day) return LATER;
return SAME_TIME;
}
@@ -229,22 +223,27 @@ bool operator==(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) == 0);
}
+
bool operator!=(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) != 0);
}
+
bool operator<=(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) <= 0);
}
+
bool operator>=(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) >= 0);
}
+
bool operator>(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) > 0);
}
+
bool operator<(const EAC_Time& t1, const EAC_Time& t2)
{
return (t1.cmp(t2) < 0);
@@ -281,19 +280,6 @@ void EAC_Time::decode_from(BER_Decoder& source)
}
-u32bit EAC_Time::get_year() const
- {
- return year;
- }
-u32bit EAC_Time::get_month() const
- {
- return month;
- }
-u32bit EAC_Time::get_day() const
- {
- return day;
- }
-
/*
* make the value an octet string for encoding
*/
@@ -306,28 +292,4 @@ SecureVector<byte> EAC_Time::encoded_eac_time() const
return result;
}
-ASN1_Ced::ASN1_Ced(std::string const& str)
- : EAC_Time(str, ASN1_Tag(37))
- {}
-
-ASN1_Ced::ASN1_Ced(u64bit val)
- : EAC_Time(val, ASN1_Tag(37))
- {}
-
-ASN1_Ced::ASN1_Ced(EAC_Time const& other)
- : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(37))
- {}
-
-ASN1_Cex::ASN1_Cex(std::string const& str)
- : EAC_Time(str, ASN1_Tag(36))
- {}
-
-ASN1_Cex::ASN1_Cex(u64bit val)
- : EAC_Time(val, ASN1_Tag(36))
- {}
-
-ASN1_Cex::ASN1_Cex(EAC_Time const& other)
- : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(36))
- {}
-
}
diff --git a/src/cert/cvc/cvc_gen_cert.h b/src/cert/cvc/cvc_gen_cert.h
index 4ad8cfaac..8c3b1b989 100644
--- a/src/cert/cvc/cvc_gen_cert.h
+++ b/src/cert/cvc/cvc_gen_cert.h
@@ -31,7 +31,7 @@ class EAC1_1_gen_CVC : public EAC1_1_obj<Derived> // CRTP continuation from EAC1
* Get this certificates public key.
* @result this certificates public key
*/
- std::auto_ptr<Public_Key> subject_public_key() const;
+ std::unique_ptr<Public_Key> subject_public_key() const;
/**
* Find out whether this object is self signed.
@@ -118,9 +118,9 @@ MemoryVector<byte> EAC1_1_gen_CVC<Derived>::make_signed(
}
template<typename Derived>
-std::auto_ptr<Public_Key> EAC1_1_gen_CVC<Derived>::subject_public_key() const
+std::unique_ptr<Public_Key> EAC1_1_gen_CVC<Derived>::subject_public_key() const
{
- return std::auto_ptr<Public_Key>(new ECDSA_PublicKey(*m_pk));
+ return std::unique_ptr<Public_Key>(new ECDSA_PublicKey(*m_pk));
}
template<typename Derived> SecureVector<byte> EAC1_1_gen_CVC<Derived>::build_cert_body(MemoryRegion<byte> const& tbs)
diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp
index fbd042676..0c765347f 100644
--- a/src/cert/cvc/cvc_self.cpp
+++ b/src/cert/cvc/cvc_self.cpp
@@ -163,11 +163,12 @@ EAC1_1_ADO create_ado_req(Private_Key const& key,
{
throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type");
}
+
std::string padding_and_hash = padding_and_hash_from_oid(req.signature_algorithm().oid);
PK_Signer signer(*priv_key, padding_and_hash);
SecureVector<byte> tbs_bits = req.BER_encode();
tbs_bits.append(DER_Encoder().encode(car).get_contents());
- MemoryVector<byte> signed_cert = EAC1_1_ADO::make_signed(signer, tbs_bits, rng);
+ MemoryVector<byte> signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng);
DataSource_Memory source(signed_cert);
return EAC1_1_ADO(source);
@@ -190,9 +191,8 @@ EAC1_1_CVC create_cvca(Private_Key const& key,
}
EAC1_1_CVC_Options opts;
opts.car = car;
- const u64bit current_time = system_time();
- opts.ced = ASN1_Ced(current_time);
+ opts.ced = ASN1_Ced(std::chrono::system_clock::now());
opts.cex = ASN1_Cex(opts.ced);
opts.cex.add_months(cvca_validity_months);
opts.holder_auth_templ = (CVCA | (iris * IRIS) | (fingerpr * FINGERPRINT));
@@ -207,12 +207,12 @@ EAC1_1_CVC link_cvca(EAC1_1_CVC const& signer,
EAC1_1_CVC const& signee,
RandomNumberGenerator& rng)
{
- ECDSA_PrivateKey const* priv_key = dynamic_cast<ECDSA_PrivateKey const*>(&key);
+ const ECDSA_PrivateKey* priv_key = dynamic_cast<ECDSA_PrivateKey const*>(&key);
+
if (priv_key == 0)
- {
- throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type");
- }
- ASN1_Ced ced(system_time());
+ throw Invalid_Argument("link_cvca(): unsupported key type");
+
+ ASN1_Ced ced(std::chrono::system_clock::now());
ASN1_Cex cex(signee.get_cex());
if (*static_cast<EAC_Time*>(&ced) > *static_cast<EAC_Time*>(&cex))
{
@@ -265,7 +265,7 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert,
PK_Signer pk_signer(*priv_key, padding_and_hash);
std::auto_ptr<Public_Key> pk = signee.subject_public_key();
ECDSA_PublicKey* subj_pk = dynamic_cast<ECDSA_PublicKey*>(pk.get());
- std::auto_ptr<Public_Key> signer_pk = signer_cert.subject_public_key();
+ std::unique_ptr<Public_Key> signer_pk = signer_cert.subject_public_key();
// for the case that the domain parameters are not set...
// (we use those from the signer because they must fit)
@@ -274,8 +274,9 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert,
subj_pk->set_parameter_encoding(EC_DOMPAR_ENC_IMPLICITCA);
AlgorithmIdentifier sig_algo(signer_cert.signature_algorithm());
- const u64bit current_time = system_time();
- ASN1_Ced ced(current_time);
+
+ ASN1_Ced ced(std::chrono::system_clock::now());
+
u32bit chat_val;
u32bit chat_low = signer_cert.get_chat_value() & 0x3; // take the chat rights from signer
ASN1_Cex cex(ced);
diff --git a/src/cert/cvc/eac_asn_obj.h b/src/cert/cvc/eac_asn_obj.h
index 9eaf02f63..3ab57d7e4 100644
--- a/src/cert/cvc/eac_asn_obj.h
+++ b/src/cert/cvc/eac_asn_obj.h
@@ -56,7 +56,6 @@ class BOTAN_DLL EAC_Time : public ASN1_Object
* e.g. "2007 08 01"
*/
void set_to(const std::string& str);
- //void set_to(const std::string&, ASN1_Tag);
/**
* Add the specified number of years to this.
@@ -74,24 +73,28 @@ class BOTAN_DLL EAC_Time : public ASN1_Object
* Get the year value of this objects.
* @return the year value
*/
- u32bit get_year() const;
+ u32bit get_year() const { return year; }
/**
* Get the month value of this objects.
* @return the month value
*/
- u32bit get_month() const;
+ u32bit get_month() const { return month; }
/**
* Get the day value of this objects.
* @return the day value
*/
- u32bit get_day() const;
+ u32bit get_day() const { return day; }
- EAC_Time(u64bit, ASN1_Tag t = ASN1_Tag(0));
- //EAC_Time(const std::string& = "");
- EAC_Time(const std::string&, ASN1_Tag = ASN1_Tag(0));
- EAC_Time(u32bit year, u32bit month, u32bit day, ASN1_Tag = ASN1_Tag(0));
+ EAC_Time(const std::chrono::system_clock::time_point& time,
+ ASN1_Tag tag = ASN1_Tag(0));
+
+ EAC_Time(const std::string& yyyy_mm_dd,
+ ASN1_Tag tag = ASN1_Tag(0));
+
+ EAC_Time(u32bit year, u32bit month, u32bit day,
+ ASN1_Tag tag = ASN1_Tag(0));
virtual ~EAC_Time() {}
private:
@@ -113,25 +116,25 @@ class BOTAN_DLL ASN1_Ced : public EAC_Time
* @param str a string in the format "yyyy mm dd",
* e.g. "2007 08 01"
*/
- ASN1_Ced(std::string const& str = "");
+ ASN1_Ced(std::string const& str = "") :
+ EAC_Time(str, ASN1_Tag(37)) {}
/**
- * Construct a CED from a timer value.
- * @param time the number of seconds elapsed midnight, 1st
- * January 1970 GMT (or 7pm, 31st December 1969 EST) up to the
- * desired date
+ * Construct a CED from a time point
*/
- ASN1_Ced(u64bit time);
+ ASN1_Ced(const std::chrono::system_clock::time_point& time) :
+ EAC_Time(time, ASN1_Tag(37)) {}
/**
* Copy constructor (for general EAC_Time objects).
* @param other the object to copy from
*/
- ASN1_Ced(EAC_Time const& other);
- //ASN1_Ced(ASN1_Cex const& cex);
+ ASN1_Ced(EAC_Time const& other) :
+ EAC_Time(other.get_year(), other.get_month(), other.get_day(),
+ ASN1_Tag(37))
+ {}
};
-
/**
* This class represents CVC CEXs. Only limited sanity checks of
* the inputted date value are performed.
@@ -140,27 +143,20 @@ class BOTAN_DLL ASN1_Cex : public EAC_Time
{
public:
/**
- * Construct a CED from a string value.
+ * Construct a CEX from a string value.
* @param str a string in the format "yyyy mm dd",
* e.g. "2007 08 01"
*/
- ASN1_Cex(std::string const& str="");
+ ASN1_Cex(std::string const& str = "") :
+ EAC_Time(str, ASN1_Tag(36)) {}
- /**
- * Construct a CED from a timer value.
- * @param time the number of seconds elapsed
- * midnight, 1st
- * January 1970 GMT (or 7pm, 31st December 1969 EST)
- * up to the desired date
- */
- ASN1_Cex(u64bit time);
+ ASN1_Cex(const std::chrono::system_clock::time_point& time) :
+ EAC_Time(time, ASN1_Tag(36)) {}
- /**
- * Copy constructor (for general EAC_Time objects).
- * @param other the object to copy from
- */
- ASN1_Cex(EAC_Time const& other);
- //ASN1_Cex(ASN1_Ced const& ced);
+ ASN1_Cex(EAC_Time const& other) :
+ EAC_Time(other.get_year(), other.get_month(), other.get_day(),
+ ASN1_Tag(36))
+ {}
};
/**
diff --git a/src/cert/cvc/info.txt b/src/cert/cvc/info.txt
index 0d5687770..91de3bc19 100644
--- a/src/cert/cvc/info.txt
+++ b/src/cert/cvc/info.txt
@@ -1,5 +1,4 @@
define CARD_VERIFIABLE_CERTIFICATES
-
load_on auto
<header:public>
diff --git a/src/cert/x509/crl_ent.cpp b/src/cert/x509/crl_ent.cpp
index 42a742ebb..e7ce1a57a 100644
--- a/src/cert/x509/crl_ent.cpp
+++ b/src/cert/x509/crl_ent.cpp
@@ -11,7 +11,6 @@
#include <botan/ber_dec.h>
#include <botan/bigint.h>
#include <botan/oids.h>
-#include <botan/time.h>
namespace Botan {
@@ -31,7 +30,7 @@ CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why) :
throw_on_unknown_critical(false)
{
serial = cert.serial_number();
- time = X509_Time(system_time());
+ time = X509_Time(std::chrono::system_clock::now());
reason = why;
}
diff --git a/src/cert/x509/pkcs10.cpp b/src/cert/x509/pkcs10.cpp
index 81bb58555..e78439757 100644
--- a/src/cert/x509/pkcs10.cpp
+++ b/src/cert/x509/pkcs10.cpp
@@ -45,7 +45,7 @@ void PKCS10_Request::force_decode()
cert_req_info.decode(version);
if(version != 0)
throw Decoding_Error("Unknown version code in PKCS #10 request: " +
- to_string(version));
+ std::to_string(version));
X509_DN dn_subject;
cert_req_info.decode(dn_subject);
diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp
index 1f3e643e9..3eb7ff77e 100644
--- a/src/cert/x509/x509_ca.cpp
+++ b/src/cert/x509/x509_ca.cpp
@@ -14,10 +14,6 @@
#include <botan/parsing.h>
#include <botan/lookup.h>
#include <botan/oids.h>
-#include <botan/time.h>
-#include <algorithm>
-#include <typeinfo>
-#include <iterator>
#include <memory>
#include <set>
@@ -57,7 +53,7 @@ X509_Certificate X509_CA::sign_request(const PKCS10_Request& req,
constraints = Key_Constraints(KEY_CERT_SIGN | CRL_SIGN);
else
{
- std::auto_ptr<Public_Key> key(req.subject_public_key());
+ std::unique_ptr<Public_Key> key(req.subject_public_key());
constraints = X509::find_constraints(*key, req.constraints());
}
@@ -169,8 +165,7 @@ X509_CRL X509_CA::update_crl(const X509_CRL& crl,
for(u32bit j = 0; j != already_revoked.size(); ++j)
{
- std::set<SecureVector<byte> >::const_iterator i;
- i = removed_from_crl.find(already_revoked[j].serial_number());
+ auto i = removed_from_crl.find(already_revoked[j].serial_number());
if(i == removed_from_crl.end())
all_revoked.push_back(already_revoked[j]);
@@ -197,7 +192,8 @@ X509_CRL X509_CA::make_crl(const std::vector<CRL_Entry>& revoked,
next_update = timespec_to_u32bit("7d");
// Totally stupid: ties encoding logic to the return of std::time!!
- const u64bit current_time = system_time();
+ auto current_time = std::chrono::system_clock::now();
+ auto expire_time = current_time + std::chrono::seconds(next_update);
Extensions extensions;
extensions.add(
@@ -210,7 +206,7 @@ X509_CRL X509_CA::make_crl(const std::vector<CRL_Entry>& revoked,
.encode(ca_sig_algo)
.encode(cert.issuer_dn())
.encode(X509_Time(current_time))
- .encode(X509_Time(current_time + next_update))
+ .encode(X509_Time(expire_time))
.encode_if(revoked.size() > 0,
DER_Encoder()
.start_cons(SEQUENCE)
diff --git a/src/cert/x509/x509_ca.h b/src/cert/x509/x509_ca.h
index 6eb4bbbef..b680bd0e4 100644
--- a/src/cert/x509/x509_ca.h
+++ b/src/cert/x509/x509_ca.h
@@ -97,11 +97,11 @@ class BOTAN_DLL X509_CA
const Private_Key& key,
const std::string& hash_fn);
+ X509_CA(const X509_CA&) = delete;
+ X509_CA& operator=(const X509_CA&) = delete;
+
~X509_CA();
private:
- X509_CA(const X509_CA&) {}
- X509_CA& operator=(const X509_CA&) { return (*this); }
-
X509_CRL make_crl(const std::vector<CRL_Entry>& entries,
u32bit crl_number, u32bit next_update,
RandomNumberGenerator& rng) const;
diff --git a/src/cert/x509/x509_crl.cpp b/src/cert/x509/x509_crl.cpp
index f6a344dba..3613c1a91 100644
--- a/src/cert/x509/x509_crl.cpp
+++ b/src/cert/x509/x509_crl.cpp
@@ -44,7 +44,7 @@ void X509_CRL::force_decode()
if(version != 0 && version != 1)
throw X509_CRL_Error("Unknown X.509 CRL version " +
- to_string(version+1));
+ std::to_string(version+1));
AlgorithmIdentifier sig_algo_inner;
tbs_crl.decode(sig_algo_inner);
diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp
index 05f23298b..e3844e8e9 100644
--- a/src/cert/x509/x509cert.cpp
+++ b/src/cert/x509/x509cert.cpp
@@ -27,12 +27,8 @@ std::vector<std::string> lookup_oids(const std::vector<std::string>& in)
{
std::vector<std::string> out;
- std::vector<std::string>::const_iterator i = in.begin();
- while(i != in.end())
- {
+ for(auto i = in.begin(); i != in.end(); ++i)
out.push_back(OIDS::lookup(OID(*i)));
- ++i;
- }
return out;
}
@@ -84,7 +80,7 @@ void X509_Certificate::force_decode()
.decode(dn_subject);
if(version > 2)
- throw Decoding_Error("Unknown X.509 cert version " + to_string(version));
+ throw Decoding_Error("Unknown X.509 cert version " + std::to_string(version));
if(sig_algo != sig_algo_inner)
throw Decoding_Error("Algorithm identifier mismatch");
@@ -304,25 +300,16 @@ bool operator!=(const X509_Certificate& cert1, const X509_Certificate& cert2)
*/
X509_DN create_dn(const Data_Store& info)
{
- class DN_Matcher : public Data_Store::Matcher
+ auto names = info.search_for(
+ [](const std::string& key, const std::string&)
{
- public:
- bool operator()(const std::string& key, const std::string&) const
- {
- if(key.find("X520.") != std::string::npos)
- return true;
- return false;
- }
- };
-
- std::multimap<std::string, std::string> names =
- info.search_with(DN_Matcher());
+ return (key.find("X520.") != std::string::npos);
+ });
X509_DN dn;
- std::multimap<std::string, std::string>::iterator j;
- for(j = names.begin(); j != names.end(); ++j)
- dn.add_attribute(j->first, j->second);
+ for(auto i = names.begin(); i != names.end(); ++i)
+ dn.add_attribute(i->first, i->second);
return dn;
}
@@ -332,33 +319,19 @@ X509_DN create_dn(const Data_Store& info)
*/
AlternativeName create_alt_name(const Data_Store& info)
{
- class AltName_Matcher : public Data_Store::Matcher
+ auto names = info.search_for(
+ [](const std::string& key, const std::string&)
{
- public:
- bool operator()(const std::string& key, const std::string&) const
- {
- for(u32bit j = 0; j != matches.size(); ++j)
- if(key.compare(matches[j]) == 0)
- return true;
- return false;
- }
-
- AltName_Matcher(const std::string& match_any_of)
- {
- matches = split_on(match_any_of, '/');
- }
- private:
- std::vector<std::string> matches;
- };
-
- std::multimap<std::string, std::string> names =
- info.search_with(AltName_Matcher("RFC822/DNS/URI/IP"));
+ return (key == "RFC822" ||
+ key == "DNS" ||
+ key == "URI" ||
+ key == "IP");
+ });
AlternativeName alt_name;
- std::multimap<std::string, std::string>::iterator j;
- for(j = names.begin(); j != names.end(); ++j)
- alt_name.add_attribute(j->first, j->second);
+ for(auto i = names.begin(); i != names.end(); ++i)
+ alt_name.add_attribute(i->first, i->second);
return alt_name;
}
diff --git a/src/cert/x509/x509find.cpp b/src/cert/x509/x509find.cpp
index 257367da9..41643a94a 100644
--- a/src/cert/x509/x509find.cpp
+++ b/src/cert/x509/x509find.cpp
@@ -11,6 +11,8 @@
namespace Botan {
+namespace X509_Store_Search {
+
namespace {
/*
@@ -42,70 +44,65 @@ bool ignore_case(const std::string& searching_for, const std::string& found)
/*
* Search based on the contents of a DN entry
*/
-bool DN_Check::match(const X509_Certificate& cert) const
+std::function<bool (const X509_Certificate&)>
+by_dn(const std::string& dn_entry,
+ const std::string& to_find,
+ DN_Search_Type method)
{
- std::vector<std::string> info = cert.subject_info(dn_entry);
-
- for(u32bit j = 0; j != info.size(); ++j)
- if(compare(info[j], looking_for))
- return true;
- return false;
- }
+ if(method == SUBSTRING_MATCHING)
+ return by_dn(dn_entry, to_find, substring_match);
+ else if(method == IGNORE_CASE)
+ return by_dn(dn_entry, to_find, ignore_case);
-/*
-* DN_Check Constructor
-*/
-DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for,
- compare_fn func)
- {
- this->dn_entry = dn_entry;
- this->looking_for = looking_for;
- compare = func;
+ throw Invalid_Argument("Unknown method argument to by_dn");
}
-/*
-* DN_Check Constructor
-*/
-DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for,
- Search_Type method)
+std::function<bool (const X509_Certificate&)>
+by_dn(const std::string& dn_entry,
+ const std::string& to_find,
+ std::function<bool (std::string, std::string)> compare)
{
- this->dn_entry = dn_entry;
- this->looking_for = looking_for;
+ return [&](const X509_Certificate& cert)
+ {
+ std::vector<std::string> info = cert.subject_info(dn_entry);
- if(method == SUBSTRING_MATCHING)
- compare = &substring_match;
- else if(method == IGNORE_CASE)
- compare = &ignore_case;
- else
- throw Invalid_Argument("Unknown method argument to DN_Check()");
+ for(u32bit i = 0; i != info.size(); ++i)
+ if(compare(info[i], to_find))
+ return true;
+ return false;
+ };
}
-/*
-* Match by issuer and serial number
-*/
-bool IandS_Match::match(const X509_Certificate& cert) const
+std::function<bool (const X509_Certificate&)>
+by_issuer_and_serial(const X509_DN& issuer, const MemoryRegion<byte>& serial)
{
- if(cert.serial_number() != serial)
- return false;
- return (cert.issuer_dn() == issuer);
+ /* Serial number compare is much faster than X.509 DN, and unlikely
+ to collide even across issuers, so do that first to fail fast
+ */
+
+ return [&](const X509_Certificate& cert)
+ {
+ if(cert.serial_number() != serial)
+ return false;
+ return (cert.issuer_dn() == issuer);
+ };
}
-/*
-* IandS_Match Constructor
-*/
-IandS_Match::IandS_Match(const X509_DN& issuer,
- const MemoryRegion<byte>& serial)
+std::function<bool (const X509_Certificate&)>
+by_issuer_and_serial(const X509_DN& issuer, const BigInt& serial)
{
- this->issuer = issuer;
- this->serial = serial;
+ return by_issuer_and_serial(issuer, BigInt::encode(serial));
}
-/*
-* Match by subject key identifier
-*/
-bool SKID_Match::match(const X509_Certificate& cert) const
+std::function<bool (const X509_Certificate&)>
+by_skid(const MemoryRegion<byte>& subject_key_id)
{
- return (cert.subject_key_id() == skid);
+ return [&](const X509_Certificate& cert)
+ {
+ return (cert.subject_key_id() == subject_key_id);
+ };
}
}
+
+}
diff --git a/src/cert/x509/x509find.h b/src/cert/x509/x509find.h
index a7a84c7a5..1bf29dfbc 100644
--- a/src/cert/x509/x509find.h
+++ b/src/cert/x509/x509find.h
@@ -9,51 +9,43 @@
#define BOTAN_X509_CERT_STORE_SEARCH_H__
#include <botan/x509stor.h>
+#include <botan/bigint.h>
namespace Botan {
+namespace X509_Store_Search {
+
/*
* Search based on the contents of a DN entry
*/
-class BOTAN_DLL DN_Check : public X509_Store::Search_Func
- {
- public:
- typedef bool (*compare_fn)(const std::string&, const std::string&);
- enum Search_Type { SUBSTRING_MATCHING, IGNORE_CASE };
+enum DN_Search_Type { SUBSTRING_MATCHING, IGNORE_CASE };
- bool match(const X509_Certificate& cert) const;
+std::function<bool (const X509_Certificate&)>
+by_dn(const std::string& dn_entry,
+ const std::string& to_find,
+ DN_Search_Type method);
- DN_Check(const std::string&, const std::string&, compare_fn);
- DN_Check(const std::string&, const std::string&, Search_Type);
- private:
- std::string dn_entry, looking_for;
- compare_fn compare;
- };
+std::function<bool (const X509_Certificate&)>
+by_dn(const std::string& dn_entry,
+ const std::string& to_find,
+ std::function<bool (std::string, std::string)> method);
-/*
-* Search for a certificate by issuer/serial
+/**
+* Search for certs by issuer + serial number
*/
-class BOTAN_DLL IandS_Match : public X509_Store::Search_Func
- {
- public:
- bool match(const X509_Certificate& cert) const;
- IandS_Match(const X509_DN&, const MemoryRegion<byte>&);
- private:
- X509_DN issuer;
- MemoryVector<byte> serial;
- };
+std::function<bool (const X509_Certificate&)>
+by_issuer_and_serial(const X509_DN& issuer, const MemoryRegion<byte>& serial);
-/*
-* Search for a certificate by subject keyid
+std::function<bool (const X509_Certificate&)>
+by_issuer_and_serial(const X509_DN& issuer, const BigInt& serial);
+
+/**
+* Search for certs by subject key identifier
*/
-class BOTAN_DLL SKID_Match : public X509_Store::Search_Func
- {
- public:
- bool match(const X509_Certificate& cert) const;
- SKID_Match(const MemoryRegion<byte>& s) : skid(s) {}
- private:
- MemoryVector<byte> skid;
- };
+std::function<bool (const X509_Certificate&)>
+by_skid(const MemoryRegion<byte>& subject_key_id);
+
+}
}
diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp
index 0702ebf19..8d235ad5d 100644
--- a/src/cert/x509/x509opt.cpp
+++ b/src/cert/x509/x509opt.cpp
@@ -8,7 +8,7 @@
#include <botan/x509self.h>
#include <botan/oids.h>
#include <botan/parsing.h>
-#include <botan/time.h>
+#include <chrono>
namespace Botan {
@@ -78,16 +78,16 @@ void X509_Cert_Options::sanity_check() const
* Initialize the certificate options
*/
X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts,
- u32bit expiration_time_in_seconds)
+ u32bit expiration_time)
{
is_CA = false;
path_limit = 0;
constraints = NO_CONSTRAINTS;
- const u64bit now = system_time();
+ auto now = std::chrono::system_clock::now();
start = X509_Time(now);
- end = X509_Time(now + expiration_time_in_seconds);
+ end = X509_Time(now + std::chrono::seconds(expiration_time));
if(initial_opts == "")
return;
diff --git a/src/cert/x509/x509self.cpp b/src/cert/x509/x509self.cpp
index 89b63c8b2..1f647f8bb 100644
--- a/src/cert/x509/x509self.cpp
+++ b/src/cert/x509/x509self.cpp
@@ -68,7 +68,7 @@ X509_Certificate create_self_signed_cert(const X509_Cert_Options& opts,
AlternativeName subject_alt;
MemoryVector<byte> pub_key = shared_setup(opts, key);
- std::auto_ptr<PK_Signer> signer(choose_sig_format(key, hash_fn, sig_algo));
+ std::unique_ptr<PK_Signer> signer(choose_sig_format(key, hash_fn, sig_algo));
load_info(opts, subject_dn, subject_alt);
Key_Constraints constraints;
@@ -107,7 +107,7 @@ PKCS10_Request create_cert_req(const X509_Cert_Options& opts,
AlternativeName subject_alt;
MemoryVector<byte> pub_key = shared_setup(opts, key);
- std::auto_ptr<PK_Signer> signer(choose_sig_format(key, hash_fn, sig_algo));
+ std::unique_ptr<PK_Signer> signer(choose_sig_format(key, hash_fn, sig_algo));
load_info(opts, subject_dn, subject_alt);
const u32bit PKCS10_VERSION = 0;
diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp
index a24d4a070..6b2c0eee0 100644
--- a/src/cert/x509/x509stor.cpp
+++ b/src/cert/x509/x509stor.cpp
@@ -9,8 +9,8 @@
#include <botan/parsing.h>
#include <botan/pubkey.h>
#include <botan/oids.h>
-#include <botan/time.h>
#include <algorithm>
+#include <chrono>
#include <memory>
namespace Botan {
@@ -21,13 +21,14 @@ namespace {
* Do a validity check
*/
s32bit validity_check(const X509_Time& start, const X509_Time& end,
- u64bit current_time, u32bit slack)
+ const std::chrono::system_clock::time_point& now,
+ std::chrono::seconds slack)
{
const s32bit NOT_YET_VALID = -1, VALID_TIME = 0, EXPIRED = 1;
- if(start.cmp(current_time + slack) > 0)
+ if(start.cmp(now + slack) > 0)
return NOT_YET_VALID;
- if(end.cmp(current_time - slack) < 0)
+ if(end.cmp(now - slack) < 0)
return EXPIRED;
return VALID_TIME;
}
@@ -168,7 +169,8 @@ bool X509_Store::CRL_Data::operator<(const X509_Store::CRL_Data& other) const
/*
* X509_Store Constructor
*/
-X509_Store::X509_Store(u32bit slack, u32bit cache_timeout)
+X509_Store::X509_Store(std::chrono::seconds slack,
+ std::chrono::seconds cache_timeout)
{
revoked_info_valid = true;
@@ -211,10 +213,11 @@ X509_Code X509_Store::validate_cert(const X509_Certificate& cert,
if(chaining_result != VERIFIED)
return chaining_result;
- const u64bit current_time = system_time();
+ auto current_time = std::chrono::system_clock::now();
s32bit time_check = validity_check(cert.start_time(), cert.end_time(),
current_time, time_slack);
+
if(time_check < 0) return CERT_NOT_YET_VALID;
else if(time_check > 0) return CERT_HAS_EXPIRED;
@@ -379,7 +382,7 @@ X509_Code X509_Store::check_sig(const Cert_Info& cert_info,
*/
X509_Code X509_Store::check_sig(const X509_Object& object, Public_Key* key)
{
- std::auto_ptr<Public_Key> pub_key(key);
+ std::unique_ptr<Public_Key> pub_key(key);
try {
std::vector<std::string> sig_info =
@@ -450,12 +453,12 @@ bool X509_Store::is_revoked(const X509_Certificate& cert) const
* Retrieve all the certificates in the store
*/
std::vector<X509_Certificate>
-X509_Store::get_certs(const Search_Func& search) const
+X509_Store::get_certs(std::function<bool (const X509_Certificate&)> pred) const
{
std::vector<X509_Certificate> found_certs;
for(u32bit j = 0; j != certs.size(); ++j)
{
- if(search.match(certs[j].cert))
+ if(pred(certs[j].cert))
found_certs.push_back(certs[j].cert);
}
return found_certs;
@@ -549,8 +552,10 @@ void X509_Store::add_trusted_certs(DataSource& source)
*/
X509_Code X509_Store::add_crl(const X509_CRL& crl)
{
+ auto current_time = std::chrono::system_clock::now();
+
s32bit time_check = validity_check(crl.this_update(), crl.next_update(),
- system_time(), time_slack);
+ current_time, time_slack);
if(time_check < 0) return CRL_NOT_YET_VALID;
else if(time_check > 0) return CRL_HAS_EXPIRED;
@@ -589,8 +594,7 @@ X509_Code X509_Store::add_crl(const X509_CRL& crl)
revoked_info.serial = revoked_certs[j].serial_number();
revoked_info.auth_key_id = crl.authority_key_id();
- std::vector<CRL_Data>::iterator p =
- std::find(revoked.begin(), revoked.end(), revoked_info);
+ auto p = std::find(revoked.begin(), revoked.end(), revoked_info);
if(revoked_certs[j].reason_code() == REMOVE_FROM_CRL)
{
@@ -628,8 +632,8 @@ X509_Store::Cert_Info::Cert_Info(const X509_Certificate& c,
bool t) : cert(c), trusted(t)
{
checked = false;
+ last_checked = std::chrono::system_clock::time_point::min();
result = UNKNOWN_X509_ERROR;
- last_checked = 0;
}
/*
@@ -647,9 +651,9 @@ X509_Code X509_Store::Cert_Info::verify_result() const
*/
void X509_Store::Cert_Info::set_result(X509_Code code) const
{
- result = code;
- last_checked = system_time();
checked = true;
+ last_checked = std::chrono::system_clock::now();
+ result = code;
}
/*
@@ -663,16 +667,16 @@ bool X509_Store::Cert_Info::is_trusted() const
/*
* Check if this certificate has been verified
*/
-bool X509_Store::Cert_Info::is_verified(u32bit timeout) const
+bool X509_Store::Cert_Info::is_verified(std::chrono::seconds timeout) const
{
if(!checked)
return false;
if(result != VERIFIED && result != CERT_NOT_YET_VALID)
return true;
- const u64bit current_time = system_time();
+ auto now = std::chrono::system_clock::now();
- if(current_time > last_checked + timeout)
+ if(now > last_checked + timeout)
checked = false;
return checked;
diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h
index 4e6037883..1911c6b6a 100644
--- a/src/cert/x509/x509stor.h
+++ b/src/cert/x509/x509stor.h
@@ -11,6 +11,7 @@
#include <botan/x509cert.h>
#include <botan/x509_crl.h>
#include <botan/certstor.h>
+#include <functional>
namespace Botan {
@@ -48,13 +49,6 @@ enum X509_Code {
class BOTAN_DLL X509_Store
{
public:
- class BOTAN_DLL Search_Func
- {
- public:
- virtual bool match(const X509_Certificate&) const = 0;
- virtual ~Search_Func() {}
- };
-
enum Cert_Usage {
ANY = 0x00,
TLS_SERVER = 0x01,
@@ -67,7 +61,13 @@ class BOTAN_DLL X509_Store
X509_Code validate_cert(const X509_Certificate&, Cert_Usage = ANY);
- std::vector<X509_Certificate> get_certs(const Search_Func&) const;
+ /**
+ * @param match the matching function
+ * @return list of certs for which match returns true
+ */
+ std::vector<X509_Certificate>
+ get_certs(std::function<bool (const X509_Certificate&)> match) const;
+
std::vector<X509_Certificate> get_cert_chain(const X509_Certificate&);
std::string PEM_encode() const;
@@ -94,18 +94,22 @@ class BOTAN_DLL X509_Store
static X509_Code check_sig(const X509_Object&, Public_Key*);
- X509_Store(u32bit time_slack = 24*60*60,
- u32bit cache_results = 30*60);
+ X509_Store& operator=(const X509_Store&) = delete;
+
+ /**
+ * @param slack the slack in checking validity times against current clock
+ * @param cache how long to cache validation results before rechecking
+ */
+ X509_Store(std::chrono::seconds slack = std::chrono::seconds(24*60*60),
+ std::chrono::seconds cache = std::chrono::seconds(30*60));
X509_Store(const X509_Store&);
~X509_Store();
private:
- X509_Store& operator=(const X509_Store&) { return (*this); }
-
class BOTAN_DLL Cert_Info
{
public:
- bool is_verified(u32bit timeout) const;
+ bool is_verified(std::chrono::seconds cache_timeout) const;
bool is_trusted() const;
X509_Code verify_result() const;
void set_result(X509_Code) const;
@@ -116,7 +120,7 @@ class BOTAN_DLL X509_Store
private:
mutable bool checked;
mutable X509_Code result;
- mutable u64bit last_checked;
+ mutable std::chrono::system_clock::time_point last_checked;
};
u32bit find_cert(const X509_DN&, const MemoryRegion<byte>&) const;
@@ -131,10 +135,12 @@ class BOTAN_DLL X509_Store
bool is_revoked(const X509_Certificate&) const;
static const u32bit NO_CERT_FOUND = 0xFFFFFFFF;
+
std::vector<Cert_Info> certs;
std::vector<CRL_Data> revoked;
std::vector<Certificate_Store*> stores;
- u32bit time_slack, validation_cache_timeout;
+
+ std::chrono::seconds time_slack, validation_cache_timeout;
mutable bool revoked_info_valid;
};
diff --git a/src/cms/cms_dalg.cpp b/src/cms/cms_dalg.cpp
index 50a2397e5..2a380b596 100644
--- a/src/cms/cms_dalg.cpp
+++ b/src/cms/cms_dalg.cpp
@@ -51,10 +51,11 @@ std::vector<X509_Certificate> get_cert(BER_Decoder& signer_info,
iands.decode(issuer);
iands.decode(serial);
- found = store.get_certs(IandS_Match(issuer, BigInt::encode(serial)));
+ found = store.get_certs(
+ X509_Store_Search::by_issuer_and_serial(issuer, serial));
}
else if(id.type_tag == 0 && id.class_tag == CONSTRUCTED)
- found = store.get_certs(SKID_Match(id.value));
+ found = store.get_certs(X509_Store_Search::by_skid(id.value));
else
throw Decoding_Error("CMS: Unknown tag for cert identifier");
diff --git a/src/engine/openssl/arc4_openssl.cpp b/src/engine/openssl/arc4_openssl.cpp
index d76bce349..fcb39f9e6 100644
--- a/src/engine/openssl/arc4_openssl.cpp
+++ b/src/engine/openssl/arc4_openssl.cpp
@@ -40,7 +40,7 @@ std::string ARC4_OpenSSL::name() const
{
if(SKIP == 0) return "ARC4";
if(SKIP == 256) return "MARK-4";
- else return "RC4_skip(" + to_string(SKIP) + ")";
+ else return "RC4_skip(" + std::to_string(SKIP) + ")";
}
/*
diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp
index e1b4928df..5725cb154 100644
--- a/src/entropy/hres_timer/hres_timer.cpp
+++ b/src/entropy/hres_timer/hres_timer.cpp
@@ -7,9 +7,8 @@
#include <botan/internal/hres_timer.h>
#include <botan/cpuid.h>
-#include <botan/time.h>
-#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER)
#include <windows.h>
#endif
@@ -20,8 +19,7 @@ namespace Botan {
*/
void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum)
{
- // If Windows, grab the Performance Counter (usually TSC or PIT)
-#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER)
LARGE_INTEGER tv;
::QueryPerformanceCounter(&tv);
accum.add(tv.QuadPart, 0);
diff --git a/src/filters/data_snk.h b/src/filters/data_snk.h
index 61ddf6e0d..fda06e492 100644
--- a/src/filters/data_snk.h
+++ b/src/filters/data_snk.h
@@ -22,9 +22,9 @@ class BOTAN_DLL DataSink : public Filter
bool attachable() { return false; }
DataSink() {}
virtual ~DataSink() {}
- private:
- DataSink& operator=(const DataSink&) { return (*this); }
- DataSink(const DataSink&);
+
+ DataSink& operator=(const DataSink&) = delete;
+ DataSink(const DataSink&) = delete;
};
/**
diff --git a/src/filters/data_src.h b/src/filters/data_src.h
index e16217e0f..dea46584c 100644
--- a/src/filters/data_src.h
+++ b/src/filters/data_src.h
@@ -78,9 +78,8 @@ class BOTAN_DLL DataSource
DataSource() {}
virtual ~DataSource() {}
- private:
- DataSource& operator=(const DataSource&) { return (*this); }
- DataSource(const DataSource&);
+ DataSource& operator=(const DataSource&) = delete;
+ DataSource(const DataSource&) = delete;
};
/**
diff --git a/src/filters/filter.h b/src/filters/filter.h
index b13a36650..8fc114db7 100644
--- a/src/filters/filter.h
+++ b/src/filters/filter.h
@@ -19,6 +19,8 @@ namespace Botan {
class BOTAN_DLL Filter
{
public:
+ friend class Pipe;
+ friend class Fanout_Filter;
/**
* Write a portion of a message to this filter.
@@ -56,6 +58,9 @@ class BOTAN_DLL Filter
*/
void finish_msg();
+ Filter(const Filter&) = delete;
+ Filter& operator=(const Filter&) = delete;
+
virtual ~Filter() {}
protected:
void send(const byte[], u32bit);
@@ -63,12 +68,6 @@ class BOTAN_DLL Filter
void send(const MemoryRegion<byte>& in) { send(in.begin(), in.size()); }
Filter();
private:
- Filter(const Filter&) {}
- Filter& operator=(const Filter&) { return (*this); }
-
- friend class Pipe;
- friend class Fanout_Filter;
-
u32bit total_ports() const;
u32bit current_port() const { return port_num; }
void set_port(u32bit);
diff --git a/src/filters/hex/hex.cpp b/src/filters/hex/hex.cpp
index 651899b73..56576a8a0 100644
--- a/src/filters/hex/hex.cpp
+++ b/src/filters/hex/hex.cpp
@@ -141,7 +141,7 @@ void Hex_Decoder::handle_bad_char(byte c)
return;
throw Decoding_Error("Hex_Decoder: Invalid hex character: " +
- to_string(c));
+ std::to_string(c));
}
/*
diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp
index 778d47484..ff1714b81 100644
--- a/src/filters/modes/cfb/cfb.cpp
+++ b/src/filters/modes/cfb/cfb.cpp
@@ -26,7 +26,7 @@ CFB_Encryption::CFB_Encryption(BlockCipher* ciph, u32bit fback_bits)
if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
- to_string(fback_bits));
+ std::to_string(fback_bits));
}
/*
@@ -46,7 +46,7 @@ CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
- to_string(fback_bits));
+ std::to_string(fback_bits));
set_key(key);
set_iv(iv);
@@ -103,7 +103,7 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph, u32bit fback_bits)
if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
- to_string(fback_bits));
+ std::to_string(fback_bits));
}
/*
@@ -123,7 +123,7 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
- to_string(fback_bits));
+ std::to_string(fback_bits));
set_key(key);
set_iv(iv);
diff --git a/src/filters/modes/eax/eax.cpp b/src/filters/modes/eax/eax.cpp
index 2cb700daa..ee3b9f8e7 100644
--- a/src/filters/modes/eax/eax.cpp
+++ b/src/filters/modes/eax/eax.cpp
@@ -45,7 +45,7 @@ EAX_Base::EAX_Base(BlockCipher* cipher, u32bit tag_size) :
ctr = new CTR_BE(cipher); // takes ownership
if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > cmac->OUTPUT_LENGTH)
- throw Invalid_Argument(name() + ": Bad tag size " + to_string(tag_size));
+ throw Invalid_Argument(name() + ": Bad tag size " + std::to_string(tag_size));
}
/*
diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp
index 77e4ae283..2e8bc8d10 100644
--- a/src/filters/pipe.cpp
+++ b/src/filters/pipe.cpp
@@ -41,11 +41,12 @@ Pipe::Pipe(Filter* f1, Filter* f2, Filter* f3, Filter* f4)
/*
* Pipe Constructor
*/
-Pipe::Pipe(Filter* filter_array[], u32bit count)
+Pipe::Pipe(std::initializer_list<Filter*> args)
{
init();
- for(u32bit j = 0; j != count; ++j)
- append(filter_array[j]);
+
+ for(auto i = args.begin(); i != args.end(); ++i)
+ append(*i);
}
/*
diff --git a/src/filters/pipe.h b/src/filters/pipe.h
index 9af21a13f..a927e1a0f 100644
--- a/src/filters/pipe.h
+++ b/src/filters/pipe.h
@@ -11,6 +11,7 @@
#include <botan/data_src.h>
#include <botan/filter.h>
#include <botan/exceptn.h>
+#include <initializer_list>
#include <iosfwd>
namespace Botan {
@@ -32,7 +33,7 @@ class BOTAN_DLL Pipe : public DataSource
{
Invalid_Message_Number(const std::string& where, message_id msg) :
Invalid_Argument("Pipe::" + where + ": Invalid message number " +
- to_string(msg))
+ std::to_string(msg))
{}
};
@@ -240,15 +241,16 @@ class BOTAN_DLL Pipe : public DataSource
Pipe(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0);
/**
- * Construct a Pipe from range of filters passed as an array
+ * Construct a Pipe from a list of filters
* @param filters the set of filters to use
- * @param count the number of elements in filters
*/
- Pipe(Filter* filters[], u32bit count);
+ Pipe(std::initializer_list<Filter*> filters);
+
+ Pipe(const Pipe&) = delete;
+ Pipe& operator=(const Pipe&) = delete;
+
~Pipe();
private:
- Pipe(const Pipe&) : DataSource() {}
- Pipe& operator=(const Pipe&) { return (*this); }
void init();
void destruct(Filter*);
void find_endpoints(Filter*);
diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp
index 0ba3f5a4f..fdd028f58 100644
--- a/src/hash/par_hash/par_hash.cpp
+++ b/src/hash/par_hash/par_hash.cpp
@@ -1,6 +1,6 @@
/*
* Parallel
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -18,8 +18,8 @@ u32bit sum_of_hash_lengths(const std::vector<HashFunction*>& hashes)
{
u32bit sum = 0;
- for(u32bit j = 0; j != hashes.size(); ++j)
- sum += hashes[j]->OUTPUT_LENGTH;
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ sum += (*hash)->OUTPUT_LENGTH;
return sum;
}
@@ -31,20 +31,21 @@ u32bit sum_of_hash_lengths(const std::vector<HashFunction*>& hashes)
*/
void Parallel::add_data(const byte input[], u32bit length)
{
- for(u32bit j = 0; j != hashes.size(); ++j)
- hashes[j]->update(input, length);
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ (*hash)->update(input, length);
}
/*
* Finalize the hash
*/
-void Parallel::final_result(byte hash[])
+void Parallel::final_result(byte out[])
{
u32bit offset = 0;
- for(u32bit j = 0; j != hashes.size(); ++j)
+
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
{
- hashes[j]->final(hash + offset);
- offset += hashes[j]->OUTPUT_LENGTH;
+ (*hash)->final(out + offset);
+ offset += (*hash)->OUTPUT_LENGTH;
}
}
@@ -54,12 +55,14 @@ void Parallel::final_result(byte hash[])
std::string Parallel::name() const
{
std::string hash_names;
- for(u32bit j = 0; j != hashes.size(); ++j)
+
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
{
- if(j)
+ if(hash != hashes.begin())
hash_names += ',';
- hash_names += hashes[j]->name();
+ hash_names += (*hash)->name();
}
+
return "Parallel(" + hash_names + ")";
}
@@ -69,8 +72,10 @@ std::string Parallel::name() const
HashFunction* Parallel::clone() const
{
std::vector<HashFunction*> hash_copies;
- for(u32bit j = 0; j != hashes.size(); ++j)
- hash_copies.push_back(hashes[j]->clone());
+
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ hash_copies.push_back((*hash)->clone());
+
return new Parallel(hash_copies);
}
@@ -79,8 +84,8 @@ HashFunction* Parallel::clone() const
*/
void Parallel::clear()
{
- for(u32bit j = 0; j != hashes.size(); ++j)
- hashes[j]->clear();
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ (*hash)->clear();
}
/*
@@ -96,8 +101,8 @@ Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
*/
Parallel::~Parallel()
{
- for(u32bit j = 0; j != hashes.size(); ++j)
- delete hashes[j];
+ for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ delete (*hash);
}
}
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index cb4b7a7a2..869257567 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -176,7 +176,7 @@ Skein_512::Skein_512(u32bit arg_output_bits,
std::string Skein_512::name() const
{
- return "Skein-512(" + to_string(output_bits) + ")";
+ return "Skein-512(" + std::to_string(output_bits) + ")";
}
HashFunction* Skein_512::clone() const
diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp
index 3013ab38e..42df69eae 100644
--- a/src/hash/tiger/tiger.cpp
+++ b/src/hash/tiger/tiger.cpp
@@ -147,7 +147,7 @@ void Tiger::clear()
*/
std::string Tiger::name() const
{
- return "Tiger(" + to_string(OUTPUT_LENGTH) + "," + to_string(PASS) + ")";
+ return "Tiger(" + std::to_string(OUTPUT_LENGTH) + "," + std::to_string(PASS) + ")";
}
/*
@@ -158,10 +158,10 @@ Tiger::Tiger(u32bit hashlen, u32bit pass) :
{
if(OUTPUT_LENGTH != 16 && OUTPUT_LENGTH != 20 && OUTPUT_LENGTH != 24)
throw Invalid_Argument("Tiger: Illegal hash output size: " +
- to_string(OUTPUT_LENGTH));
+ std::to_string(OUTPUT_LENGTH));
if(PASS < 3)
throw Invalid_Argument("Tiger: Invalid number of passes: "
- + to_string(PASS));
+ + std::to_string(PASS));
clear();
}
diff --git a/src/libstate/info.txt b/src/libstate/info.txt
index 3992d25bd..f50b7f3dc 100644
--- a/src/libstate/info.txt
+++ b/src/libstate/info.txt
@@ -32,8 +32,6 @@ hash
kdf
mac
mode_pad
-mutex
-noop_mutex
pk_pad
pubkey
rng
diff --git a/src/libstate/init.cpp b/src/libstate/init.cpp
index b908de6c7..0d9a2420c 100644
--- a/src/libstate/init.cpp
+++ b/src/libstate/init.cpp
@@ -1,12 +1,11 @@
/**
* Default Initialization Function
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/init.h>
-#include <botan/parsing.h>
#include <botan/libstate.h>
namespace Botan {
@@ -14,36 +13,8 @@ namespace Botan {
/*
* Library Initialization
*/
-void LibraryInitializer::initialize(const std::string& arg_string)
+void LibraryInitializer::initialize(const std::string&)
{
- bool thread_safe = false;
-
- const std::vector<std::string> arg_list = split_on(arg_string, ' ');
- for(u32bit j = 0; j != arg_list.size(); ++j)
- {
- if(arg_list[j].size() == 0)
- continue;
-
- std::string name, value;
-
- if(arg_list[j].find('=') == std::string::npos)
- {
- name = arg_list[j];
- value = "true";
- }
- else
- {
- std::vector<std::string> name_and_value = split_on(arg_list[j], '=');
- name = name_and_value[0];
- value = name_and_value[1];
- }
-
- bool is_on =
- (value == "1" || value == "true" || value == "yes" || value == "on");
-
- if(name == "thread_safe")
- thread_safe = is_on;
- }
try
{
@@ -55,7 +26,7 @@ void LibraryInitializer::initialize(const std::string& arg_string)
*/
set_global_state(new Library_State);
- global_state().initialize(thread_safe);
+ global_state().initialize();
}
catch(...)
{
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index 919b12494..fccedacdf 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -6,13 +6,9 @@
*/
#include <botan/libstate.h>
-#include <botan/charset.h>
-#include <botan/engine.h>
#include <botan/init.h>
#include <botan/internal/defalloc.h>
#include <botan/internal/default_engine.h>
-#include <botan/internal/mutex.h>
-#include <botan/internal/mux_noop.h>
#include <botan/internal/stl_util.h>
#include <algorithm>
@@ -20,14 +16,6 @@
#include <botan/selftest.h>
#endif
-#if defined(BOTAN_HAS_MUTEX_PTHREAD)
- #include <botan/internal/mux_pthr.h>
-#elif defined(BOTAN_HAS_MUTEX_WIN32)
- #include <botan/internal/mux_win32.h>
-#elif defined(BOTAN_HAS_MUTEX_QT)
- #include <botan/internal/mux_qt.h>
-#endif
-
#if defined(BOTAN_HAS_ALLOC_MMAP)
#include <botan/internal/mmap_mem.h>
#endif
@@ -94,25 +82,17 @@ void set_global_state(Library_State* new_state)
*/
Library_State* swap_global_state(Library_State* new_state)
{
- Library_State* old_state = global_lib_state;
+ auto old_state = global_lib_state;
global_lib_state = new_state;
return old_state;
}
/*
-* Get a new mutex object
-*/
-Mutex* Library_State::get_mutex() const
- {
- return mutex_factory->make();
- }
-
-/*
* Get an allocator by its name
*/
-Allocator* Library_State::get_allocator(const std::string& type) const
+Allocator* Library_State::get_allocator(const std::string& type)
{
- Mutex_Holder lock(allocator_lock);
+ std::lock_guard<std::mutex> lock(allocator_lock);
if(type != "")
return search_map<std::string, Allocator*>(alloc_factory, type, 0);
@@ -136,7 +116,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const
*/
void Library_State::add_allocator(Allocator* allocator)
{
- Mutex_Holder lock(allocator_lock);
+ std::lock_guard<std::mutex> lock(allocator_lock);
allocator->init();
@@ -149,11 +129,11 @@ void Library_State::add_allocator(Allocator* allocator)
*/
void Library_State::set_default_allocator(const std::string& type)
{
- Mutex_Holder lock(allocator_lock);
-
if(type == "")
return;
+ std::lock_guard<std::mutex> lock(allocator_lock);
+
this->set("conf", "base/default_allocator", type);
cached_default_allocator = 0;
}
@@ -162,9 +142,9 @@ void Library_State::set_default_allocator(const std::string& type)
* Get a configuration value
*/
std::string Library_State::get(const std::string& section,
- const std::string& key) const
+ const std::string& key)
{
- Mutex_Holder lock(config_lock);
+ std::lock_guard<std::mutex> lock(config_lock);
return search_map<std::string, std::string>(config,
section + "/" + key, "");
@@ -174,9 +154,9 @@ std::string Library_State::get(const std::string& section,
* See if a particular option has been set
*/
bool Library_State::is_set(const std::string& section,
- const std::string& key) const
+ const std::string& key)
{
- Mutex_Holder lock(config_lock);
+ std::lock_guard<std::mutex> lock(config_lock);
return search_map(config, section + "/" + key, false, true);
}
@@ -187,12 +167,11 @@ bool Library_State::is_set(const std::string& section,
void Library_State::set(const std::string& section, const std::string& key,
const std::string& value, bool overwrite)
{
- Mutex_Holder lock(config_lock);
+ std::lock_guard<std::mutex> lock(config_lock);
std::string full_key = section + "/" + key;
- std::map<std::string, std::string>::const_iterator i =
- config.find(full_key);
+ auto i = config.find(full_key);
if(overwrite || i == config.end() || i->second == "")
config[full_key] = value;
@@ -209,7 +188,7 @@ void Library_State::add_alias(const std::string& key, const std::string& value)
/*
* Dereference an alias to a fixed name
*/
-std::string Library_State::deref_alias(const std::string& key) const
+std::string Library_State::deref_alias(const std::string& key)
{
std::string result = key;
while(is_set("alias", result))
@@ -229,7 +208,7 @@ void Library_State::set_option(const std::string& key,
/*
* Get an option value
*/
-std::string Library_State::option(const std::string& key) const
+std::string Library_State::option(const std::string& key)
{
return get("conf", key);
}
@@ -247,73 +226,54 @@ Algorithm_Factory& Library_State::algorithm_factory()
/*
* Load a set of modules
*/
-void Library_State::initialize(bool thread_safe)
+void Library_State::initialize()
{
- if(mutex_factory)
+ if(m_algorithm_factory)
throw Invalid_State("Library_State has already been initialized");
- if(!thread_safe)
- {
- mutex_factory = new Noop_Mutex_Factory;
- }
- else
- {
-#if defined(BOTAN_HAS_MUTEX_PTHREAD)
- mutex_factory = new Pthread_Mutex_Factory;
-#elif defined(BOTAN_HAS_MUTEX_WIN32)
- mutex_factory = new Win32_Mutex_Factory;
-#elif defined(BOTAN_HAS_MUTEX_QT)
- mutex_factory Qt_Mutex_Factory;
-#else
- throw Invalid_State("Could not find a thread-safe mutex object to use");
-#endif
- }
-
- allocator_lock = mutex_factory->make();
- config_lock = mutex_factory->make();
-
cached_default_allocator = 0;
add_allocator(new Malloc_Allocator);
- add_allocator(new Locking_Allocator(mutex_factory->make()));
+ add_allocator(new Locking_Allocator);
#if defined(BOTAN_HAS_ALLOC_MMAP)
- add_allocator(new MemoryMapping_Allocator(mutex_factory->make()));
+ add_allocator(new MemoryMapping_Allocator);
#endif
set_default_allocator("locking");
load_default_config();
- std::vector<Engine*> engines;
+ std::vector<Engine*> engines = {
#if defined(BOTAN_HAS_ENGINE_GNU_MP)
- engines.push_back(new GMP_Engine);
+ new GMP_Engine,
#endif
#if defined(BOTAN_HAS_ENGINE_OPENSSL)
- engines.push_back(new OpenSSL_Engine);
+ new OpenSSL_Engine,
#endif
#if defined(BOTAN_HAS_ENGINE_AES_ISA)
- engines.push_back(new AES_ISA_Engine);
+ new AES_ISA_Engine,
#endif
#if defined(BOTAN_HAS_ENGINE_SIMD)
- engines.push_back(new SIMD_Engine);
+ new SIMD_Engine,
#endif
#if defined(BOTAN_HAS_ENGINE_AMD64_ASSEMBLER)
- engines.push_back(new AMD64_Assembler_Engine);
+ new AMD64_Assembler_Engine,
#endif
#if defined(BOTAN_HAS_ENGINE_IA32_ASSEMBLER)
- engines.push_back(new IA32_Assembler_Engine);
+ new IA32_Assembler_Engine,
#endif
- engines.push_back(new Default_Engine);
+ new Default_Engine
+ };
- m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory);
+ m_algorithm_factory = new Algorithm_Factory(engines);
#if defined(BOTAN_HAS_SELFTESTS)
confirm_startup_self_tests(algorithm_factory());
@@ -325,8 +285,6 @@ void Library_State::initialize(bool thread_safe)
*/
Library_State::Library_State()
{
- mutex_factory = 0;
- allocator_lock = config_lock = 0;
cached_default_allocator = 0;
m_algorithm_factory = 0;
}
@@ -337,6 +295,7 @@ Library_State::Library_State()
Library_State::~Library_State()
{
delete m_algorithm_factory;
+ m_algorithm_factory = 0;
cached_default_allocator = 0;
@@ -345,10 +304,6 @@ Library_State::~Library_State()
allocators[j]->destroy();
delete allocators[j];
}
-
- delete allocator_lock;
- delete mutex_factory;
- delete config_lock;
}
}
diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h
index d5c442214..5a84f9cb1 100644
--- a/src/libstate/libstate.h
+++ b/src/libstate/libstate.h
@@ -12,14 +12,13 @@
#include <botan/allocate.h>
#include <botan/algo_factory.h>
+#include <mutex>
#include <string>
#include <vector>
#include <map>
namespace Botan {
-class Mutex;
-
/*
* Global State Container Base
*/
@@ -29,7 +28,10 @@ class BOTAN_DLL Library_State
Library_State();
~Library_State();
- void initialize(bool thread_safe);
+ Library_State(const Library_State&) = delete;
+ Library_State& operator=(const Library_State&) = delete;
+
+ void initialize();
/**
* @return the global Algorithm_Factory
@@ -40,7 +42,7 @@ class BOTAN_DLL Library_State
* @param name the name of the allocator
* @return allocator matching this name, or NULL
*/
- Allocator* get_allocator(const std::string& name = "") const;
+ Allocator* get_allocator(const std::string& name = "");
/**
* Add a new allocator to the list of available ones
@@ -61,7 +63,7 @@ class BOTAN_DLL Library_State
* @result the value of the parameter
*/
std::string get(const std::string& section,
- const std::string& key) const;
+ const std::string& key);
/**
* Check whether a certain parameter is set
@@ -72,7 +74,7 @@ class BOTAN_DLL Library_State
* false otherwise
*/
bool is_set(const std::string& section,
- const std::string& key) const;
+ const std::string& key);
/**
* Set a configuration parameter.
@@ -92,7 +94,7 @@ class BOTAN_DLL Library_State
* referred to as option).
* @param key the desired keys name
*/
- std::string option(const std::string& key) const;
+ std::string option(const std::string& key);
/**
* Set an option.
@@ -115,24 +117,14 @@ class BOTAN_DLL Library_State
* @param alias the alias to resolve.
* @return what the alias stands for
*/
- std::string deref_alias(const std::string& alias) const;
-
- /**
- * @return a newly created Mutex (free with delete)
- */
- Mutex* get_mutex() const;
+ std::string deref_alias(const std::string&);
private:
void load_default_config();
- Library_State(const Library_State&) {}
- Library_State& operator=(const Library_State&) { return (*this); }
-
- class Mutex_Factory* mutex_factory;
-
+ std::mutex config_lock;
std::map<std::string, std::string> config;
- Mutex* config_lock;
- Mutex* allocator_lock;
+ std::mutex allocator_lock;
std::map<std::string, Allocator*> alloc_factory;
mutable Allocator* cached_default_allocator;
std::vector<Allocator*> allocators;
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index 09ac2a75d..b92cd359e 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -40,7 +40,7 @@ BigInt::BigInt(Sign s, u32bit size)
}
/*
-* Construct a BigInt from a "raw" BigInt
+* Copy constructor
*/
BigInt::BigInt(const BigInt& b)
{
@@ -100,6 +100,25 @@ BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits)
randomize(rng, bits);
}
+/**
+* Move constructor
+*/
+BigInt::BigInt(BigInt&& other)
+ {
+ std::swap(*this, other);
+ }
+
+/**
+* Move assignment
+*/
+BigInt& BigInt::operator=(BigInt&& other)
+ {
+ if(this != &other)
+ std::swap(*this, other);
+
+ return (*this);
+ }
+
/*
* Swap this BigInt with another
*/
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index 55ccf7aae..2612850c3 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -425,10 +425,14 @@ class BOTAN_DLL BigInt
BigInt(u64bit n);
/**
- * Copy-Constructor: clone given BigInt
- * @param bigint the BigInt to clone
+ * Copy constructor
*/
- BigInt(const BigInt& bigint);
+ BigInt(const BigInt& other);
+
+ /**
+ * Assignment operator
+ */
+ BigInt& operator=(const BigInt&) = default;
/**
* Create BigInt from a string.
@@ -471,6 +475,15 @@ class BOTAN_DLL BigInt
*/
BigInt(NumberType type, u32bit n);
+ /**
+ * Move constructor
+ */
+ BigInt(BigInt&& other);
+
+ /**
+ * Move assignment
+ */
+ BigInt& operator=(BigInt&& other);
private:
SecureVector<word> reg;
Sign signedness;
diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp
index 83646e50e..39a7cf5fa 100644
--- a/src/math/numbertheory/dsa_gen.cpp
+++ b/src/math/numbertheory/dsa_gen.cpp
@@ -47,15 +47,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
if(!fips186_3_valid_size(pbits, qbits))
throw Invalid_Argument(
"FIPS 186-3 does not allow DSA domain parameters of " +
- to_string(pbits) + "/" + to_string(qbits) + " bits long");
+ std::to_string(pbits) + "/" + std::to_string(qbits) + " bits long");
if(seed_c.size() * 8 < qbits)
throw Invalid_Argument(
- "Generating a DSA parameter set with a " + to_string(qbits) +
+ "Generating a DSA parameter set with a " + std::to_string(qbits) +
"long q requires a seed at least as many bits long");
- std::auto_ptr<HashFunction> hash(
- af.make_hash_function("SHA-" + to_string(qbits)));
+ std::unique_ptr<HashFunction> hash(
+ af.make_hash_function("SHA-" + std::to_string(qbits)));
const u32bit HASH_SIZE = hash->OUTPUT_LENGTH;
diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp
index 61d42634a..23b8cf549 100644
--- a/src/math/numbertheory/make_prm.cpp
+++ b/src/math/numbertheory/make_prm.cpp
@@ -20,7 +20,7 @@ BigInt random_prime(RandomNumberGenerator& rng,
{
if(bits <= 1)
throw Invalid_Argument("random_prime: Can't make a prime of " +
- to_string(bits) + " bits");
+ std::to_string(bits) + " bits");
else if(bits == 2)
return ((rng.next_byte() % 2) ? 2 : 3);
else if(bits == 3)
@@ -88,7 +88,7 @@ BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits)
{
if(bits <= 64)
throw Invalid_Argument("random_safe_prime: Can't make a prime of " +
- to_string(bits) + " bits");
+ std::to_string(bits) + " bits");
BigInt p;
do
diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp
index e4c52323e..f79fdec2b 100644
--- a/src/math/numbertheory/numthry.cpp
+++ b/src/math/numbertheory/numthry.cpp
@@ -77,7 +77,7 @@ u32bit miller_rabin_test_iterations(u32bit bits, bool verify)
{
struct mapping { u32bit bits; u32bit verify_iter; u32bit check_iter; };
- static const mapping tests[] = {
+ const mapping tests[] = {
{ 50, 55, 25 },
{ 100, 38, 22 },
{ 160, 32, 18 },
diff --git a/src/mutex/info.txt b/src/mutex/info.txt
deleted file mode 100644
index af4cf9bb3..000000000
--- a/src/mutex/info.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-define MUTEX_WRAPPERS
-
-<header:internal>
-mutex.h
-</header:internal>
diff --git a/src/mutex/mutex.h b/src/mutex/mutex.h
deleted file mode 100644
index fcb0e9982..000000000
--- a/src/mutex/mutex.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-* Mutex
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MUTEX_H__
-#define BOTAN_MUTEX_H__
-
-#include <botan/exceptn.h>
-
-namespace Botan {
-
-/*
-* Mutex Base Class
-*/
-class Mutex
- {
- public:
- virtual void lock() = 0;
- virtual void unlock() = 0;
- virtual ~Mutex() {}
- };
-
-/*
-* Mutex Factory
-*/
-class Mutex_Factory
- {
- public:
- virtual Mutex* make() = 0;
- virtual ~Mutex_Factory() {}
- };
-
-/*
-* Mutex Holding Class
-*/
-class Mutex_Holder
- {
- public:
- Mutex_Holder(Mutex* m) : mux(m)
- {
- if(!mux)
- throw Invalid_Argument("Mutex_Holder: Argument was NULL");
- mux->lock();
- }
-
- ~Mutex_Holder() { mux->unlock(); }
- private:
- Mutex* mux;
- };
-
-}
-
-#endif
diff --git a/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt
deleted file mode 100644
index 16670b1dd..000000000
--- a/src/mutex/noop_mutex/info.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-define MUTEX_NOOP
-
-<source>
-mux_noop.cpp
-</source>
-
-<header:internal>
-mux_noop.h
-</header:internal>
diff --git a/src/mutex/noop_mutex/mux_noop.cpp b/src/mutex/noop_mutex/mux_noop.cpp
deleted file mode 100644
index 18151274a..000000000
--- a/src/mutex/noop_mutex/mux_noop.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-* No-Op Mutex Factory
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/internal/mux_noop.h>
-
-namespace Botan {
-
-/*
-* No-Op Mutex Factory
-*/
-Mutex* Noop_Mutex_Factory::make()
- {
- class Noop_Mutex : public Mutex
- {
- public:
- class Mutex_State_Error : public Internal_Error
- {
- public:
- Mutex_State_Error(const std::string& where) :
- Internal_Error("Noop_Mutex::" + where + ": " +
- "Mutex is already " + where + "ed") {}
- };
-
- void lock()
- {
- if(locked)
- throw Mutex_State_Error("lock");
- locked = true;
- }
-
- void unlock()
- {
- if(!locked)
- throw Mutex_State_Error("unlock");
- locked = false;
- }
-
- Noop_Mutex() { locked = false; }
- private:
- bool locked;
- };
-
- return new Noop_Mutex;
- }
-
-}
diff --git a/src/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h
deleted file mode 100644
index a1bd57858..000000000
--- a/src/mutex/noop_mutex/mux_noop.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* No-Op Mutex Factory
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__
-#define BOTAN_NOOP_MUTEX_FACTORY_H__
-
-#include <botan/internal/mutex.h>
-
-namespace Botan {
-
-/*
-* No-Op Mutex Factory
-*/
-class Noop_Mutex_Factory : public Mutex_Factory
- {
- public:
- Mutex* make();
- };
-
-}
-
-#endif
diff --git a/src/mutex/pthreads/info.txt b/src/mutex/pthreads/info.txt
deleted file mode 100644
index 1d826b61c..000000000
--- a/src/mutex/pthreads/info.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-define MUTEX_PTHREAD
-
-<source>
-mux_pthr.cpp
-</source>
-
-<header:internal>
-mux_pthr.h
-</header:internal>
-
-<libs>
-all!qnx,freebsd,dragonfly,openbsd,netbsd -> pthread
-</libs>
-
-<os>
-aix
-cygwin
-darwin
-freebsd
-dragonfly
-hpux
-irix
-linux
-netbsd
-openbsd
-qnx
-solaris
-tru64
-</os>
diff --git a/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp
deleted file mode 100644
index 165132239..000000000
--- a/src/mutex/pthreads/mux_pthr.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-* Pthread Mutex
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/internal/mux_pthr.h>
-#include <botan/exceptn.h>
-
-#ifndef _POSIX_C_SOURCE
- #define _POSIX_C_SOURCE 199506
-#endif
-
-#include <pthread.h>
-
-namespace Botan {
-
-/*
-* Pthread Mutex Factory
-*/
-Mutex* Pthread_Mutex_Factory::make()
- {
-
- class Pthread_Mutex : public Mutex
- {
- public:
- void lock()
- {
- if(pthread_mutex_lock(&mutex) != 0)
- throw Invalid_State("Pthread_Mutex::lock: Error occured");
- }
-
- void unlock()
- {
- if(pthread_mutex_unlock(&mutex) != 0)
- throw Invalid_State("Pthread_Mutex::unlock: Error occured");
- }
-
- Pthread_Mutex()
- {
- if(pthread_mutex_init(&mutex, 0) != 0)
- throw Invalid_State("Pthread_Mutex: initialization failed");
- }
-
- ~Pthread_Mutex()
- {
- if(pthread_mutex_destroy(&mutex) != 0)
- throw Invalid_State("~Pthread_Mutex: mutex is still locked");
- }
- private:
- pthread_mutex_t mutex;
- };
-
- return new Pthread_Mutex();
- }
-
-}
diff --git a/src/mutex/pthreads/mux_pthr.h b/src/mutex/pthreads/mux_pthr.h
deleted file mode 100644
index 27b854265..000000000
--- a/src/mutex/pthreads/mux_pthr.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* Pthread Mutex
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MUTEX_PTHREAD_H__
-#define BOTAN_MUTEX_PTHREAD_H__
-
-#include <botan/internal/mutex.h>
-
-namespace Botan {
-
-/*
-* Pthread Mutex Factory
-*/
-class Pthread_Mutex_Factory : public Mutex_Factory
- {
- public:
- Mutex* make();
- };
-
-}
-
-#endif
diff --git a/src/mutex/qt_mutex/info.txt b/src/mutex/qt_mutex/info.txt
deleted file mode 100644
index 7b014f886..000000000
--- a/src/mutex/qt_mutex/info.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-define MUTEX_QT
-
-load_on request
-
-<source>
-mux_qt.cpp
-</source>
-
-<header:internal>
-mux_qt.h
-</header:internal>
-
-# I think we want to always use qt-mt, not qt -- not much point in supporting
-# mutexes in a single threaded application, after all.
-<libs>
-all -> qt-mt
-</libs>
diff --git a/src/mutex/qt_mutex/mux_qt.cpp b/src/mutex/qt_mutex/mux_qt.cpp
deleted file mode 100644
index da4e5ce5c..000000000
--- a/src/mutex/qt_mutex/mux_qt.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-* Qt Thread Mutex
-* (C) 2004-2007 Justin Karneges
-* 2004-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/internal/mux_qt.h>
-#include <qmutex.h>
-
-#if !defined(QT_THREAD_SUPPORT)
- #error Your version of Qt does not support threads or mutexes
-#endif
-
-namespace Botan {
-
-/*
-* Qt Mutex Factory
-*/
-Mutex* Qt_Mutex_Factory::make()
- {
- class Qt_Mutex : public Mutex
- {
- public:
- void lock() { mutex.lock(); }
- void unlock() { mutex.unlock(); }
- private:
- QMutex mutex;
- };
-
- return new Qt_Mutex();
- }
-
-}
diff --git a/src/mutex/qt_mutex/mux_qt.h b/src/mutex/qt_mutex/mux_qt.h
deleted file mode 100644
index cb396b81d..000000000
--- a/src/mutex/qt_mutex/mux_qt.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-* Qt Mutex
-* (C) 2004-2007 Justin Karneges
-* 2004-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MUTEX_QT_H__
-#define BOTAN_MUTEX_QT_H__
-
-#include <botan/internal/mutex.h>
-
-namespace Botan {
-
-/*
-* Qt Mutex
-*/
-class Qt_Mutex_Factory : public Mutex_Factory
- {
- public:
- Mutex* make();
- };
-
-}
-
-#endif
diff --git a/src/mutex/win32_crit_section/info.txt b/src/mutex/win32_crit_section/info.txt
deleted file mode 100644
index d90b8b64b..000000000
--- a/src/mutex/win32_crit_section/info.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-define MUTEX_WIN32
-
-<source>
-mux_win32.cpp
-</source>
-
-<header:internal>
-mux_win32.h
-</header:internal>
-
-<os>
-cygwin
-windows
-mingw
-</os>
diff --git a/src/mutex/win32_crit_section/mux_win32.cpp b/src/mutex/win32_crit_section/mux_win32.cpp
deleted file mode 100644
index fa6051798..000000000
--- a/src/mutex/win32_crit_section/mux_win32.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-* Win32 Mutex
-* (C) 2006 Luca Piccarreta
-* 2006-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/internal/mux_win32.h>
-#include <windows.h>
-
-namespace Botan {
-
-/*
-* Win32 Mutex Factory
-*/
-Mutex* Win32_Mutex_Factory::make()
- {
- class Win32_Mutex : public Mutex
- {
- public:
- void lock() { EnterCriticalSection(&mutex); }
- void unlock() { LeaveCriticalSection(&mutex); }
-
- Win32_Mutex() { InitializeCriticalSection(&mutex); }
- ~Win32_Mutex() { DeleteCriticalSection(&mutex); }
- private:
- CRITICAL_SECTION mutex;
- };
-
- return new Win32_Mutex();
- }
-
-}
diff --git a/src/mutex/win32_crit_section/mux_win32.h b/src/mutex/win32_crit_section/mux_win32.h
deleted file mode 100644
index 4bbf6a540..000000000
--- a/src/mutex/win32_crit_section/mux_win32.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* Win32 Mutex
-* (C) 2006 Luca Piccarreta
-* 2006-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MUTEX_WIN32_H__
-#define BOTAN_MUTEX_WIN32_H__
-
-#include <botan/internal/mutex.h>
-
-namespace Botan {
-
-/*
-* Win32 Mutex Factory
-*/
-class Win32_Mutex_Factory : public Mutex_Factory
- {
- public:
- Mutex* make();
- };
-}
-
-#endif
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index 7940e69b2..55a83794c 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -46,7 +46,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng,
PrimeType type, u32bit pbits, u32bit qbits)
{
if(pbits < 512)
- throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) +
+ throw Invalid_Argument("DL_Group: prime size " + std::to_string(pbits) +
" is too small");
if(type == Strong)
@@ -237,7 +237,7 @@ SecureVector<byte> DL_Group::DER_encode(Format format) const
.get_contents();
}
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
}
/*
@@ -253,7 +253,7 @@ std::string DL_Group::PEM_encode(Format format) const
else if(format == ANSI_X9_42)
return PEM_Code::encode(encoding, "X942 DH PARAMETERS");
else
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
}
/*
@@ -287,7 +287,7 @@ void DL_Group::BER_decode(DataSource& source, Format format)
.discard_remaining();
}
else
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
initialize(new_p, new_q, new_g);
}
diff --git a/src/pubkey/pkcs8.cpp b/src/pubkey/pkcs8.cpp
index 400fdbb48..d3a62aa01 100644
--- a/src/pubkey/pkcs8.cpp
+++ b/src/pubkey/pkcs8.cpp
@@ -89,7 +89,7 @@ SecureVector<byte> PKCS8_decode(DataSource& source, const User_Interface& ui,
if(is_encrypted)
{
DataSource_Memory params(pbe_alg_id.parameters);
- std::auto_ptr<PBE> pbe(get_pbe(pbe_alg_id.oid, params));
+ std::unique_ptr<PBE> pbe(get_pbe(pbe_alg_id.oid, params));
User_Interface::UI_Result result = User_Interface::OK;
const std::string passphrase =
@@ -171,7 +171,7 @@ void encrypt_key(const Private_Key& key,
encode(key, raw_key, RAW_BER);
raw_key.end_msg();
- std::auto_ptr<PBE> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE)));
+ std::unique_ptr<PBE> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE)));
pbe->new_params(rng);
pbe->set_key(pass);
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 4a9f1be9d..751f20583 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -226,7 +226,7 @@ SecureVector<byte> PK_Signer::signature(RandomNumberGenerator& rng)
}
else
throw Encoding_Error("PK_Signer: Unknown signature format " +
- to_string(sig_format));
+ std::to_string(sig_format));
}
/*
@@ -313,7 +313,7 @@ bool PK_Verifier::check_signature(const byte sig[], u32bit length)
}
else
throw Decoding_Error("PK_Verifier: Unknown signature format " +
- to_string(sig_format));
+ std::to_string(sig_format));
}
catch(Invalid_Argument) { return false; }
}
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index b278ade52..200e92821 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -20,7 +20,7 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
{
if(bits < 512)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
- to_string(bits) + " bits long");
+ std::to_string(bits) + " bits long");
if(exp < 3 || exp % 2 == 0)
throw Invalid_Argument(algo_name() + ": Invalid encryption exponent");
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index 508244112..9600ae709 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -21,7 +21,7 @@ RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng,
{
if(bits < 512)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
- to_string(bits) + " bits long");
+ std::to_string(bits) + " bits long");
if(exp < 2 || exp % 2 == 1)
throw Invalid_Argument(algo_name() + ": Invalid encryption exponent");
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index 84a7b1c13..97200c481 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -8,7 +8,6 @@
#include <botan/hmac_rng.h>
#include <botan/get_byte.h>
#include <botan/internal/xor_buf.h>
-#include <botan/internal/stl_util.h>
#include <algorithm>
namespace Botan {
@@ -213,8 +212,8 @@ HMAC_RNG::~HMAC_RNG()
delete extractor;
delete prf;
- std::for_each(entropy_sources.begin(), entropy_sources.end(),
- del_fun<EntropySource>());
+ for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)
+ delete *i;
counter = 0;
}
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index 9a4d77e55..c58378b32 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -8,8 +8,8 @@
#include <botan/randpool.h>
#include <botan/get_byte.h>
#include <botan/internal/xor_buf.h>
-#include <botan/internal/stl_util.h>
#include <algorithm>
+#include <chrono>
namespace Botan {
@@ -202,8 +202,8 @@ Randpool::~Randpool()
delete cipher;
delete mac;
- std::for_each(entropy_sources.begin(), entropy_sources.end(),
- del_fun<EntropySource>());
+ for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)
+ delete *i;
}
}
diff --git a/src/s2k/s2k.h b/src/s2k/s2k.h
index 055ef8911..db59a5fe8 100644
--- a/src/s2k/s2k.h
+++ b/src/s2k/s2k.h
@@ -51,9 +51,9 @@ class BOTAN_DLL S2K
S2K() {}
virtual ~S2K() {}
- private:
- S2K(const S2K&) {}
- S2K& operator=(const S2K&) { return (*this); }
+
+ S2K(const S2K&) = delete;
+ S2K& operator=(const S2K&) = delete;
};
}
diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp
index 215569cbb..a11accbd3 100644
--- a/src/selftest/selftest.cpp
+++ b/src/selftest/selftest.cpp
@@ -116,8 +116,7 @@ namespace {
void verify_results(const std::string& algo,
const std::map<std::string, bool>& results)
{
- for(std::map<std::string, bool>::const_iterator i = results.begin();
- i != results.end(); ++i)
+ for(auto i = results.begin(); i != results.end(); ++i)
{
if(!i->second)
throw Self_Test_Failure(algo + " self-test failed, provider "+
diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp
index 258b4ec17..842b2698c 100644
--- a/src/ssl/rec_wri.cpp
+++ b/src/ssl/rec_wri.cpp
@@ -250,7 +250,7 @@ void Record_Writer::send_record(byte type, byte major, byte minor,
*/
void Record_Writer::alert(Alert_Level level, Alert_Type type)
{
- byte alert[2] = { level, type };
+ byte alert[2] = { (byte)level, (byte)type };
send(ALERT, alert, sizeof(alert));
flush();
}
diff --git a/src/ssl/tls_suites.cpp b/src/ssl/tls_suites.cpp
index 26fa75428..a168dac0a 100644
--- a/src/ssl/tls_suites.cpp
+++ b/src/ssl/tls_suites.cpp
@@ -51,7 +51,7 @@ CipherSuite::CipherSuite(u16bit suite_code)
if(suite_string == "")
throw Invalid_Argument("Unknown ciphersuite: " +
- to_string(suite_code));
+ std::to_string(suite_code));
std::vector<std::string> suite_info = split_on(suite_string, '/');
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp
index 1c89379ba..705b77062 100644
--- a/src/stream/arc4/arc4.cpp
+++ b/src/stream/arc4/arc4.cpp
@@ -81,7 +81,7 @@ std::string ARC4::name() const
{
if(SKIP == 0) return "ARC4";
if(SKIP == 256) return "MARK-4";
- else return "RC4_skip(" + to_string(SKIP) + ")";
+ else return "RC4_skip(" + std::to_string(SKIP) + ")";
}
/*
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 7ee626fda..516d0a16b 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>
@@ -22,22 +23,10 @@ namespace Botan {
class BOTAN_DLL Data_Store
{
public:
- 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 5e264b916..2ac88aaf6 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 18c8b149b..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>
@@ -53,25 +37,6 @@ inline R search_map(const std::map<K, V>& mapping, const K& key,
}
/*
-* 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 0dbbd5e9c..bc9aa8a2f 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;
@@ -67,20 +67,13 @@ 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 bc571120b..44ec704a4 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 {
@@ -29,16 +29,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
* @returns 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 d540864b2..ef591b4d7 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());
}
/*