webauthn_authenticator_rs/ctap2/
ctap21pre.rs

1use std::ops::{Deref, DerefMut};
2
3use crate::{transport::Token, ui::UiCallback};
4
5use super::{
6    commands::GetInfoResponse, ctap21_bio::BiometricAuthenticatorInfo,
7    ctap21_cred::CredentialManagementAuthenticatorInfo, internal::CtapAuthenticatorVersion,
8    Ctap20Authenticator,
9};
10
11#[cfg(any(all(doc, not(doctest)), feature = "ctap2-management"))]
12use super::commands::{PrototypeBioEnrollmentRequest, PrototypeCredentialManagementRequest};
13
14/// CTAP 2.1-PRE protocol implementation.
15///
16/// This contains only CTAP 2.1-PRE-specific functionality. All CTAP 2.0
17/// functionality is avaliable via a [Deref] to [Ctap20Authenticator].
18#[derive(Debug)]
19pub struct Ctap21PreAuthenticator<'a, T: Token, U: UiCallback> {
20    authenticator: Ctap20Authenticator<'a, T, U>,
21}
22
23/// For backwards compatibility, pretend to be a
24/// [CTAP 2.0 authenticator][Ctap20Authenticator].
25impl<'a, T: Token, U: UiCallback> Deref for Ctap21PreAuthenticator<'a, T, U> {
26    type Target = Ctap20Authenticator<'a, T, U>;
27
28    fn deref(&self) -> &Self::Target {
29        &self.authenticator
30    }
31}
32
33impl<T: Token, U: UiCallback> DerefMut for Ctap21PreAuthenticator<'_, T, U> {
34    fn deref_mut(&mut self) -> &mut Self::Target {
35        &mut self.authenticator
36    }
37}
38
39impl<'a, T: Token, U: UiCallback> CtapAuthenticatorVersion<'a, T, U>
40    for Ctap21PreAuthenticator<'a, T, U>
41{
42    const VERSION: &'static str = "FIDO_2_1_PRE";
43    fn new_with_info(info: GetInfoResponse, token: T, ui_callback: &'a U) -> Self {
44        Self {
45            authenticator: Ctap20Authenticator::new_with_info(info, token, ui_callback),
46        }
47    }
48}
49
50impl<T: Token, U: UiCallback> BiometricAuthenticatorInfo<U> for Ctap21PreAuthenticator<'_, T, U> {
51    #[cfg(any(all(doc, not(doctest)), feature = "ctap2-management"))]
52    type RequestType = PrototypeBioEnrollmentRequest;
53
54    #[inline]
55    fn biometrics(&self) -> Option<bool> {
56        self.info.ctap21pre_biometrics()
57    }
58}
59
60impl<T: Token, U: UiCallback> CredentialManagementAuthenticatorInfo<U>
61    for Ctap21PreAuthenticator<'_, T, U>
62{
63    #[cfg(any(all(doc, not(doctest)), feature = "ctap2-management"))]
64    type RequestType = PrototypeCredentialManagementRequest;
65
66    #[inline]
67    fn supports_credential_management(&self) -> bool {
68        self.info.ctap21pre_credential_management()
69    }
70}