Implement touch_required() for TouchPolicy

This commit is contained in:
Heiko Schaefer 2022-05-31 00:06:13 +02:00
parent f9d69dbefb
commit e9bac43cad
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D

View file

@ -316,6 +316,7 @@ impl Display for UIF {
/// ///
/// Touch policies were introduced in YubiKey Version 4.2.0 with modes ON, OFF and FIXED. /// Touch policies were introduced in YubiKey Version 4.2.0 with modes ON, OFF and FIXED.
/// YubiKey Version >= 5.2.1 added support for modes CACHED and CACHED_FIXED. /// YubiKey Version >= 5.2.1 added support for modes CACHED and CACHED_FIXED.
#[derive(Eq, PartialEq)]
#[non_exhaustive] #[non_exhaustive]
pub enum TouchPolicy { pub enum TouchPolicy {
Off, Off,
@ -326,6 +327,17 @@ pub enum TouchPolicy {
Unknown(u8), Unknown(u8),
} }
impl TouchPolicy {
/// Returns "true" if this TouchPolicy (probably) requires touch confirmation.
///
/// Note: When the Policy is set to `Cached` or `CachedFixed`, there is no way to be sure if a
/// previous touch confirmation is still valid (touch confirmations are valid for 15s, in
/// Cached mode)
pub fn touch_required(&self) -> bool {
!matches!(self, Self::Off)
}
}
impl Display for TouchPolicy { impl Display for TouchPolicy {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {