diff options
Diffstat (limited to 'src/lib/hash/par_hash')
-rw-r--r-- | src/lib/hash/par_hash/par_hash.cpp | 28 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.h | 5 |
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() {} |