From e9bac43cad31e2040484dff16c39e03702a3d8ca Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Tue, 31 May 2022 00:06:13 +0200 Subject: [PATCH] Implement touch_required() for TouchPolicy --- openpgp-card/src/card_do.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openpgp-card/src/card_do.rs b/openpgp-card/src/card_do.rs index 303ab3c..a55dc46 100644 --- a/openpgp-card/src/card_do.rs +++ b/openpgp-card/src/card_do.rs @@ -316,6 +316,7 @@ impl Display for UIF { /// /// 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. +#[derive(Eq, PartialEq)] #[non_exhaustive] pub enum TouchPolicy { Off, @@ -326,6 +327,17 @@ pub enum TouchPolicy { 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 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self {