@@ -185,9 +185,13 @@ void MySQL_Driver::threadEnd()
185
185
186
186
void MySQL_Driver::setCallBack (sql::WebAuthn_Callback&& cb)
187
187
{
188
- webauthn_callback = cb ? std::move (cb) : nullptr ;
188
+ if (cb)
189
+ webauthn_callback = std::move (cb);
190
+ else
191
+ webauthn_callback = nullptr ;
192
+
189
193
fido_callback
190
- = reinterpret_cast <Fido_Callback*>(cb ? 1LL : 0LL );
194
+ = reinterpret_cast <Fido_Callback*>(webauthn_callback ? 1LL : 0LL );
191
195
}
192
196
193
197
void MySQL_Driver::setCallBack (sql::WebAuthn_Callback& cb)
@@ -198,15 +202,20 @@ void MySQL_Driver::setCallBack(sql::WebAuthn_Callback& cb)
198
202
webauthn_callback = nullptr ;
199
203
200
204
fido_callback
201
- = reinterpret_cast <Fido_Callback*>(cb ? 1LL : 0LL );
205
+ = reinterpret_cast <Fido_Callback*>(webauthn_callback ? 1LL : 0LL );
202
206
}
203
207
204
208
205
- // Note: Values 1 and 4 of `fido_callback` mean that user has set an WebAuthn
206
- // callback before.
209
+ /*
210
+ Note: Values 1 and 4 of `fido_callback` mean that user has set a WebAuthn
211
+ callback before and it can not be overwritten by Fido one. If later user
212
+ de-registers a WebAuthn callaback then `fido_callback` becomes 0 or 4 and
213
+ error will not be thrown -- user can set a new Fido callback in this
214
+ situation.
215
+ */
207
216
208
217
#define CHECK_FIDO_ERROR \
209
- if (1 == reinterpret_cast <intptr_t >(fido_callback) % 3 ) \
218
+ if (1 == ( reinterpret_cast <intptr_t >(fido_callback) % 3 ) ) \
210
219
throw sql::SQLException{ \
211
220
" You are trying to overwrithe WebAuthn callback with FIDO one. " \
212
221
" FIDO authentication plugin and the corresponding callback type " \
@@ -217,9 +226,14 @@ void MySQL_Driver::setCallBack(sql::WebAuthn_Callback& cb)
217
226
void MySQL_Driver::setCallBack (sql::Fido_Callback&& cb)
218
227
{
219
228
CHECK_FIDO_ERROR;
220
- webauthn_callback = cb ? std::move (cb) : nullptr ;
229
+
230
+ if (cb)
231
+ webauthn_callback = std::move (cb);
232
+ else
233
+ webauthn_callback = nullptr ;
234
+
221
235
fido_callback
222
- = reinterpret_cast <Fido_Callback*>(cb ? 2LL : 0LL );
236
+ = reinterpret_cast <Fido_Callback*>(webauthn_callback ? 2LL : 0LL );
223
237
}
224
238
225
239
void MySQL_Driver::setCallBack (sql::Fido_Callback& cb)
@@ -232,7 +246,7 @@ void MySQL_Driver::setCallBack(sql::Fido_Callback& cb)
232
246
webauthn_callback = nullptr ;
233
247
234
248
fido_callback
235
- = reinterpret_cast <Fido_Callback*>(cb ? 2LL : 0LL );
249
+ = reinterpret_cast <Fido_Callback*>(webauthn_callback ? 2LL : 0LL );
236
250
}
237
251
238
252
} /* namespace mysql */
0 commit comments