From fd3016d10124d2b7ccd7bc885235f2e407d73800 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 31 Jan 2015 16:18:09 +0000 Subject: Use registry also for KDF, EMSA, and EME --- src/lib/algo_base/algo_registry.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/lib/algo_base/algo_registry.h') diff --git a/src/lib/algo_base/algo_registry.h b/src/lib/algo_base/algo_registry.h index 80eff47be..77ed3591f 100644 --- a/src/lib/algo_base/algo_registry.h +++ b/src/lib/algo_base/algo_registry.h @@ -38,6 +38,12 @@ class Algo_Registry m_maker_fns[name][provider] = fn; } + T* make(const std::string& spec_str) + { + const Spec spec(spec_str); + return make(spec_str, ""); + } + T* make(const Spec& spec, const std::string& provider = "") { maker_fn maker = find_maker(spec, provider); @@ -48,6 +54,7 @@ class Algo_Registry } catch(std::exception& e) { + //return nullptr; // ?? throw std::runtime_error("Creating '" + spec.as_string() + "' failed: " + e.what()); } } @@ -110,6 +117,19 @@ class Algo_Registry std::map> m_maker_fns; }; +template T* +make_a(const typename T::Spec& spec, const std::string provider = "") + { + return Algo_Registry::global_registry().make(spec, provider); + } + +template T* +make_a(const std::string& spec_str, const std::string provider = "") + { + typename T::Spec spec(spec_str); + return make_a(spec, provider); + } + template T* make_new_T(const typename Algo_Registry::Spec&) { return new T; } @@ -131,7 +151,22 @@ make_new_T_1str(const typename Algo_Registry::Spec& spec, const std::string& return new T(spec.arg(0, def)); } -#define BOTAN_REGISTER_NAMED_T(T, namestr, type, maker) \ +template T* +make_new_T_1str_req(const typename Algo_Registry::Spec& spec) + { + return new T(spec.arg(0)); + } + +template T* +make_new_T_1X(const typename Algo_Registry::Spec& spec) + { + std::unique_ptr x(Algo_Registry::global_registry().make(spec.arg(0))); + if(!x) + throw std::runtime_error(spec.arg(0)); + return new T(x.release()); + } + +#define BOTAN_REGISTER_NAMED_T(T, namestr, type, maker) \ namespace { Algo_Registry::Add g_ ## type ## _reg(namestr, maker); } #define BOTAN_REGISTER_T(T, name, maker) \ namespace { Algo_Registry::Add g_ ## name ## _reg(#name, maker); } -- cgit v1.2.3