From 99e8c1a20700631103ec20386f8080eeee4df588 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 15:43:27 +0000 Subject: Remove the mutex classes in favor of C++0x's std::mutex and std::lock_guard --- src/libstate/init.cpp | 35 ++-------------------- src/libstate/libstate.cpp | 76 +++++++++++------------------------------------ src/libstate/libstate.h | 21 ++++++------- 3 files changed, 29 insertions(+), 103 deletions(-) (limited to 'src/libstate') 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 -#include #include 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 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 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 3275c6493..839d71d60 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,21 +9,12 @@ #include #include #include -#include #include #include #include #include #include -#if defined(BOTAN_HAS_MUTEX_PTHREAD) - #include -#elif defined(BOTAN_HAS_MUTEX_WIN32) - #include -#elif defined(BOTAN_HAS_MUTEX_QT) - #include -#endif - #if defined(BOTAN_HAS_ALLOC_MMAP) #include #endif @@ -91,20 +82,12 @@ Library_State* swap_global_state(Library_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 lock(allocator_lock); if(type != "") return search_map(alloc_factory, type, 0); @@ -128,7 +111,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 lock(allocator_lock); allocator->init(); @@ -141,7 +124,7 @@ void Library_State::add_allocator(Allocator* allocator) */ void Library_State::set_default_allocator(const std::string& type) { - Mutex_Holder lock(allocator_lock); + std::lock_guard lock(allocator_lock); if(type == "") return; @@ -154,9 +137,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 lock(config_lock); return search_map(config, section + "/" + key, ""); @@ -166,9 +149,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 lock(config_lock); return search_map(config, section + "/" + key, false, true); } @@ -179,7 +162,7 @@ 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 lock(config_lock); std::string full_key = section + "/" + key; @@ -201,7 +184,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)) @@ -221,7 +204,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); } @@ -239,38 +222,18 @@ 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"); @@ -301,7 +264,7 @@ void Library_State::initialize(bool thread_safe) engines.push_back(new Default_Engine); - m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory); + m_algorithm_factory = new Algorithm_Factory(engines); } /* @@ -309,8 +272,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; } @@ -321,6 +282,7 @@ Library_State::Library_State() Library_State::~Library_State() { delete m_algorithm_factory; + m_algorithm_factory = 0; cached_default_allocator = 0; @@ -329,10 +291,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 2493863a9..eb3b3b3be 100644 --- a/src/libstate/libstate.h +++ b/src/libstate/libstate.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -27,11 +28,11 @@ class BOTAN_DLL Library_State Library_State(); ~Library_State(); - void initialize(bool thread_safe); + void initialize(); Algorithm_Factory& algorithm_factory(); - Allocator* get_allocator(const std::string& = "") const; + Allocator* get_allocator(const std::string& = ""); void add_allocator(Allocator*); void set_default_allocator(const std::string&); @@ -42,7 +43,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 @@ -52,7 +53,7 @@ class BOTAN_DLL Library_State * @result true if the parameters value is set, * false otherwise */ - bool is_set(const std::string& section, const std::string& key) const; + bool is_set(const std::string& section, const std::string& key); /** * Set a configuration parameter. @@ -70,7 +71,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. @@ -91,21 +92,17 @@ class BOTAN_DLL Library_State * @param alias the alias to resolve. * @return what the alias stands for */ - std::string deref_alias(const std::string&) const; - - class 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 config; - class Mutex* config_lock; - class Mutex* allocator_lock; + std::mutex allocator_lock; std::map alloc_factory; mutable Allocator* cached_default_allocator; std::vector allocators; -- cgit v1.2.3 From cc8b60c7f5ea6be28848498367645cbccba035e8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 11 Sep 2009 19:26:44 +0000 Subject: Remove dep on mutex module (doesn't exist here). Use initializer list in libstate.cpp --- src/algo_factory/info.txt | 1 - src/alloc/mem_pool/info.txt | 4 ---- src/libstate/info.txt | 2 -- src/libstate/libstate.cpp | 22 +++++++++++----------- 4 files changed, 11 insertions(+), 18 deletions(-) (limited to 'src/libstate') diff --git a/src/algo_factory/info.txt b/src/algo_factory/info.txt index dfc42230a..fc248523d 100644 --- a/src/algo_factory/info.txt +++ b/src/algo_factory/info.txt @@ -16,6 +16,5 @@ block engine hash mac -mutex stream diff --git a/src/alloc/mem_pool/info.txt b/src/alloc/mem_pool/info.txt index 0a762ccc4..b1c7a091f 100644 --- a/src/alloc/mem_pool/info.txt +++ b/src/alloc/mem_pool/info.txt @@ -6,7 +6,3 @@ load_on auto mem_pool.cpp mem_pool.h - - -mutex - diff --git a/src/libstate/info.txt b/src/libstate/info.txt index 6eaa2f70b..fcf386e6d 100644 --- a/src/libstate/info.txt +++ b/src/libstate/info.txt @@ -34,8 +34,6 @@ hash kdf mac mode_pad -mutex -noop_mutex pk_pad pubkey rng diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 839d71d60..676c2a949 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +76,7 @@ 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; } @@ -124,11 +123,11 @@ void Library_State::add_allocator(Allocator* allocator) */ void Library_State::set_default_allocator(const std::string& type) { - std::lock_guard lock(allocator_lock); - if(type == "") return; + std::lock_guard lock(allocator_lock); + this->set("conf", "base/default_allocator", type); cached_default_allocator = 0; } @@ -240,29 +239,30 @@ void Library_State::initialize() load_default_config(); - std::vector engines; + std::vector 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_SSE2_ASSEMBLER) - engines.push_back(new SSE2_Assembler_Engine); + new SSE2_Assembler_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); } -- cgit v1.2.3 From 07cfdf3f06f35735483d4cdde9efdba558131337 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Oct 2009 19:49:13 +0000 Subject: Fixup post-merge breakage --- src/libstate/libstate.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libstate') diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 4d915973c..66e606880 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -85,7 +85,7 @@ Library_State* swap_global_state(Library_State* new_state) /* * 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) { std::lock_guard lock(allocator_lock); @@ -137,7 +137,7 @@ 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) { std::lock_guard lock(config_lock); @@ -149,7 +149,7 @@ 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) { std::lock_guard lock(config_lock); @@ -184,7 +184,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)) @@ -204,7 +204,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); } -- cgit v1.2.3 From 22a47e97f459337ff8c2b9fdcf68cb1514b19b34 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 16 Nov 2009 17:07:38 +0000 Subject: Use auto for long iterator names, etc. It will be nice to convert to the range-based for loop once that's available. --- src/algo_factory/algo_cache.h | 30 ++++++++++++------------------ src/algo_factory/algo_factory.cpp | 3 ++- src/alloc/mem_pool/mem_pool.cpp | 6 +++--- src/asn1/asn1_alt.cpp | 27 +++++++++++---------------- src/cert/x509/x509_ca.cpp | 6 +----- src/cert/x509/x509cert.cpp | 16 +++++----------- src/cert/x509/x509stor.cpp | 3 +-- src/libstate/libstate.cpp | 3 +-- src/rng/hmac_rng/hmac_rng.cpp | 5 ++--- src/rng/randpool/randpool.cpp | 5 ++--- src/selftest/selftest.cpp | 3 +-- src/utils/datastor/datastor.cpp | 7 ++----- src/utils/stl_util.h | 19 ------------------- 13 files changed, 43 insertions(+), 90 deletions(-) (limited to 'src/libstate') diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 4b264dcc1..09bbc4b5a 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -53,12 +53,8 @@ class Algorithm_Cache ~Algorithm_Cache(); private: - typedef typename std::map >::iterator - algorithms_iterator; - - typedef typename std::map::iterator provider_iterator; - - algorithms_iterator find_algorithm(const std::string& algo_spec); + typename std::map >::const_iterator + find_algorithm(const std::string& algo_spec); std::mutex mutex; std::map aliases; @@ -71,16 +67,15 @@ class Algorithm_Cache * Assumes object lock is held */ template -typename Algorithm_Cache::algorithms_iterator +typename std::map >::const_iterator Algorithm_Cache::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::const_iterator alias = - aliases.find(algo_spec); + auto alias = aliases.find(algo_spec); if(alias != aliases.end()) algo = algorithms.find(alias->second); @@ -98,14 +93,14 @@ const T* Algorithm_Cache::get(const std::string& algo_spec, { std::lock_guard 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::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); @@ -170,11 +165,10 @@ Algorithm_Cache::providers_of(const std::string& algo_name) std::vector 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()) { @@ -204,11 +198,11 @@ void Algorithm_Cache::set_preferred_provider(const std::string& algo_spec, template Algorithm_Cache::~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()) { diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp index 192d5ecdd..0b8422bcb 100644 --- a/src/algo_factory/algo_factory.cpp +++ b/src/algo_factory/algo_factory.cpp @@ -99,7 +99,8 @@ Algorithm_Factory::Algorithm_Factory(const std::vector& engines_in) */ Algorithm_Factory::~Algorithm_Factory() { - std::for_each(engines.begin(), engines.end(), del_fun()); + for(auto i = engines.begin(); i != engines.end(); ++i) + delete *i; delete block_cipher_cache; delete stream_cipher_cache; diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp index 02a12d6a5..820355678 100644 --- a/src/alloc/mem_pool/mem_pool.cpp +++ b/src/alloc/mem_pool/mem_pool.cpp @@ -190,8 +190,8 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n) { const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - std::vector::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"); @@ -208,7 +208,7 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n) if(blocks.empty()) return 0; - std::vector::iterator i = last_used; + auto i = last_used; do { diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp index 41974eef6..401eb54e9 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::iterator iter; - std::pair 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 AlternativeName::contents() const { std::multimap names; - typedef std::multimap::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::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& attr, const std::string& type, ASN1_Tag tagging) { - typedef std::multimap::const_iterator iter; + auto range = attr.equal_range(type); - std::pair 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::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/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index 3ba18e50e..6aba7e5a0 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -15,9 +15,6 @@ #include #include #include -#include -#include -#include #include #include @@ -175,8 +172,7 @@ X509_CRL X509_CA::update_crl(const X509_CRL& crl, for(u32bit j = 0; j != already_revoked.size(); ++j) { - std::set >::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]); diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp index ac5839fb6..9be645dce 100644 --- a/src/cert/x509/x509cert.cpp +++ b/src/cert/x509/x509cert.cpp @@ -27,12 +27,8 @@ std::vector lookup_oids(const std::vector& in) { std::vector out; - std::vector::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; } @@ -320,9 +316,8 @@ X509_DN create_dn(const Data_Store& info) X509_DN dn; - std::multimap::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; } @@ -356,9 +351,8 @@ AlternativeName create_alt_name(const Data_Store& info) AlternativeName alt_name; - std::multimap::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/x509stor.cpp b/src/cert/x509/x509stor.cpp index 364bbac7b..323890f2d 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -603,8 +603,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::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) { diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 80f694094..dd7fe7eaf 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -170,8 +170,7 @@ void Library_State::set(const std::string& section, const std::string& key, std::string full_key = section + "/" + key; - std::map::const_iterator i = - config.find(full_key); + auto i = config.find(full_key); if(overwrite || i == config.end() || i->second == "") config[full_key] = value; diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 9d5ee97e4..213373657 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include 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()); + 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 af1706466..b04da7358 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -208,8 +207,8 @@ Randpool::~Randpool() delete cipher; delete mac; - std::for_each(entropy_sources.begin(), entropy_sources.end(), - del_fun()); + for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i) + delete *i; } } diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp index 660be36e4..d5b184f8f 100644 --- a/src/selftest/selftest.cpp +++ b/src/selftest/selftest.cpp @@ -114,8 +114,7 @@ namespace { void verify_results(const std::string& algo, const std::map& results) { - for(std::map::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/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 129dad9bf..9f8ba2c24 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -65,12 +65,9 @@ Data_Store::search_with(const Matcher& matcher) const */ std::vector Data_Store::get(const std::string& looking_for) const { - typedef std::multimap::const_iterator iter; - - std::pair range = contents.equal_range(looking_for); - std::vector 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; } diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h index fc4d4effe..4cc081733 100644 --- a/src/utils/stl_util.h +++ b/src/utils/stl_util.h @@ -36,25 +36,6 @@ inline R search_map(const std::map& mapping, const K& key, return found_result; } -/* -* Function adaptor for delete operation -*/ -template -class del_fun : public std::unary_function - { - public: - void operator()(T* ptr) { delete ptr; } - }; - -/* -* Delete the second half of a pair of objects -*/ -template -void delete2nd(Pair& pair) - { - delete pair.second; - } - /* * Insert a key/value pair into a multimap */ -- cgit v1.2.3 From 49b20f4e4ff3b8e3141905871ccae9fc70e77a1d Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 16:25:51 +0000 Subject: Use the new support for explicitly deleting functions instead of hiding them as private variables for operator= and copy constructors that shouldn't be used. --- src/asn1/ber_dec.h | 4 ++-- src/block/block_cipher.h | 15 --------------- src/cert/x509/x509_ca.h | 6 +++--- src/cert/x509/x509stor.h | 4 ++-- src/filters/data_snk.h | 6 +++--- src/filters/data_src.h | 5 ++--- src/filters/filter.h | 11 +++++------ src/filters/pipe.h | 5 +++-- src/libstate/libstate.h | 6 +++--- src/s2k/s2k.h | 7 ++++--- 10 files changed, 27 insertions(+), 42 deletions(-) (limited to 'src/libstate') 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&, ASN1_Tag, u16bit); + BER_Decoder& operator=(const BER_Decoder&) = delete; + BER_Decoder(DataSource&); BER_Decoder(const byte[], u32bit); BER_Decoder(const MemoryRegion&); 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/block/block_cipher.h b/src/block/block_cipher.h index 1dcdde7c7..e97eebf0f 100644 --- a/src/block/block_cipher.h +++ b/src/block/block_cipher.h @@ -14,21 +14,6 @@ namespace Botan { /** * This class represents a block cipher object. -* -* It would be very useful to extend this interface to support the -* encryption of multiple blocks at a time. This could help -* performance, wrt cache effects in the software implementations, and -* could be a big deal when supporting block ciphers implemented as -* hardware devices. It could be used by implementations of ECB, and -* more importantly counter mode (which most designs are moving to, due -* to the parallelism possible in counter mode which is not the case -* with feedback-based modes like CBC). -* -* Probable future API here: -* virtual void encrypt_n(const byte in[], byte out[], -* u32bit blocks) const = 0; -* virtual void decrypt_n(const byte in[], byte out[], -* u32bit blocks) const = 0; */ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm { 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& entries, u32bit crl_number, u32bit next_update, RandomNumberGenerator& rng) const; diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h index ab31663ed..958b6da0f 100644 --- a/src/cert/x509/x509stor.h +++ b/src/cert/x509/x509stor.h @@ -94,14 +94,14 @@ class BOTAN_DLL X509_Store static X509_Code check_sig(const X509_Object&, Public_Key*); + X509_Store& operator=(const X509_Store&) = delete; + X509_Store(u32bit time_slack = 24*60*60, u32bit cache_results = 30*60); X509_Store(const X509_Store&); ~X509_Store(); private: - X509_Store& operator=(const X509_Store&) { return (*this); } - class BOTAN_DLL Cert_Info { public: 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& 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/pipe.h b/src/filters/pipe.h index 7cf7d6df2..58bb6d22a 100644 --- a/src/filters/pipe.h +++ b/src/filters/pipe.h @@ -244,10 +244,11 @@ class BOTAN_DLL Pipe : public DataSource */ Pipe(std::initializer_list 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/libstate/libstate.h b/src/libstate/libstate.h index 91fd58dff..e9a08b74b 100644 --- a/src/libstate/libstate.h +++ b/src/libstate/libstate.h @@ -28,6 +28,9 @@ class BOTAN_DLL Library_State Library_State(); ~Library_State(); + Library_State(const Library_State&) = delete; + Library_State& operator=(const Library_State&) = delete; + void initialize(); Algorithm_Factory& algorithm_factory(); @@ -96,9 +99,6 @@ class BOTAN_DLL Library_State private: void load_default_config(); - Library_State(const Library_State&) {} - Library_State& operator=(const Library_State&) { return (*this); } - std::mutex config_lock; std::map config; diff --git a/src/s2k/s2k.h b/src/s2k/s2k.h index 7af92519b..ca86ab77a 100644 --- a/src/s2k/s2k.h +++ b/src/s2k/s2k.h @@ -87,12 +87,13 @@ class BOTAN_DLL S2K S2K() { iter = 0; } virtual ~S2K() {} - private: - S2K(const S2K&) {} - S2K& operator=(const S2K&) { return (*this); } + S2K(const S2K&) = delete; + S2K& operator=(const S2K&) = delete; + private: virtual OctetString derive(u32bit, const std::string&, const byte[], u32bit, u32bit) const = 0; + SecureVector salt; u32bit iter; }; -- cgit v1.2.3 From 85b961ff87c1d6300451538c939c99a2ff74b505 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 16 Dec 2009 05:15:42 +0000 Subject: Post-merge fixes --- src/algo_factory/algo_cache.h | 2 +- src/libstate/libstate.cpp | 4 ++-- src/math/gfpmath/info.txt | 8 -------- src/pubkey/dsa/dsa_op.cpp | 2 +- src/pubkey/elgamal/elg_op.cpp | 2 +- src/pubkey/if_algo/if_op.cpp | 2 +- src/pubkey/nr/nr_op.cpp | 2 +- src/rng/hmac_rng/hmac_rng.cpp | 10 ---------- src/rng/randpool/randpool.cpp | 4 ++-- src/utils/info.txt | 1 + 10 files changed, 10 insertions(+), 27 deletions(-) (limited to 'src/libstate') diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 09bbc4b5a..bafea45e9 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -9,7 +9,7 @@ #define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ #include -#include +#include #include #include #include diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 06b05276f..1ca9415e5 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index 55ae8b5e6..b7b430805 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -7,15 +7,7 @@ gfp_modulus.h point_gfp.h -<<<<<<< variant A ->>>>>>> variant B - -####### Ancestor -define BIGINT_GFP - - -======= end curve_gfp.cpp gfp_element.cpp point_gfp.cpp diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 03eaebfb0..5eb9e92be 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index db828a300..49db44251 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 7974bf4f0..58618775b 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index 49aa9fc00..da104802d 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 00a3a27d0..84cd647b7 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -6,18 +6,8 @@ */ #include -<<<<<<< variant A #include #include -#include ->>>>>>> variant B -#include -#include -####### Ancestor -#include -#include -#include -======= end #include namespace Botan { diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index 18a3b49a0..015cac491 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -6,8 +6,8 @@ */ #include -#include -#include +#include +#include #include #include diff --git a/src/utils/info.txt b/src/utils/info.txt index edeeb1cf9..bbfcd34be 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -14,6 +14,7 @@ version.cpp +async.h bit_ops.h bswap.h loadstor.h -- cgit v1.2.3