5353#include " ../jrd/trace/TraceObjects.h"
5454#include " ../jrd/Collation.h"
5555#include " ../common/classes/FpeControl.h"
56- #include < functional>
5756#include < math.h>
5857
5958using namespace Firebird ;
@@ -106,16 +105,37 @@ struct HashAlgorithmDescriptor
106105{
107106 const char * name;
108107 USHORT length;
109- std::function< HashContext* (MemoryPool&)> create ;
108+ HashContext* (*create)( MemoryPool&);
110109
111110 static const HashAlgorithmDescriptor* find (const char * name);
112111};
113112
114- static const HashAlgorithmDescriptor hashAlgorithmDescriptors[] = {
115- {" MD5" , 16 , [](MemoryPool& pool) { return FB_NEW_POOL (pool) Md5HashContext (pool); }},
116- {" SHA1" , 20 , [](MemoryPool& pool) { return FB_NEW_POOL (pool) Sha1HashContext (pool); }},
117- {" SHA256" , 32 , [](MemoryPool& pool) { return FB_NEW_POOL (pool) Sha256HashContext (pool); }},
118- {" SHA512" , 64 , [](MemoryPool& pool) { return FB_NEW_POOL (pool) Sha512HashContext (pool); }}
113+ template <typename T>
114+ struct HashAlgorithmDescriptorFactory
115+ {
116+ static HashAlgorithmDescriptor* getInstance (const char * name, USHORT length)
117+ {
118+ desc.name = name;
119+ desc.length = length;
120+ desc.create = createContext;
121+ return &desc;
122+ }
123+
124+ static HashContext* createContext (MemoryPool& pool)
125+ {
126+ return FB_NEW_POOL (pool) T (pool);
127+ }
128+
129+ static HashAlgorithmDescriptor desc;
130+ };
131+
132+ template <typename T> HashAlgorithmDescriptor HashAlgorithmDescriptorFactory<T>::desc;
133+
134+ static const HashAlgorithmDescriptor* hashAlgorithmDescriptors[] = {
135+ HashAlgorithmDescriptorFactory<Md5HashContext>::getInstance (" MD5" , 16 ),
136+ HashAlgorithmDescriptorFactory<Sha1HashContext>::getInstance (" SHA1" , 20 ),
137+ HashAlgorithmDescriptorFactory<Sha256HashContext>::getInstance (" SHA256" , 32 ),
138+ HashAlgorithmDescriptorFactory<Sha512HashContext>::getInstance (" SHA512" , 64 )
119139};
120140
121141const HashAlgorithmDescriptor* HashAlgorithmDescriptor::find (const char * name)
@@ -124,8 +144,8 @@ const HashAlgorithmDescriptor* HashAlgorithmDescriptor::find(const char* name)
124144
125145 for (unsigned i = 0 ; i < count; ++i)
126146 {
127- if (strcmp (name, hashAlgorithmDescriptors[i]. name ) == 0 )
128- return & hashAlgorithmDescriptors[i];
147+ if (strcmp (name, hashAlgorithmDescriptors[i]-> name ) == 0 )
148+ return hashAlgorithmDescriptors[i];
129149 }
130150
131151 status_exception::raise (Arg::Gds (isc_sysf_invalid_hash_algorithm) << name);
0 commit comments