diff options
author | Jack Lloyd <[email protected]> | 2015-09-17 17:08:01 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-09-17 17:08:01 -0400 |
commit | e2e0f8f2b595122c1f8acb3b3a46501f96a2b218 (patch) | |
tree | af5e031cb1f83fae45d59fc05c05185de1138f9a /src/lib/hash | |
parent | d83ef010522373a6f8ed3876c812b18b55513103 (diff) |
Handle dependencies re static linking. GH #279
Previously we were hanging on the type destructors to pull in
the relevant objects. However that fails in many simple cases
where the object is never deleted.
For every type involved in the algo registry add static create
and providers functions to access the algo registry. Modify
lookup.h to be inline and call those functions, and move
a few to sub-headers (eg, get_pbkdf going to pbkdf.h). So
accessing the registry involves going through the same file
that handles the initialization, so there is no way to end up
with missing objs.
Diffstat (limited to 'src/lib/hash')
-rw-r--r-- | src/lib/hash/comb4p/comb4p.cpp | 5 | ||||
-rw-r--r-- | src/lib/hash/hash.cpp | 13 | ||||
-rw-r--r-- | src/lib/hash/hash.h | 15 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.cpp | 2 |
4 files changed, 31 insertions, 4 deletions
diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp index ec39bbc31..ef5f74a38 100644 --- a/src/lib/hash/comb4p/comb4p.cpp +++ b/src/lib/hash/comb4p/comb4p.cpp @@ -5,7 +5,6 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/hash_utils.h> #include <botan/comb4p.h> #include <botan/internal/xor_buf.h> #include <stdexcept> @@ -39,8 +38,8 @@ Comb4P* Comb4P::make(const Spec& spec) { if(spec.arg_count() == 2) { - std::unique_ptr<HashFunction> h1(make_hash_function(spec.arg(0))); - std::unique_ptr<HashFunction> h2(make_hash_function(spec.arg(1))); + std::unique_ptr<HashFunction> h1(HashFunction::create(spec.arg(0))); + std::unique_ptr<HashFunction> h2(HashFunction::create(spec.arg(1))); if(h1 && h2) return new Comb4P(h1.release(), h2.release()); diff --git a/src/lib/hash/hash.cpp b/src/lib/hash/hash.cpp index 723a7eba7..f965cfde8 100644 --- a/src/lib/hash/hash.cpp +++ b/src/lib/hash/hash.cpp @@ -91,6 +91,19 @@ namespace Botan { +std::unique_ptr<HashFunction> HashFunction::create(const std::string& algo_spec, + const std::string& provider) + { + return std::unique_ptr<HashFunction>(make_a<HashFunction>(algo_spec, provider)); + } + +std::vector<std::string> HashFunction::providers(const std::string& algo_spec) + { + return providers_of<HashFunction>(HashFunction::Spec(algo_spec)); + } + +HashFunction::HashFunction() {} + HashFunction::~HashFunction() {} #if defined(BOTAN_HAS_ADLER32) diff --git a/src/lib/hash/hash.h b/src/lib/hash/hash.h index 8406a4c0f..76c9d5cd7 100644 --- a/src/lib/hash/hash.h +++ b/src/lib/hash/hash.h @@ -23,10 +23,25 @@ class BOTAN_DLL HashFunction : public Buffered_Computation typedef SCAN_Name Spec; /** + * Create an instance based on a name + * Will return a null pointer if the algo/provider combination cannot + * be found. If providers is empty then best available is chosen. + */ + static std::unique_ptr<HashFunction> create(const std::string& algo_spec, + const std::string& provider = ""); + + /** + * Returns the list of available providers for this algorithm, empty if not available + */ + static std::vector<std::string> providers(const std::string& algo_spec); + + /** * @return new object representing the same algorithm as *this */ virtual HashFunction* clone() const = 0; + HashFunction(); + virtual ~HashFunction(); virtual void clear() = 0; diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp index 12271640a..57140f0a8 100644 --- a/src/lib/hash/par_hash/par_hash.cpp +++ b/src/lib/hash/par_hash/par_hash.cpp @@ -17,7 +17,7 @@ Parallel* Parallel::make(const Spec& spec) for(size_t i = 0; i != spec.arg_count(); ++i) { - std::unique_ptr<HashFunction> h(get_hash_function(spec.arg(i))); + auto h = HashFunction::create(spec.arg(i)); if(!h) return nullptr; hashes.push_back(std::move(h)); |