From e2e0f8f2b595122c1f8acb3b3a46501f96a2b218 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 17 Sep 2015 17:08:01 -0400 Subject: 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. --- src/lib/kdf/kdf.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/lib/kdf/kdf.cpp') diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp index 836e9b982..3eba8a5cd 100644 --- a/src/lib/kdf/kdf.cpp +++ b/src/lib/kdf/kdf.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #if defined(BOTAN_HAS_HKDF) #include @@ -32,10 +32,29 @@ #include #endif +#define BOTAN_REGISTER_KDF_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T)) +#define BOTAN_REGISTER_KDF_1HASH(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1X)) + +#define BOTAN_REGISTER_KDF_NAMED_1STR(type, name) \ + BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1str_req)) + namespace Botan { KDF::~KDF() {} +std::unique_ptr KDF::create(const std::string& algo_spec, + const std::string& provider) + { + return std::unique_ptr(make_a(algo_spec, provider)); + } + +std::vector KDF::providers(const std::string& algo_spec) + { + return providers_of(KDF::Spec(algo_spec)); + } + KDF* get_kdf(const std::string& algo_spec) { SCAN_Name request(algo_spec); @@ -43,9 +62,10 @@ KDF* get_kdf(const std::string& algo_spec) if(request.algo_name() == "Raw") return nullptr; // No KDF - if(KDF* kdf = make_a(algo_spec)) - return kdf; - throw Algorithm_Not_Found(algo_spec); + auto kdf = KDF::create(algo_spec); + if(!kdf) + throw Algorithm_Not_Found(algo_spec); + return kdf.release(); } #if defined(BOTAN_HAS_HKDF) -- cgit v1.2.3