aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-06-17 16:54:16 +0000
committerlloyd <[email protected]>2011-06-17 16:54:16 +0000
commitf799e57c35ff53136b0bbb7a40d44d7716db88a9 (patch)
tree4166a9694c990d667723088fcfe3fe63fef1dfd7 /src
parent98fc1399dd3e61784a08c7da76ab729be6a93aff (diff)
Add string_join; inverse of split_on.
Use auto in a few more places. Use GCC 4.6's range-for Delete rather than hide Algorithm copy constructor/assignment Move version to more or less randomly chosen 1.99 so there is no ambiguity about versions.
Diffstat (limited to 'src')
-rw-r--r--src/algo_base/algo_base.h7
-rw-r--r--src/filters/bzip2/bzip2.cpp2
-rw-r--r--src/filters/zlib/zlib.cpp2
-rw-r--r--src/hash/par_hash/par_hash.cpp40
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp4
-rw-r--r--src/utils/parsing.cpp17
-rw-r--r--src/utils/parsing.h9
-rw-r--r--src/utils/stl_util.h4
8 files changed, 54 insertions, 31 deletions
diff --git a/src/algo_base/algo_base.h b/src/algo_base/algo_base.h
index 813216a36..f757a9a83 100644
--- a/src/algo_base/algo_base.h
+++ b/src/algo_base/algo_base.h
@@ -19,7 +19,6 @@ namespace Botan {
class BOTAN_DLL Algorithm
{
public:
-
/**
* Zeroize internal state
*/
@@ -31,10 +30,10 @@ class BOTAN_DLL Algorithm
virtual std::string name() const = 0;
Algorithm() {}
+ Algorithm(const Algorithm&) = delete;
+ Algorithm& operator=(const Algorithm&) = delete;
+
virtual ~Algorithm() {}
- private:
- Algorithm(const Algorithm&) {}
- Algorithm& operator=(const Algorithm&) { return (*this); }
};
}
diff --git a/src/filters/bzip2/bzip2.cpp b/src/filters/bzip2/bzip2.cpp
index a291c1173..18a53558c 100644
--- a/src/filters/bzip2/bzip2.cpp
+++ b/src/filters/bzip2/bzip2.cpp
@@ -48,7 +48,7 @@ void* bzip_malloc(void* info_ptr, int n, int size)
void bzip_free(void* info_ptr, void* ptr)
{
Bzip_Alloc_Info* info = static_cast<Bzip_Alloc_Info*>(info_ptr);
- std::map<void*, size_t>::const_iterator i = info->current_allocs.find(ptr);
+ auto i = info->current_allocs.find(ptr);
if(i == info->current_allocs.end())
throw Invalid_Argument("bzip_free: Got pointer not allocated by us");
info->alloc->deallocate(ptr, i->second);
diff --git a/src/filters/zlib/zlib.cpp b/src/filters/zlib/zlib.cpp
index 0f88b5558..28d08df52 100644
--- a/src/filters/zlib/zlib.cpp
+++ b/src/filters/zlib/zlib.cpp
@@ -47,7 +47,7 @@ void* zlib_malloc(void* info_ptr, unsigned int n, unsigned int size)
void zlib_free(void* info_ptr, void* ptr)
{
Zlib_Alloc_Info* info = static_cast<Zlib_Alloc_Info*>(info_ptr);
- std::map<void*, size_t>::const_iterator i = info->current_allocs.find(ptr);
+ auto i = info->current_allocs.find(ptr);
if(i == info->current_allocs.end())
throw Invalid_Argument("zlib_free: Got pointer not allocated by us");
info->alloc->deallocate(ptr, i->second);
diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp
index a95ba36b9..df47780ef 100644
--- a/src/hash/par_hash/par_hash.cpp
+++ b/src/hash/par_hash/par_hash.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/par_hash.h>
+#include <botan/parsing.h>
namespace Botan {
@@ -14,8 +15,8 @@ namespace Botan {
*/
void Parallel::add_data(const byte input[], size_t length)
{
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
- (*hash)->update(input, length);
+ for(auto hash : hashes)
+ hash->update(input, length);
}
/*
@@ -25,10 +26,10 @@ void Parallel::final_result(byte out[])
{
u32bit offset = 0;
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
+ for(auto hash : hashes)
{
- (*hash)->final(out + offset);
- offset += (*hash)->output_length();
+ hash->final(out + offset);
+ offset += hash->output_length();
}
}
@@ -38,8 +39,9 @@ void Parallel::final_result(byte out[])
size_t Parallel::output_length() const
{
size_t sum = 0;
- for(size_t i = 0; i != hashes.size(); ++i)
- sum += hashes[i]->output_length();
+
+ for(auto hash : hashes)
+ sum += hash->output_length();
return sum;
}
@@ -48,16 +50,12 @@ size_t Parallel::output_length() const
*/
std::string Parallel::name() const
{
- std::string hash_names;
+ std::vector<std::string> names;
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
- {
- if(hash != hashes.begin())
- hash_names += ',';
- hash_names += (*hash)->name();
- }
+ for(auto hash : hashes)
+ names.push_back(hash->name());
- return "Parallel(" + hash_names + ")";
+ return "Parallel(" + string_join(names, ',') + ")";
}
/*
@@ -67,8 +65,8 @@ HashFunction* Parallel::clone() const
{
std::vector<HashFunction*> hash_copies;
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
- hash_copies.push_back((*hash)->clone());
+ for(auto hash : hashes)
+ hash_copies.push_back(hash->clone());
return new Parallel(hash_copies);
}
@@ -78,8 +76,8 @@ HashFunction* Parallel::clone() const
*/
void Parallel::clear()
{
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
- (*hash)->clear();
+ for(auto hash : hashes)
+ hash->clear();
}
/*
@@ -95,8 +93,8 @@ Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
*/
Parallel::~Parallel()
{
- for(auto hash = hashes.begin(); hash != hashes.end(); ++hash)
- delete (*hash);
+ for(auto hash : hashes)
+ delete hash;
}
}
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index 4f6a90565..6911a3af5 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -215,8 +215,8 @@ HMAC_RNG::~HMAC_RNG()
delete extractor;
delete prf;
- for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)
- delete *i;
+ for(auto src : entropy_sources)
+ delete src;
counter = 0;
}
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index ff0718bb0..f4f65dcb2 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -128,6 +128,23 @@ std::vector<std::string> split_on(const std::string& str, char delim)
}
/*
+* Join a string
+*/
+std::string string_join(const std::vector<std::string>& strs, char delim)
+ {
+ std::string out = "";
+
+ for(size_t i = 0; i != strs.size(); ++i)
+ {
+ if(i != 0)
+ out += delim;
+ out += strs[i];
+ }
+
+ return out;
+ }
+
+/*
* Parse an ASN.1 OID string
*/
std::vector<u32bit> parse_asn1_oid(const std::string& oid)
diff --git a/src/utils/parsing.h b/src/utils/parsing.h
index 98dcd82b5..2d53551bf 100644
--- a/src/utils/parsing.h
+++ b/src/utils/parsing.h
@@ -32,6 +32,15 @@ BOTAN_DLL std::vector<std::string> split_on(
const std::string& str, char delim);
/**
+* Join a string
+* @param strs strings to join
+* @param delim the delimitor
+* @return string joined by delim
+*/
+BOTAN_DLL std::string string_join(const std::vector<std::string>& strs,
+ char delim);
+
+/**
* Parse an ASN.1 OID
* @param oid the OID in string form
* @return OID components
diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h
index 0eb078244..6e85839a5 100644
--- a/src/utils/stl_util.h
+++ b/src/utils/stl_util.h
@@ -24,7 +24,7 @@ inline V search_map(const std::map<K, V>& mapping,
const K& key,
const V& null_result = V())
{
- typename std::map<K, V>::const_iterator i = mapping.find(key);
+ auto i = mapping.find(key);
if(i == mapping.end())
return null_result;
return i->second;
@@ -34,7 +34,7 @@ template<typename K, typename V, typename R>
inline R search_map(const std::map<K, V>& mapping, const K& key,
const R& null_result, const R& found_result)
{
- typename std::map<K, V>::const_iterator i = mapping.find(key);
+ auto i = mapping.find(key);
if(i == mapping.end())
return null_result;
return found_result;