wasefire_board_api/fingerprint/matcher.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Fingerprint matcher interface.
16
17use alloc::vec::Vec;
18
19use crate::{Error, Support};
20
21/// Fingerprint matcher event.
22#[cfg_attr(feature = "defmt", derive(defmt::Format))]
23#[derive(Debug, PartialEq, Eq)]
24pub enum Event {
25 /// The enrollment process finished successfully.
26 ///
27 /// The `read_enroll()` function must be called before any other process.
28 EnrollDone,
29
30 /// The enrollment process made a step.
31 EnrollStep {
32 /// Estimated number of remaining steps.
33 remaining: usize,
34 },
35
36 /// The enrollment process encountered an error.
37 EnrollError {
38 /// The device error.
39 error: Error,
40 },
41
42 /// The identification process finished successfully.
43 ///
44 /// If the result is `true`, then the `read_identify()` function must be called before any other
45 /// process to read the template ID.
46 IdentifyDone {
47 /// Whether the finger was identified.
48 result: bool,
49 },
50
51 /// The identification process encountered an error.
52 IdentifyError {
53 /// The device error.
54 error: Error,
55 },
56}
57
58impl<B: crate::Api> From<Event> for crate::Event<B> {
59 fn from(event: Event) -> Self {
60 super::Event::Matcher(event).into()
61 }
62}
63
64/// Fingerprint matcher interface.
65pub trait Api: Support<bool> + Send {
66 /// Size in bytes of a template ID.
67 const TEMPLATE_ID_SIZE: usize;
68
69 /// Starts a finger enrollment process.
70 ///
71 /// The process will send a (possibly empty) series of `EnrollStep` events followed by an
72 /// `EnrollDone` (resp. `EnrollError`) event in case of success (resp. error) to indicate that
73 /// the enrollment finished.
74 fn start_enroll() -> Result<(), Error>;
75
76 /// Reads the template ID of a successful enrollment.
77 fn read_enroll(template_id: &mut [u8]) -> Result<(), Error>;
78
79 /// Aborts a finger enrollment process.
80 fn abort_enroll() -> Result<(), Error>;
81
82 /// Starts a finger identification process.
83 ///
84 /// If the template ID is not provided, the identification is done against all enrolled fingers.
85 ///
86 /// The process will send an `IdentifyDone` (resp. `IdentifyError`) event in case of success
87 /// (resp. error) to indicate that the identification finished.
88 fn start_identify(template_id: Option<&[u8]>) -> Result<(), Error>;
89
90 /// Reads the template ID of an identified finger.
91 fn read_identify(template_id: &mut [u8]) -> Result<(), Error>;
92
93 /// Aborts a finger identification process.
94 fn abort_identify() -> Result<(), Error>;
95
96 /// Deletes a template (or all) from the enrolled fingers.
97 ///
98 /// If the template ID is not provided, all templates are deleted.
99 fn delete_template(template_id: Option<&[u8]>) -> Result<(), Error>;
100
101 /// Returns a concatenation of the template IDs.
102 fn list_templates() -> Result<Vec<u8>, Error>;
103}