@@ -70,7 +70,7 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
7070public:
7171 explicit CryptKeyHolder (IPluginConfig* cnf) noexcept
7272 : callbackInterface(this ), named(NULL ), tempStatus(master->getStatus ()),
73- config(cnf), key(0 ), owner(NULL )
73+ config(cnf), key(0 ), init( false ), owner(NULL )
7474 {
7575 config->addRef ();
7676 }
@@ -111,10 +111,13 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
111111 return owner;
112112 }
113113
114- ISC_UCHAR getKey ()
114+ const ISC_UCHAR& getKey ()
115115 {
116- if (!key)
116+ if (!init)
117+ {
117118 keyCallback (&tempStatus, NULL );
119+ init = true ;
120+ }
118121
119122 return key;
120123 }
@@ -140,7 +143,7 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
140143
141144 unsigned int callback (unsigned int , const void *, unsigned int length, void * buffer) override
142145 {
143- ISC_UCHAR k = holder->getKey ();
146+ const ISC_UCHAR& k = holder->getKey ();
144147 if (!k)
145148 {
146149 return 0 ;
@@ -153,6 +156,36 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
153156 return 1 ;
154157 }
155158
159+ int getHashLength (Firebird::CheckStatusWrapper* status) override
160+ {
161+ const ISC_UCHAR& k = holder->getKey ();
162+ if (!k)
163+ {
164+ ISC_STATUS err[] = {isc_arg_gds, isc_wish_list};
165+ status->setErrors2 (2 , err);
166+
167+ return -1 ;
168+ }
169+
170+ return 1 ;
171+ }
172+
173+ void getHashData (Firebird::CheckStatusWrapper* status, void * h) override
174+ {
175+ // here key value is returned by hash function as is
176+ // do not do it in production - use some hash function
177+ const ISC_UCHAR& k = holder->getKey ();
178+ if (!k)
179+ {
180+ ISC_STATUS err[] = {isc_arg_gds, isc_wish_list};
181+ status->setErrors2 (2 , err);
182+
183+ return ;
184+ }
185+
186+ memcpy (h, &k, 1 );
187+ }
188+
156189 private:
157190 CryptKeyHolder* holder;
158191 };
@@ -173,6 +206,18 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
173206 return 1 ;
174207 }
175208
209+ int getHashLength (Firebird::CheckStatusWrapper* status) override
210+ {
211+ return 1 ;
212+ }
213+
214+ void getHashData (Firebird::CheckStatusWrapper* status, void * h) override
215+ {
216+ // here key value is returned by hash function as is
217+ // do not do it in production - use some hash function
218+ memcpy (h, &key, 1 );
219+ }
220+
176221 ~NamedCallback ()
177222 {
178223 delete next;
@@ -189,6 +234,7 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
189234
190235 IPluginConfig* config;
191236 ISC_UCHAR key;
237+ bool init;
192238
193239 std::atomic_int refCounter;
194240 IReferenceCounted* owner;
0 commit comments