aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/par_hash
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-10-11 13:00:57 -0400
committerJack Lloyd <[email protected]>2016-10-21 16:53:16 -0400
commit558808900bffc3c48da5e6d79ba602e88e619154 (patch)
treefd76ee2d009c2b707d888683cbd767351c4ff6b3 /src/lib/hash/par_hash
parent6aa855bba613c7b6fedfbe71d15930964acb1633 (diff)
Remove Algo_Registry
I repent my use of global constructors. I repent my use of global locks. Hopefully I will never touch this code again. :)
Diffstat (limited to 'src/lib/hash/par_hash')
-rw-r--r--src/lib/hash/par_hash/par_hash.cpp28
-rw-r--r--src/lib/hash/par_hash/par_hash.h5
2 files changed, 7 insertions, 26 deletions
diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp
index f6bed96ee..7320afee3 100644
--- a/src/lib/hash/par_hash/par_hash.cpp
+++ b/src/lib/hash/par_hash/par_hash.cpp
@@ -10,23 +10,6 @@
namespace Botan {
-Parallel* Parallel::make(const Spec& spec)
- {
- std::vector<std::unique_ptr<HashFunction>> m_hashes;
-
- for(size_t i = 0; i != spec.arg_count(); ++i)
- {
- auto h = HashFunction::create(spec.arg(i));
- if(!h)
- return nullptr;
- m_hashes.push_back(std::move(h));
- }
-
- Parallel* p = new Parallel;
- std::swap(p->m_hashes, m_hashes);
- return p;
- }
-
void Parallel::add_data(const byte input[], size_t length)
{
for(auto&& hash : m_hashes)
@@ -65,10 +48,10 @@ std::string Parallel::name() const
HashFunction* Parallel::clone() const
{
- std::vector<HashFunction*> hash_copies;
+ std::vector<std::unique_ptr<HashFunction>> hash_copies;
for(auto&& hash : m_hashes)
- hash_copies.push_back(hash.get());
+ hash_copies.push_back(std::unique_ptr<HashFunction>(hash->clone()));
return new Parallel(hash_copies);
}
@@ -79,12 +62,11 @@ void Parallel::clear()
hash->clear();
}
-Parallel::Parallel(const std::vector<HashFunction*>& in)
+Parallel::Parallel(std::vector<std::unique_ptr<HashFunction>>& h)
{
- for(size_t i = 0; i != in.size(); ++i)
+ for(size_t i = 0; i != h.size(); ++i)
{
- std::unique_ptr<HashFunction> h(in[i]->clone());
- m_hashes.push_back(std::move(h));
+ m_hashes.push_back(std::unique_ptr<HashFunction>(h[i].release()));
}
}
diff --git a/src/lib/hash/par_hash/par_hash.h b/src/lib/hash/par_hash/par_hash.h
index 3a93f4e8e..67d026c2f 100644
--- a/src/lib/hash/par_hash/par_hash.h
+++ b/src/lib/hash/par_hash/par_hash.h
@@ -27,13 +27,12 @@ class BOTAN_DLL Parallel final : public HashFunction
/**
* @param hashes a set of hashes to compute in parallel
+ * Takes ownership of all pointers
*/
- explicit Parallel(const std::vector<HashFunction*>& hashes);
+ explicit Parallel(std::vector<std::unique_ptr<HashFunction>>& hashes);
Parallel(const Parallel&) = delete;
Parallel& operator=(const Parallel&) = delete;
-
- static Parallel* make(const Spec& spec);
private:
Parallel() {}