From 3717468a8a8ad650a3c488c72f9444a19b15e7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 9 Apr 2021 19:41:48 +0200 Subject: [PATCH] device: Make verification support optional We always assumed a device can verify, but nothing prevents from having a device that only can identify or capture. So, given that we've more fine grained checks, let's stop the task if this is the case. --- libfprint/fp-device.c | 11 ++++++++++- tests/test-fpi-device.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/libfprint/fp-device.c b/libfprint/fp-device.c index 7b0a659a..ba003628 100644 --- a/libfprint/fp-device.c +++ b/libfprint/fp-device.c @@ -955,6 +955,7 @@ fp_device_verify (FpDevice *device, { g_autoptr(GTask) task = NULL; FpDevicePrivate *priv = fp_device_get_instance_private (device); + FpDeviceClass *cls = FP_DEVICE_GET_CLASS (device); FpMatchData *data; task = g_task_new (device, cancellable, callback, user_data); @@ -975,6 +976,14 @@ fp_device_verify (FpDevice *device, return; } + if (!cls->verify || !(cls->features & FPI_DEVICE_FEATURE_VERIFY)) + { + g_task_return_error (task, + fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED, + "Device has no verification support")); + return; + } + priv->current_action = FPI_DEVICE_ACTION_VERIFY; priv->current_task = g_steal_pointer (&task); maybe_cancel_on_cancelled (device, cancellable); @@ -988,7 +997,7 @@ fp_device_verify (FpDevice *device, // Attach the match data as task data so that it is destroyed g_task_set_task_data (priv->current_task, data, (GDestroyNotify) match_data_free); - FP_DEVICE_GET_CLASS (device)->verify (device); + cls->verify (device); } /** diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c index a6b72858..9aa7e37a 100644 --- a/tests/test-fpi-device.c +++ b/tests/test-fpi-device.c @@ -1161,6 +1161,39 @@ test_driver_verify (void) g_assert_true (match); } +static void +test_driver_verify_not_supported (void) +{ + g_autoptr(GError) error = NULL; + g_autoptr(FpPrint) enrolled_print = NULL; + g_autoptr(FpPrint) out_print = NULL; + g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1); + g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class (); + g_autoptr(FpAutoCloseDevice) device = NULL; + FpiDeviceFake *fake_dev; + gboolean match; + + dev_class->features &= ~FPI_DEVICE_FEATURE_VERIFY; + + device = auto_close_fake_device_new (); + fake_dev = FPI_DEVICE_FAKE (device); + fake_dev->last_called_function = NULL; + + enrolled_print = make_fake_print_reffed (device, g_variant_new_uint64 (3)); + g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, + test_driver_match_cb, match_data, + &match, &out_print, &error)); + + g_assert_null (fake_dev->last_called_function); + g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_NOT_SUPPORTED); + + g_assert_false (match_data->called); + g_assert_no_error (match_data->error); + + g_assert_null (out_print); + g_assert_false (match); +} + static void test_driver_verify_fail (void) { @@ -2629,6 +2662,7 @@ main (int argc, char *argv[]) g_test_add_func ("/driver/verify/fail", test_driver_verify_fail); g_test_add_func ("/driver/verify/retry", test_driver_verify_retry); g_test_add_func ("/driver/verify/error", test_driver_verify_error); + g_test_add_func ("/driver/verify/not_supported", test_driver_verify_not_supported); g_test_add_func ("/driver/verify/report_no_cb", test_driver_verify_report_no_callback); g_test_add_func ("/driver/verify/not_reported", test_driver_verify_not_reported); g_test_add_func ("/driver/verify/complete_retry", test_driver_verify_complete_retry);