-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathuser_presence.rs
More file actions
52 lines (46 loc) · 1.84 KB
/
user_presence.rs
File metadata and controls
52 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2022-2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::api::connection::RecvStatus;
use crate::ctap::status_code::CtapResult;
#[derive(Debug)]
pub enum UserPresenceError {
/// User explicitly declined user presence check.
Declined,
/// User presence check was canceled by User Agent.
Canceled,
/// User presence check timed out.
Timeout,
}
pub type UserPresenceResult = Result<(), UserPresenceError>;
pub type UserPresenceWaitResult = CtapResult<(UserPresenceResult, RecvStatus)>;
pub trait UserPresence {
/// Initializes for a user presence check.
///
/// Must eventually be followed by a call to [`Self::check_complete`].
fn check_init(&mut self);
/// Waits until user presence is confirmed, rejected, or the given timeout expires.
///
/// Must be called between calls to [`Self::check_init`] and [`Self::check_complete`].
/// The function may write to the packet buffer, if it receives one during the wait.
/// If it does, the returned option contains the endpoint it received the data from.
fn wait_with_timeout(
&mut self,
packet: &mut [u8; 64],
timeout_ms: usize,
) -> UserPresenceWaitResult;
/// Finalizes a user presence check.
///
/// Must be called after [`Self::check_init`].
fn check_complete(&mut self);
}