From 3e5228dd7328eefcc9541b2f798c1e62463a7e8f Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 10 Nov 2021 09:50:46 +0100 Subject: [PATCH] pve: add_totp anda dd_yubico cannot error, drop Result type Signed-off-by: Wolfgang Bumiller --- pve-rs/src/tfa/proxmox_tfa_api/api.rs | 16 ++++++++++------ pve-rs/src/tfa/proxmox_tfa_api/mod.rs | 24 ++++++------------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/pve-rs/src/tfa/proxmox_tfa_api/api.rs b/pve-rs/src/tfa/proxmox_tfa_api/api.rs index 6be5205..031aaf3 100644 --- a/pve-rs/src/tfa/proxmox_tfa_api/api.rs +++ b/pve-rs/src/tfa/proxmox_tfa_api/api.rs @@ -388,9 +388,11 @@ fn add_totp( { bail!("failed to verify TOTP challenge"); } - config - .add_totp(userid, description, totp) - .map(TfaUpdateInfo::id) + Ok(TfaUpdateInfo::id(config.add_totp( + userid, + description, + totp, + ))) } fn add_yubico( @@ -400,9 +402,11 @@ fn add_yubico( value: Option, ) -> Result { let key = value.ok_or_else(|| format_err!("missing 'value' parameter for 'yubico' entry"))?; - config - .add_yubico(userid, description, key) - .map(TfaUpdateInfo::id) + Ok(TfaUpdateInfo::id(config.add_yubico( + userid, + description, + key, + ))) } fn add_u2f( diff --git a/pve-rs/src/tfa/proxmox_tfa_api/mod.rs b/pve-rs/src/tfa/proxmox_tfa_api/mod.rs index bd5ab27..0a6dfd0 100644 --- a/pve-rs/src/tfa/proxmox_tfa_api/mod.rs +++ b/pve-rs/src/tfa/proxmox_tfa_api/mod.rs @@ -167,34 +167,22 @@ impl TfaConfig { /// /// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret /// themselves. - pub fn add_totp( - &mut self, - userid: &str, - description: String, - value: Totp, - ) -> Result { - Ok(self - .users + pub fn add_totp(&mut self, userid: &str, description: String, value: Totp) -> String { + self.users .entry(userid.to_owned()) .or_default() - .add_totp(description, value)) + .add_totp(description, value) } /// Add a Yubico key to a user. /// /// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret /// themselves. - pub fn add_yubico( - &mut self, - userid: &str, - description: String, - key: String, - ) -> Result { - Ok(self - .users + pub fn add_yubico(&mut self, userid: &str, description: String, key: String) -> String { + self.users .entry(userid.to_owned()) .or_default() - .add_yubico(description, key)) + .add_yubico(description, key) } /// Add a new set of recovery keys. There can only be 1 set of keys at a time.